From 68dded538685c6ac1ec299e0f0af68d5fc23af04 Mon Sep 17 00:00:00 2001 From: Artem Gayardo-Matrosov Date: Fri, 3 Mar 2017 15:15:18 +0100 Subject: [PATCH 1/2] Fix for data corruption when reading to a buffer that is smaller than the internal buffer. --- src/Renci.SshNet/Sftp/SftpFileStream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renci.SshNet/Sftp/SftpFileStream.cs b/src/Renci.SshNet/Sftp/SftpFileStream.cs index 853010cb0..cc66677f5 100644 --- a/src/Renci.SshNet/Sftp/SftpFileStream.cs +++ b/src/Renci.SshNet/Sftp/SftpFileStream.cs @@ -362,7 +362,7 @@ public override int Read(byte[] buffer, int offset, int count) { // copy remaining bytes to read buffer _bufferLen = data.Length - bytesToWriteToCallerBuffer; - Buffer.BlockCopy(data, count, _readBuffer, 0, _bufferLen); + Buffer.BlockCopy(data, bytesToWriteToCallerBuffer, _readBuffer, 0, _bufferLen); } } else From c2bd7b5171d2ccce0780774f283effd2bf13b84d Mon Sep 17 00:00:00 2001 From: Artem Gayardo-Matrosov Date: Fri, 3 Mar 2017 15:39:31 +0100 Subject: [PATCH 2/2] Unit test fix. --- src/Renci.SshNet/Abstractions/ThreadAbstraction.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs index f1ed202ae..fe6e3e218 100644 --- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs @@ -36,6 +36,8 @@ public static void ExecuteThreadLongRunning(Action action) /// The action to execute. public static void ExecuteThread(Action action) { + if (action == null) + throw new ArgumentNullException("action"); #if FEATURE_THREAD_THREADPOOL System.Threading.ThreadPool.QueueUserWorkItem(o => action()); #elif FEATURE_THREAD_TAP