From 1ad94992aba401bee00494434ac7005fe0cc0a43 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 3 Jul 2026 17:52:34 +0530 Subject: [PATCH] (fix): reject images exceeding the area limit in preview pre-check --- .../Http/Buckets/Files/Preview/Get.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 0d4955a60b..a5562281d5 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -242,15 +242,20 @@ class Get extends Action $maxWidth = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_WIDTH); $maxHeight = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_HEIGHT); + $maxArea = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_AREA); $dimensions = \getimagesizefromstring($source); - if ( - $dimensions !== false && - (($maxWidth > 0 && $dimensions[0] > $maxWidth) || ($maxHeight > 0 && $dimensions[1] > $maxHeight)) - ) { - throw new Exception( - Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED, - \sprintf('Image resolution %dx%d exceeds the maximum allowed %dx%d pixels', $dimensions[0], $dimensions[1], $maxWidth, $maxHeight) - ); + if ($dimensions !== false) { + [$width, $height] = $dimensions; + if ( + ($maxWidth > 0 && $width > $maxWidth) || + ($maxHeight > 0 && $height > $maxHeight) || + ($maxArea > 0 && $width * $height > $maxArea) + ) { + throw new Exception( + Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED, + \sprintf('Image resolution %dx%d exceeds the maximum allowed %dx%d or %d total pixels', $width, $height, $maxWidth, $maxHeight, $maxArea) + ); + } } try {