From 773941dfb021f7a29adb6076071155b3294a3465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 16 Sep 2015 11:07:13 +0200 Subject: [PATCH 1/2] prevent 0 byte downloads when storage returns false --- lib/private/connector/sabre/file.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 17659c96b07..f4acc8290bc 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -261,10 +261,13 @@ class File extends Node implements IFile { * @throws ServiceUnavailable */ public function get() { - //throw exception if encryption is disabled but files are still encrypted try { - return $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); + $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); + if ($res === false) { + throw new ServiceUnavailable("Could not open file"); + } + return $res; } catch (GenericEncryptionException $e) { // returning 503 will allow retry of the operation at a later point in time throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); From 2839ef34395599adf060a485a263a69ce27305e1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 16 Sep 2015 13:40:12 +0200 Subject: [PATCH 2/2] add unit test --- tests/lib/connector/sabre/file.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index e5605dd7cc5..fe4c5ec7c29 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -809,4 +809,21 @@ class File extends \Test\TestCase { return $files; } + /** + * @expectedException \Sabre\DAV\Exception\ServiceUnavailable + */ + public function testGetFopenFails() { + $view = $this->getMock('\OC\Files\View', ['fopen'], array()); + $view->expects($this->atLeastOnce()) + ->method('fopen') + ->will($this->returnValue(false)); + + $info = new \OC\Files\FileInfo('/test.txt', null, null, array( + 'permissions' => \OCP\Constants::PERMISSION_ALL + ), null); + + $file = new \OC\Connector\Sabre\File($view, $info); + + $file->get(); + } }