From 2c80ac8acad6d4b0c486d4e5db63ac6e27b3e4ea Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 9 May 2013 00:02:04 -0500 Subject: [PATCH 1/2] SFTP: Add support for files larger than 2GB 0x7FFFFFFF is about 2GB. To support larger files floating point is used --- phpseclib/Net/SFTP.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index caee65fb..69ce9de8 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1025,7 +1025,7 @@ class Net_SFTP extends Net_SSH2 { */ function truncate($filename, $new_size) { - $attr = pack('N3', NET_SFTP_ATTR_SIZE, 0, $new_size); + $attr = pack('N3', NET_SFTP_ATTR_SIZE, $new_size / 0x100000000, $new_size); return $this->_setstat($filename, $attr, false); } @@ -1520,7 +1520,8 @@ class Net_SFTP extends Net_SSH2 { $i = 0; while ($sent < $size) { $temp = $mode & NET_SFTP_LOCAL_FILE ? fread($fp, $sftp_packet_size) : $this->_string_shift($data, $sftp_packet_size); - $packet = pack('Na*N3a*', strlen($handle), $handle, 0, $offset + $sent, strlen($temp), $temp); + $subtemp = $offset + $sent; + $packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 0x100000000, $subtemp, strlen($temp), $temp); if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) { fclose($fp); return false; @@ -1650,7 +1651,7 @@ class Net_SFTP extends Net_SSH2 { $size = (1 << 20) < $length || $length < 0 ? 1 << 20 : $length; while (true) { - $packet = pack('Na*N3', strlen($handle), $handle, 0, $offset, $size); + $packet = pack('Na*N3', strlen($handle), $handle, $offset / 0x100000000, $offset, $size); if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) { if ($local_file !== false) { fclose($fp); @@ -1904,11 +1905,8 @@ class Net_SFTP extends Net_SSH2 { // (0xFFFFFFFF bytes), anyway. as such, we'll just represent all file sizes that are bigger than // 4GB as being 4GB. extract(unpack('Nupper/Nsize', $this->_string_shift($response, 8))); - if ($upper) { - $attr['size'] = 0xFFFFFFFF; - } else { - $attr['size'] = $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size; - } + $attr['size'] = $upper ? 0x100000000 * $upper; + $attr['size']+= $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size; break; case NET_SFTP_ATTR_UIDGID: // 0x00000002 (SFTPv3 only) $attr+= unpack('Nuid/Ngid', $this->_string_shift($response, 8)); @@ -2204,4 +2202,4 @@ class Net_SFTP extends Net_SSH2 { $this->pwd = false; parent::_disconnect($reason); } -} +} \ No newline at end of file From d2d4e89ffc00e8b1cc85d1e0fde007d71b46620d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 9 May 2013 13:23:54 -0400 Subject: [PATCH 2/2] SFTP: typo --- phpseclib/Net/SFTP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 69ce9de8..7f31079f 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1905,7 +1905,7 @@ class Net_SFTP extends Net_SSH2 { // (0xFFFFFFFF bytes), anyway. as such, we'll just represent all file sizes that are bigger than // 4GB as being 4GB. extract(unpack('Nupper/Nsize', $this->_string_shift($response, 8))); - $attr['size'] = $upper ? 0x100000000 * $upper; + $attr['size'] = $upper ? 0x100000000 * $upper : 0; $attr['size']+= $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size; break; case NET_SFTP_ATTR_UIDGID: // 0x00000002 (SFTPv3 only) @@ -2202,4 +2202,4 @@ class Net_SFTP extends Net_SSH2 { $this->pwd = false; parent::_disconnect($reason); } -} \ No newline at end of file +}