From b91c564b91f7a190e6cdf89592d38682eee08e7e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Apr 2024 16:28:27 +0200 Subject: [PATCH] Prevent the generation of thumbnails for small images --- .../lib/system/file/processor/FileProcessor.class.php | 6 ++++++ .../lib/system/image/adapter/ImageAdapter.class.php | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php index fe6639b445..2ffb4e40cf 100644 --- a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php +++ b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php @@ -102,6 +102,12 @@ final class FileProcessor extends SingletonFactory continue; } + // Check if we the source image is larger than the dimensions of the + // requested thumbnails. + if ($format->width > $file->width && $format->height > $file->height) { + continue; + } + if ($imageAdapter === null) { $imageAdapter = ImageHandler::getInstance()->getAdapter(); $imageAdapter->loadFile($file->getPathname()); diff --git a/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php index 2f59a1c949..9420f2d51a 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php @@ -80,7 +80,15 @@ class ImageAdapter implements IImageAdapter, IMemoryAwareImageAdapter public function createThumbnail($maxWidth, $maxHeight, $preserveAspectRatio = true) { if ($maxWidth > $this->getWidth() && $maxHeight > $this->getHeight()) { - throw new SystemException("Dimensions for thumbnail can not exceed image dimensions."); + throw new SystemException( + \sprintf( + "Dimensions for thumbnail can not exceed image dimensions (requested: %d × %d, actual: %d × %d).", + $maxWidth, + $maxHeight, + $this->getWidth(), + $this->getHeight(), + ) + ); } $maxHeight = \min($maxHeight, $this->getHeight()); -- 2.20.1