瀏覽代碼

Bug 2218: WinSCP could ask the server to return mode data during SFTP download than it can process

https://winscp.net/tracker/2218

Source commit: 5bd9afb1c64da8308dcc27640bd5cadead774709
Martin Prikryl 2 年之前
父節點
當前提交
7240e942e9
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      source/core/SftpFileSystem.cpp

+ 8 - 2
source/core/SftpFileSystem.cpp

@@ -2241,12 +2241,13 @@ inline void __fastcall TSFTPFileSystem::BusyEnd()
   }
 }
 //---------------------------------------------------------------------------
+// size + message number + type
+const unsigned long SFTPPacketOverhead = 4 + 4 + 1;
+//---------------------------------------------------------------------------
 unsigned long __fastcall TSFTPFileSystem::TransferBlockSize(
   unsigned long Overhead, TFileOperationProgressType * OperationProgress)
 {
   const unsigned long MinPacketSize = 32768;
-  // size + message number + type
-  const unsigned long SFTPPacketOverhead = 4 + 4 + 1;
   unsigned long AMaxPacketSize = FSecureShell->MaxPacketSize();
   bool MaxPacketSizeValid = (AMaxPacketSize > 0);
   unsigned long CPSRounded = TEncryption::RoundToBlock(OperationProgress->CPS());
@@ -2316,6 +2317,11 @@ unsigned long __fastcall TSFTPFileSystem::DownloadBlockSize(
   {
     Result = FSupport->MaxReadSize;
   }
+  // Never ask for more than we can accept (overhead here should correctly not include the "size" field)
+  if (Result + SFTPPacketOverhead > SFTP_MAX_PACKET_LEN)
+  {
+    Result = SFTP_MAX_PACKET_LEN - SFTPPacketOverhead;
+  }
   return Result;
 }
 //---------------------------------------------------------------------------