1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-11-27 04:34:45 +01:00

Merge pull request #834 from terrafrost/sftp-endless-loop-v2

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

* terrafrost/sftp-endless-loop-v2:
  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:27:37 +02:00
commit cf101b5d8c
2 changed files with 24 additions and 4 deletions

View File

@ -1876,10 +1876,7 @@ class SFTP extends SSH2
if ($local_start >= 0) {
fseek($fp, $local_start);
} elseif ($mode & self::RESUME_START) {
// do nothing
} else {
fseek($fp, $offset);
$size-= $local_start;
}
} elseif ($dataCallback) {
$size = 0;

View File

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