From 6688f650f1aa53e7fb946932a19ead8037ade958 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 29 Sep 2015 21:39:35 -0500 Subject: [PATCH] SFTP: don't start in local file middle when uploading to middle of the remote file --- phpseclib/Net/SFTP.php | 5 ----- tests/Functional/Net/SFTPUserStoryTest.php | 14 ++++++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index fb4a0be4..93778c14 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1918,11 +1918,6 @@ class Net_SFTP extends Net_SSH2 if ($local_start >= 0) { fseek($fp, $local_start); $size-= $local_start; - } elseif ($mode & NET_SFTP_RESUME_START) { - // do nothing - } else { - fseek($fp, $offset); - $size-= $offset; } } elseif ($dataCallback) { $size = 0; diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index ceedcfa5..770ad95b 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -657,14 +657,20 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase * @depends testStatVsLstat * @group github830 */ - public function testEndlessLoopOnUpload($sftp) + public function testUploadOffsets($sftp) { - $sftp->put('endless.txt', 'res.txt', NET_SFTP_LOCAL_FILE, 0, 10); - + $sftp->put('offset.txt', 'res.txt', NET_SFTP_LOCAL_FILE, 0, 10); $this->assertSame( substr(self::$exampleData, 10), - $sftp->get('endless.txt'), + $sftp->get('offset.txt'), 'Failed asserting that portions of a file could be uploaded.' ); + + $sftp->put('offset.txt', 'res.txt', NET_SFTP_LOCAL_FILE, self::$exampleDataLength - 100); + $this->assertSame( + substr(self::$exampleData, 10, -90) . self::$exampleData, + $sftp->get('offset.txt'), + 'Failed asserting that you could upload into the middle of a file.' + ); } }