From 78f4ccb576af5571f171cf504009a75d9016c057 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Tue, 17 Aug 2021 23:14:08 +0100 Subject: [PATCH] [ImageEncoder] Fix ImageSanitization, it should never modify the input image --- plugins/ImageEncoder/ImageEncoder.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/ImageEncoder/ImageEncoder.php b/plugins/ImageEncoder/ImageEncoder.php index c3c452c0e3..3179589fe4 100644 --- a/plugins/ImageEncoder/ImageEncoder.php +++ b/plugins/ImageEncoder/ImageEncoder.php @@ -44,7 +44,6 @@ use SplFileInfo; * * @author Diogo Peralta Cordeiro * @author Hugo Sales - * * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ @@ -107,9 +106,12 @@ class ImageEncoder extends Plugin Log::debug("ImageEncoder's Vips couldn't handle the image file, failed with {$e}."); throw new UnsupportedFileTypeException(_m("Unsupported image file with {$mimetype}.", previous: $e)); } - $width = Common::clamp($image->width, 0, Common::config('attachments', 'max_width')); - $height = Common::clamp($image->height, 0, Common::config('attachments', 'max_height')); - $image = $image->crop(0, 0, $width, $height); + $width = $image->width; + $height = $image->height; + $image = $image->crop(left: 0, + top: 0, + width: $width, + height: $height); $image->writeToFile($temp->getRealPath()); // Replace original file with the sanitized one