diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index c5ac4b9afc89f..d01f33ae626ac 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -120,6 +120,10 @@ public function getThumbnail($x, $y, $file) { throw new NotFoundException(); } + if ($file->getId() <= 0) { + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); + } + /** @var File $file */ $preview = $this->previewManager->getPreview($file, $x, $y, true); diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php index 269977350f784..1e574e16d0495 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -177,6 +177,7 @@ public function testGetThumbnailInvalidSize() { public function testGetThumbnailInvalidImage() { $file = $this->createMock(File::class); + $file->method('getId')->willReturn(123); $this->userFolder->method('get') ->with($this->equalTo('unknown.jpg')) ->willReturn($file); @@ -188,8 +189,19 @@ public function testGetThumbnailInvalidImage() { $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); } + public function testGetThumbnailInvalidPartFile() { + $file = $this->createMock(File::class); + $file->method('getId')->willReturn(0); + $this->userFolder->method('get') + ->with($this->equalTo('unknown.jpg')) + ->willReturn($file); + $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); + $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); + } + public function testGetThumbnail() { $file = $this->createMock(File::class); + $file->method('getId')->willReturn(123); $this->userFolder->method('get') ->with($this->equalTo('known.jpg')) ->willReturn($file); diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 118f1b47752d6..04307c977e6be 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -130,6 +130,10 @@ private function fetchPreview( return new DataResponse([], Http::STATUS_FORBIDDEN); } + if ($node->getId() <= 0) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + $storage = $node->getStorage(); if ($storage->instanceOfStorage(SharedStorage::class)) { /** @var SharedStorage $storage */ diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index d047ea4e53ee6..d9b0aa966e399 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1369,9 +1369,6 @@ public function getFileInfo($path, $includeMountPoints = true) { if (!Filesystem::isValidPath($path)) { return false; } - if (Cache\Scanner::isPartialFile($path)) { - return $this->getPartFileInfo($path); - } $relativePath = $path; $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); @@ -1382,6 +1379,10 @@ public function getFileInfo($path, $includeMountPoints = true) { $data = $this->getCacheEntry($storage, $internalPath, $relativePath); if (!$data instanceof ICacheEntry) { + if (Cache\Scanner::isPartialFile($relativePath)) { + return $this->getPartFileInfo($relativePath); + } + return false; } diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index 7815505d5a8bb..82c4fe1188cc1 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -204,6 +204,7 @@ public function testValidPreview() { ->willReturn($userFolder); $file = $this->createMock(File::class); + $file->method('getId')->willReturn(123); $userFolder->method('get') ->with($this->equalTo('file')) ->willReturn($file);