From a4ed6b80f3676bf3a712af6d89e8f465f4b27747 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 2 Nov 2019 12:42:34 -0500 Subject: [PATCH] SSH2: make window resizing behave more consistently with PuTTY --- phpseclib/Net/SSH2.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index ae53fbed..6208f38c 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -597,6 +597,20 @@ class Net_SSH2 */ var $window_size = 0x7FFFFFFF; + /** + * What we resize the window to + * + * When PuTTY resizes the window it doesn't add an additional 0x7FFFFFFF bytes - it adds 0x40000000 bytes. + * Some SFTP clients (GoAnywhere) don't support adding 0x7FFFFFFF to the window size after the fact so + * we'll just do what PuTTY does + * + * @var int + * @see self::_send_channel_packet() + * @see self::exec() + * @access private + */ + var $window_resize = 0x40000000; + /** * Window size, server to client * @@ -3723,11 +3737,13 @@ class Net_SSH2 // resize the window, if appropriate if ($this->window_size_server_to_client[$channel] < 0) { - $packet = pack('CNN', NET_SSH2_MSG_CHANNEL_WINDOW_ADJUST, $this->server_channels[$channel], $this->window_size); + // PuTTY does something more analogous to the following: + //if ($this->window_size_server_to_client[$channel] < 0x3FFFFFFF) { + $packet = pack('CNN', NET_SSH2_MSG_CHANNEL_WINDOW_ADJUST, $this->server_channels[$channel], $this->window_resize); if (!$this->_send_binary_packet($packet)) { return false; } - $this->window_size_server_to_client[$channel]+= $this->window_size; + $this->window_size_server_to_client[$channel]+= $this->window_resize; } switch ($type) {