From 20500123e5c7356c2ef9d65018eeaeb9c99ef7bd Mon Sep 17 00:00:00 2001 From: Nick Lassonde Date: Mon, 23 Aug 2021 13:17:36 -0700 Subject: [PATCH 1/2] add option to allow arbitrary length packets, for servers like OpenText which sends extremely long directory listings --- phpseclib/Net/SFTP.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 4aa44613..c44f3066 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -310,6 +310,21 @@ class Net_SFTP extends Net_SSH2 */ var $preserveTime = false; + /** + * Arbitrary Length Packets Flag + * + * Determines whether or not packets of any length should be allowed, + * in cases where the server chooses the packet length (such as + * directory listings). By default, packets are only allowed to be + * 256 * 1024 bytes (SFTP_MAX_MSG_LENGTH from OpenSSH's sftp-common.h) + * + * @see self::enableArbitraryLengthPackets() + * @see self::_get_sftp_packet() + * @var bool + * @access private + */ + var $allow_arbitrary_length_packets = false; + /** * Was the last packet due to the channels being closed or not? * @@ -703,6 +718,16 @@ class Net_SFTP extends Net_SSH2 $this->canonicalize_paths = true; } + /** + * Enable arbitrary length packets + * + * @access public + */ + function enableArbitraryLengthPackets() + { + $this->allow_arbitrary_length_packets = true; + } + /** * Enable path canonicalization * @@ -3187,7 +3212,7 @@ class Net_SFTP extends Net_SSH2 // 256 * 1024 is what SFTP_MAX_MSG_LENGTH is set to in OpenSSH's sftp-common.h - if (!$this->use_request_id && $tempLength > 256 * 1024) { + if (!$this->allow_arbitrary_length_packets &&!$this->use_request_id && $tempLength > 256 * 1024) { user_error('Invalid SFTP packet size'); return false; } From fc40727cfbbc8c997ffdcef9511a3b22db290bd8 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 24 Aug 2021 20:22:29 -0500 Subject: [PATCH 2/2] SFTP: add disableArbitraryLengthPackets() --- phpseclib/Net/SFTP.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index c44f3066..fccff3ce 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -718,6 +718,16 @@ class Net_SFTP extends Net_SSH2 $this->canonicalize_paths = true; } + /** + * Enable path canonicalization + * + * @access public + */ + function disablePathCanonicalization() + { + $this->canonicalize_paths = false; + } + /** * Enable arbitrary length packets * @@ -729,13 +739,13 @@ class Net_SFTP extends Net_SSH2 } /** - * Enable path canonicalization + * Disable arbitrary length packets * * @access public */ - function disablePathCanonicalization() + function disableArbitraryLengthPackets() { - $this->canonicalize_paths = false; + $this->allow_arbitrary_length_packets = false; } /** @@ -3212,7 +3222,7 @@ class Net_SFTP extends Net_SSH2 // 256 * 1024 is what SFTP_MAX_MSG_LENGTH is set to in OpenSSH's sftp-common.h - if (!$this->allow_arbitrary_length_packets &&!$this->use_request_id && $tempLength > 256 * 1024) { + if (!$this->allow_arbitrary_length_packets && !$this->use_request_id && $tempLength > 256 * 1024) { user_error('Invalid SFTP packet size'); return false; }