Skip to content

Commit

Permalink
Always try and show pre rendered preview
Browse files Browse the repository at this point in the history
Currently if the following situation happens

Server generates preview
Server has command removed which allows a preview to be shown
Client asks for preview, gets a 404 error when preview exists
(Mime checked before preview)

This happens more often with documents, or video as the commands are not
native PHP, they require a binary on the server.

After the fix the following would happen

Server generates preview
Server has command removed which allows a preview to be shown
Client asks for preview, gets preview which has been generated
(Mime checked after preview)

This would also allow offline generation (for example a docker image
containing the extra binaries), allowing a reduction in attack surface
of the instance serving the preview data.

Signed-off-by: Scott Dutton <scott@exussum.co.uk>
  • Loading branch information
exussum12 committed Apr 18, 2020
1 parent c79fa74 commit 4ab6721
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
if ($mimeType === null) {
$mimeType = $file->getMimeType();
}
if (!$this->previewManager->isMimeSupported($mimeType)) {
throw new NotFoundException();
}

$previewFolder = $this->getPreviewFolder($file);

Expand All @@ -154,7 +151,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
$crop = $specification['crop'] ?? false;
$mode = $specification['mode'] ?? IPreview::MODE_FILL;

// If both width and heigth are -1 we just want the max preview
// If both width and height are -1 we just want the max preview
if ($width === -1 && $height === -1) {
$width = $maxWidth;
$height = $maxHeight;
Expand All @@ -175,6 +172,10 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
try {
$preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
} catch (NotFoundException $e) {
if (!$this->previewManager->isMimeSupported($mimeType)) {
throw new NotFoundException();
}

if ($maxPreviewImage === null) {
$maxPreviewImage = $this->helper->getImage($maxPreview);
}
Expand Down

0 comments on commit 4ab6721

Please sign in to comment.