From 9bac11e57439a075007abe4776eee5c7703da9c1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 24 Aug 2023 18:10:14 +0200 Subject: [PATCH] Prevent attempts to generate thumbnails for underflowing images --- .../upload/DefaultUploadFileSaveStrategy.class.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/upload/DefaultUploadFileSaveStrategy.class.php b/wcfsetup/install/files/lib/system/upload/DefaultUploadFileSaveStrategy.class.php index 0d8b6d5a66..9d53ccad1a 100644 --- a/wcfsetup/install/files/lib/system/upload/DefaultUploadFileSaveStrategy.class.php +++ b/wcfsetup/install/files/lib/system/upload/DefaultUploadFileSaveStrategy.class.php @@ -331,7 +331,18 @@ class DefaultUploadFileSaveStrategy implements IUploadFileSaveStrategy $updateData[$prefix . 'Height'] = 0; } - if ($file->width > $sizeData['width'] || $file->height > $sizeData['height']) { + // Thumbnails should only be created if at least one side exceeds the + // dimensions of the thumbnail and the other side is at least of equal + // size. This prevents attempts to create a thumbnail of an image that + // underflows the thumbnail dimensions on one side. + $createThumbnail = false; + if ($file->width > $sizeData['width'] && $file->height >= $sizeData['height']) { + $createThumbnail = true; + } else if ($file->height > $sizeData['height'] && $file->width >= $sizeData['width']) { + $createThumbnail = true; + } + + if ($createThumbnail) { try { $thumbnail = $adapter->createThumbnail( $sizeData['width'], -- 2.20.1