Skip to content

Commit

Permalink
Bug 2218: WinSCP could ask the server to return mode data during SFTP…
Browse files Browse the repository at this point in the history
… download than it can process

https://winscp.net/tracker/2218

Source commit: 5bd9afb1c64da8308dcc27640bd5cadead774709
  • Loading branch information
martinprikryl committed Sep 8, 2023
1 parent d8d0adf commit 7240e94
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/core/SftpFileSystem.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
//---------------------------------------------------------------------------
Expand Down

0 comments on commit 7240e94

Please sign in to comment.