From 41875685221582eeff6f4316640f6fac83492dbb Mon Sep 17 00:00:00 2001 From: Miguel Dantas Date: Fri, 28 Jun 2019 01:44:51 +0100 Subject: [PATCH] [OEMBED][UI] Skip adding an image thumbnail for oembed results if we don't have a file locally to generate it, which can happen, for instance, if StoreRemoteMedia is disabled --- actions/attachment_thumbnail.php | 7 +++++-- lib/imagefile.php | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/actions/attachment_thumbnail.php b/actions/attachment_thumbnail.php index 3e5fbf222f..f0a54883b1 100644 --- a/actions/attachment_thumbnail.php +++ b/actions/attachment_thumbnail.php @@ -72,9 +72,12 @@ class Attachment_thumbnailAction extends AttachmentAction $filepath = $file->getPath(); $size = $file->size; } - } catch (InvalidFilenameException $e) { + // XXX PHP: Upgrade to PHP 7.1 + // FileNotFoundException | InvalidFilenameException + } catch (Exception $e) { // We don't have a file to display - return; + $this->clientError(_('No such attachment.'), 404); + return false; } $filename = MediaFile::getDisplayName($file); diff --git a/lib/imagefile.php b/lib/imagefile.php index 2138a03e60..1bbadd0b24 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -535,6 +535,11 @@ class ImageFile extends MediaFile throw new ServerException('No File object attached to this ImageFile object.'); } + // File not stored locally, can't generate a thumbnail + if (empty($this->fileRecord->filename)) { + throw new FileNotStoredLocallyException($this->fileRecord); + } + if ($width === null) { $width = common_config('thumbnail', 'width'); $height = common_config('thumbnail', 'height'); -- 2.39.5