Skip to content

Commit

Permalink
SSH2: uploads on low speed networks could get in infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Aug 9, 2020
1 parent a019cf3 commit 239bc63
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpseclib/Net/SFTP.php
Expand Up @@ -3041,6 +3041,10 @@ function _parseLongname($longname)
*/
function _send_sftp_packet($type, $data, $request_id = 1)
{
// in SSH2.php the timeout is cumulative per function call. eg. exec() will
// timeout after 10s. but for SFTP.php it's cumulative per packet
$this->curTimeout = $this->timeout;

$packet = $this->use_request_id ?
pack('NCNa*', strlen($data) + 5, $type, $request_id, $data) :
pack('NCa*', strlen($data) + 1, $type, $data);
Expand Down

3 comments on commit 239bc63

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1507

@zabullet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrafrost it does appear to fix it. Out of interest could you explain the root cause?

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was happening before is that there'd be a timeout and then, when waiting for window size adjustment packets, _get_binay_packet just returned a bool because of the timeout and so the window size was never being adjusted so it got caught up in an infinite loop, requesting a packet only to get a bool that doesn't adjust the window size.

Or something like that - it's been a few days since I've worked on it lol

Please sign in to comment.