Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Ignore preview requests for invalid file ids
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jul 22, 2024
commit 6c1e896a03f20e568df5af1d547f46e2df9b71a9
4 changes: 4 additions & 0 deletions apps/files/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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);

Expand Down
12 changes: 12 additions & 0 deletions apps/files/tests/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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);
Expand All @@ -168,8 +169,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);
Expand Down
4 changes: 4 additions & 0 deletions core/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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 */
Expand Down
1 change: 1 addition & 0 deletions tests/Core/Controller/PreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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);
Expand Down