From b6129dcde58456a1d297adcfc6e00549ca66a586 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 15 Oct 2011 20:36:02 +0000 Subject: [PATCH] Per bug 28135, disable $wgMaxImageArea check when transforming using a hook, and enable the check for non IM scalers. --- RELEASE-NOTES-1.19 | 2 ++ includes/media/Bitmap.php | 46 ++++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index a07c7b30ff..ce48ecf0e7 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -15,6 +15,8 @@ production. * (bug 27132) movefile right granted by default to registered users. * Default cookie lifetime ($wgCookieExpiration) is increased to 180 days. * (bug 31204) Removed old user.user_options +* $wgMaxImageArea now applies to jpeg files if they are not scaled with + ImageMagick. === New features in 1.19 === * (bug 19838) Possibility to get all interwiki prefixes if the interwiki diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 6c576153b9..a5cc711d9a 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -21,7 +21,7 @@ class BitmapHandler extends ImageHandler { * @return bool */ function normaliseParams( $image, &$params ) { - global $wgMaxImageArea; + if ( !parent::normaliseParams( $image, $params ) ) { return false; } @@ -42,20 +42,44 @@ class BitmapHandler extends ImageHandler { return true; } } - + + return true; + } + + /** + * Check if the file is smaller than the maximum image area for + * thumbnailing. Check will always pass if the scaler is 'hookaborted' or + * if the scaler is 'im' and the mime type is 'image/jpeg' + * + * @param File $image + * @param string $scaler + */ + function checkImageArea( $image, $scaler ) { + global $wgMaxImageArea; # Don't thumbnail an image so big that it will fill hard drives and send servers into swap # JPEG has the handy property of allowing thumbnailing without full decompression, so we make # an exception for it. - # @todo FIXME: This actually only applies to ImageMagick - if ( $mimeType !== 'image/jpeg' && - $srcWidth * $srcHeight > $wgMaxImageArea ) + + + if ( $image->getMimeType() == 'image/jpeg' && $scaler == 'im' ) { - return false; + # ImageMagick can efficiently downsize jpg images without loading + # the entire file in memory + return true; } - - return true; + + if ( $scaler == 'hookaborted' ) + { + # If a hook wants to transform the image, it is responsible for + # checking the image size, so abort here + return true; + } + + # Do the actual check + return $this->getImageArea( $image, $image->getWidth(), $image->getHeight() ) <= $wgMaxImageArea; } + /** * Extracts the width/height if the image will be scaled before rotating * @@ -160,6 +184,12 @@ class BitmapHandler extends ImageHandler { wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" ); $scaler = 'hookaborted'; } + + # Check max image area + if ( !$this->checkImageArea( $image, $scaler ) ) + { + return new TransformParameterError( $params ); + } switch ( $scaler ) { case 'hookaborted': -- 2.20.1