Skip to content

Commit 0f48386

Browse files
authored
Merge pull request #46762 from nextcloud/backport/46672/stable27
[stable27] Avoid using partial file info as valid one
2 parents 1e77c4a + e4e4e12 commit 0f48386

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

apps/files/lib/Controller/ApiController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public function getThumbnail($x, $y, $file) {
120120
throw new NotFoundException();
121121
}
122122

123+
if ($file->getId() <= 0) {
124+
return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
125+
}
126+
123127
/** @var File $file */
124128
$preview = $this->previewManager->getPreview($file, $x, $y, true);
125129

apps/files/tests/Controller/ApiControllerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function testGetThumbnailInvalidSize() {
177177

178178
public function testGetThumbnailInvalidImage() {
179179
$file = $this->createMock(File::class);
180+
$file->method('getId')->willReturn(123);
180181
$this->userFolder->method('get')
181182
->with($this->equalTo('unknown.jpg'))
182183
->willReturn($file);
@@ -188,8 +189,19 @@ public function testGetThumbnailInvalidImage() {
188189
$this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg'));
189190
}
190191

192+
public function testGetThumbnailInvalidPartFile() {
193+
$file = $this->createMock(File::class);
194+
$file->method('getId')->willReturn(0);
195+
$this->userFolder->method('get')
196+
->with($this->equalTo('unknown.jpg'))
197+
->willReturn($file);
198+
$expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
199+
$this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg'));
200+
}
201+
191202
public function testGetThumbnail() {
192203
$file = $this->createMock(File::class);
204+
$file->method('getId')->willReturn(123);
193205
$this->userFolder->method('get')
194206
->with($this->equalTo('known.jpg'))
195207
->willReturn($file);

core/Controller/PreviewController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ private function fetchPreview(
130130
return new DataResponse([], Http::STATUS_FORBIDDEN);
131131
}
132132

133+
if ($node->getId() <= 0) {
134+
return new DataResponse([], Http::STATUS_NOT_FOUND);
135+
}
136+
133137
$storage = $node->getStorage();
134138
if ($storage->instanceOfStorage(SharedStorage::class)) {
135139
/** @var SharedStorage $storage */

lib/private/Files/View.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,6 @@ public function getFileInfo($path, $includeMountPoints = true) {
13691369
if (!Filesystem::isValidPath($path)) {
13701370
return false;
13711371
}
1372-
if (Cache\Scanner::isPartialFile($path)) {
1373-
return $this->getPartFileInfo($path);
1374-
}
13751372
$relativePath = $path;
13761373
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
13771374

@@ -1382,6 +1379,10 @@ public function getFileInfo($path, $includeMountPoints = true) {
13821379
$data = $this->getCacheEntry($storage, $internalPath, $relativePath);
13831380

13841381
if (!$data instanceof ICacheEntry) {
1382+
if (Cache\Scanner::isPartialFile($relativePath)) {
1383+
return $this->getPartFileInfo($relativePath);
1384+
}
1385+
13851386
return false;
13861387
}
13871388

tests/Core/Controller/PreviewControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public function testValidPreview() {
204204
->willReturn($userFolder);
205205

206206
$file = $this->createMock(File::class);
207+
$file->method('getId')->willReturn(123);
207208
$userFolder->method('get')
208209
->with($this->equalTo('file'))
209210
->willReturn($file);

0 commit comments

Comments
 (0)