GD zero filesize error
authorDan Mattern <dan@danmattern.com>
Mon, 19 Feb 2018 22:59:17 +0000 (17:59 -0500)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Feb 2018 03:59:33 +0000 (03:59 +0000)
Checking if the filesize is zero before passing to GD. This can result
in a fatal error.

Bug: T182387
Change-Id: I26a24286f3035f233de682caed21a8e8c2d5aaad

includes/media/Bitmap.php
languages/i18n/en.json
languages/i18n/qqq.json

index 712906e..b88a34d 100644 (file)
@@ -440,6 +440,14 @@ class BitmapHandler extends TransformationalImageHandler {
                        return $this->getMediaTransformError( $params, $errMsg );
                }
 
+               if ( filesize( $params['srcPath'] ) === 0 ) {
+                       $err = "Image file size seems to be zero.";
+                       wfDebug( "$err\n" );
+                       $errMsg = wfMessage( 'thumbnail_image-size-zero', $params['srcPath'] )->text();
+
+                       return $this->getMediaTransformError( $params, $errMsg );
+               }
+
                $src_image = call_user_func( $loader, $params['srcPath'] );
 
                $rotation = function_exists( 'imagerotate' ) && !isset( $params['disableRotation'] ) ?
index b710762..bcf0ec5 100644 (file)
        "thumbnail_dest_directory": "Unable to create destination directory",
        "thumbnail_image-type": "Image type not supported",
        "thumbnail_gd-library": "Incomplete GD library configuration: Missing function $1",
+       "thumbnail_image-size-zero": "Image file size seems to be zero.",
        "thumbnail_image-missing": "File seems to be missing: $1",
        "thumbnail_image-failure-limit": "There have been too many recent failed attempts ($1 or more) to render this thumbnail. Please try again later.",
        "import": "Import pages",
index 6a071ed..852d3eb 100644 (file)
        "thumbnail_image-type": "This is the parameter 1 of the message {{msg-mw|thumbnail error}}",
        "thumbnail_gd-library": "This is the parameter 1 of the message {{msg-mw|thumbnail error}}.\n*$1 is a function name of the GD library",
        "thumbnail_image-missing": "This is the parameter 1 of the message {{msg-mw|thumbnail error}}.\n*$1 is the path incl. filename of the missing image",
+       "thumbnail_image-size-zero": "This is the parameter 1 of the message {{msg-mw|thumbnail error}}.\n*$1 is the path incl. filename of the image with zero size",
        "thumbnail_image-failure-limit": "Used as <code>$1</code> in {{msg-mw|Thumbnail error}}.\n\nParameters:\n* $1 - the maximum allowed number of failed attempts",
        "import": "The title of the special page [[Special:Import]];",
        "import-summary": "{{doc-specialpagesummary|import}}",