From 13eedf662af9367d4fe0bb413da94bff043e17be Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Fri, 22 Nov 2013 21:58:32 +0100 Subject: [PATCH] resolve bug with syncing on FTP --- src/Kp2aBusinessLogic/Io/CachingFileStorage.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Kp2aBusinessLogic/Io/CachingFileStorage.cs b/src/Kp2aBusinessLogic/Io/CachingFileStorage.cs index f58ad80b..95dd50cf 100644 --- a/src/Kp2aBusinessLogic/Io/CachingFileStorage.cs +++ b/src/Kp2aBusinessLogic/Io/CachingFileStorage.cs @@ -200,10 +200,16 @@ namespace keepass2android.Io public MemoryStream GetRemoteDataAndHash(IOConnectionInfo ioc, out string hash) { MemoryStream remoteData = new MemoryStream(); - using ( - HashingStreamEx hashingRemoteStream = new HashingStreamEx(_cachedStorage.OpenFileForRead(ioc), false, - new SHA256Managed())) + + using (var remoteStream =_cachedStorage.OpenFileForRead(ioc)) { + //note: directly copying to remoteData and hashing causes NullReferenceExceptions in FTP and with Digest auth + // -> use the temp data approach: + MemoryStream tempData = new MemoryStream(); + remoteStream.CopyTo(tempData); + tempData.Position = 0; + HashingStreamEx hashingRemoteStream = new HashingStreamEx(tempData, false, new SHA256Managed()); + hashingRemoteStream.CopyTo(remoteData); hashingRemoteStream.Close(); hash = MemUtil.ByteArrayToHexString(hashingRemoteStream.Hash);