Merge pull request #15980 from owncloud/jknockaert-patch-1

fix bug #15973
This commit is contained in:
Björn Schießle 2015-05-18 15:01:16 +02:00
commit a1e60e7882
2 changed files with 18 additions and 19 deletions

View File

@ -356,24 +356,22 @@ class Encryption extends Wrapper {
switch ($whence) { switch ($whence) {
case SEEK_SET: case SEEK_SET:
if ($offset < $this->unencryptedSize && $offset >= 0) { $newPosition = $offset;
$newPosition = $offset;
}
break; break;
case SEEK_CUR: case SEEK_CUR:
if ($offset >= 0) { $newPosition = $this->position + $offset;
$newPosition = $offset + $this->position;
}
break; break;
case SEEK_END: case SEEK_END:
if ($this->unencryptedSize + $offset >= 0) { $newPosition = $this->unencryptedSize + $offset;
$newPosition = $this->unencryptedSize + $offset;
}
break; break;
default: default:
return $return; return $return;
} }
if ($newPosition > $this->unencryptedSize || $newPosition < 0) {
return $return;
}
$newFilePosition = floor($newPosition / $this->unencryptedBlockSize) $newFilePosition = floor($newPosition / $this->unencryptedBlockSize)
* $this->util->getBlockSize() + $this->headerSize; * $this->util->getBlockSize() + $this->headerSize;

View File

@ -160,15 +160,6 @@ class Encryption extends \Test\TestCase {
$this->assertEquals('foobar', fread($stream, 100)); $this->assertEquals('foobar', fread($stream, 100));
fclose($stream); fclose($stream);
unlink($fileName);
}
public function testWriteWriteRead() {
$fileName = tempnam("/tmp", "FOO");
$stream = $this->getStream($fileName, 'w+', 0);
$this->assertEquals(6, fwrite($stream, 'foobar'));
fclose($stream);
$stream = $this->getStream($fileName, 'r+', 6); $stream = $this->getStream($fileName, 'r+', 6);
$this->assertEquals(3, fwrite($stream, 'bar')); $this->assertEquals(3, fwrite($stream, 'bar'));
fclose($stream); fclose($stream);
@ -176,6 +167,8 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 6); $stream = $this->getStream($fileName, 'r', 6);
$this->assertEquals('barbar', fread($stream, 100)); $this->assertEquals('barbar', fread($stream, 100));
fclose($stream); fclose($stream);
unlink($fileName);
} }
public function testRewind() { public function testRewind() {
@ -191,7 +184,9 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 6); $stream = $this->getStream($fileName, 'r', 6);
$this->assertEquals('barbar', fread($stream, 100)); $this->assertEquals('barbar', fread($stream, 100));
fclose($stream); fclose($stream);
}
unlink($fileName);
}
public function testSeek() { public function testSeek() {
$fileName = tempnam("/tmp", "FOO"); $fileName = tempnam("/tmp", "FOO");
@ -203,6 +198,12 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 9); $stream = $this->getStream($fileName, 'r', 9);
$this->assertEquals('foofoobar', fread($stream, 100)); $this->assertEquals('foofoobar', fread($stream, 100));
$this->assertEquals(-1, fseek($stream, 10));
$this->assertEquals(0, fseek($stream, 9));
$this->assertEquals(-1, fseek($stream, -10, SEEK_CUR));
$this->assertEquals(0, fseek($stream, -9, SEEK_CUR));
$this->assertEquals(-1, fseek($stream, -10, SEEK_END));
$this->assertEquals(0, fseek($stream, -9, SEEK_END));
fclose($stream); fclose($stream);
unlink($fileName); unlink($fileName);