diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-07-25 19:37:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 19:37:30 +0200 |
commit | 4f2a29adf95c57bef5d01f27c8b741a9840e82b3 (patch) | |
tree | 964245a9302baa5b49f215642fb1f82acfa5987b | |
parent | 2e353d88498e841a468eaa28874f18ba20c7a9b1 (diff) | |
parent | 2b0bc8b310aef675af35373fbc8a7884869f7d05 (diff) | |
download | nextcloud-server-4f2a29adf95c57bef5d01f27c8b741a9840e82b3.tar.gz nextcloud-server-4f2a29adf95c57bef5d01f27c8b741a9840e82b3.zip |
Merge pull request #46672 from nextcloud/fix/preview-invalid-id
Avoid using partial file info as valid one
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 4 | ||||
-rw-r--r-- | apps/files/tests/Controller/ApiControllerTest.php | 12 | ||||
-rw-r--r-- | core/Controller/PreviewController.php | 4 | ||||
-rw-r--r-- | lib/private/Files/View.php | 7 | ||||
-rw-r--r-- | tests/Core/Controller/PreviewControllerTest.php | 1 |
5 files changed, 25 insertions, 3 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 64082fbfd85..9cf634f9404 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -93,6 +93,10 @@ class ApiController extends Controller { 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 0093603c5f6..844fabc93a3 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -157,6 +157,7 @@ class ApiControllerTest extends TestCase { public function testGetThumbnailInvalidImage() { $file = $this->createMock(File::class); + $file->method('getId')->willReturn(123); $this->userFolder->method('get') ->with($this->equalTo('unknown.jpg')) ->willReturn($file); @@ -168,8 +169,19 @@ class ApiControllerTest extends TestCase { $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 ffe761fd706..4ace295a6aa 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -141,6 +141,10 @@ class PreviewController extends Controller { 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 c20ff9f3c02..0e5e433ccb6 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1338,9 +1338,6 @@ class View { if (!Filesystem::isValidPath($path)) { return false; } - if (Cache\Scanner::isPartialFile($path)) { - return $this->getPartFileInfo($path); - } $relativePath = $path; $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); @@ -1351,6 +1348,10 @@ class View { $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 d330c1d5209..7c9a32eae38 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -187,6 +187,7 @@ class PreviewControllerTest extends \Test\TestCase { ->willReturn($userFolder); $file = $this->createMock(File::class); + $file->method('getId')->willReturn(123); $userFolder->method('get') ->with($this->equalTo('file')) ->willReturn($file); |