Merge pull request #833 from terrafrost/sftp-endless-loop

SFTP.php : prevent endless loop when upload completed with non-zero $start or $local_start for 1.0

* terrafrost/sftp-endless-loop:
  SFTP: don't start in local file middle when uploading to middle of the remote file
  Tests/SFTP: updates to newly added unit test
  SFTP: backport DavidAnderson684's changes to 1.0 branch
  add unit test demo'ing issue # 830
This commit is contained in:
Andreas Fischer 2015-09-30 17:26:23 +02:00
commit c0e42ad751
2 changed files with 24 additions and 4 deletions

View File

@ -1917,10 +1917,7 @@ class Net_SFTP extends Net_SSH2
if ($local_start >= 0) { if ($local_start >= 0) {
fseek($fp, $local_start); fseek($fp, $local_start);
} elseif ($mode & NET_SFTP_RESUME_START) { $size-= $local_start;
// do nothing
} else {
fseek($fp, $offset);
} }
} elseif ($dataCallback) { } elseif ($dataCallback) {
$size = 0; $size = 0;

View File

@ -649,5 +649,28 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK); $this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
$sftp->enableStatCache(); $sftp->enableStatCache();
return $sftp;
}
/**
* @depends testStatVsLstat
* @group github830
*/
public function testUploadOffsets($sftp)
{
$sftp->put('offset.txt', 'res.txt', NET_SFTP_LOCAL_FILE, 0, 10);
$this->assertSame(
substr(self::$exampleData, 10),
$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.'
);
} }
} }