From: brian at gtv dot com Operating system: FreeBSD 5.4 PHP version: 5.1.1 PHP Bug Type: GetImageSize related Bug description: Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type
Description: ------------ I am using the GetImageSize function in a function I wrote which validates the width, height, and type of an image as the user uploads it to my website. On my website I have setup a number of different fields where a user can upload different images that are very specific to the width, height, and type that I allow for each field. For example in field one I allow the user to upload an image of width=512, height=315, and type=BMP and in field two I allow the user to upload an image of width=48, height=48, and type=ICO and in field three I allow the user to upload an image of width=176, height=36, and type=GIF. My problem is that the GetImageSize function does not currently support the ICO file type and the image/vnd.microsoft.icon mime type. When I upload a ICO image and use the GetImageSize function on the image the $image_size_array[0], $image_size_array[1], and $image_size_array[2] are blank as well as the $image_size_array['mime'] being blank. This means I can't validate the width, height, or file type of the ICO images that are being uploaded. Which defeats the purpose of validating the files for a good number of the images in this section of my website. >From my review of the bug report DB I have not seen anyone else report this problem and I'm a little shocked to see that no one else would need support for ICO images in PHP. It may just be the type of website I'm building and the type of company I work for - a software company - where we are using these ICO images that are uploaded from our customers in our software. However I think it would be a good idea to add support into PHP for this fairly common image format that is widely used. Reproduce code: --------------- function validateGraphic($image, $width, $height, $type){ $err_text = ""; if(!isset($image)) { $err_text .= "You must select an image file to upload.<br>\n"; } if($image['error'] > '0') { $err_text .= "There was an error uploading the image file.<br>\n"; } if($image['error'] == '0') { $image_size_array = getimagesize($image['tmp_name']); //check the width of the image if($image_size_array[0] > $width) { $err_text .= "Image is too wide. It is {$image_size_array[0]} pixels wide.<br>\n"; } if($image_size_array[0] < $width) { $err_text .= "Image is too narrow. It is {$image_size_array[0]} pixels wide.<br>\n"; } //check the height of the image if($image_size_array[1] > $height) { $err_text .= "Image is too tall. It is {$image_size_array[1]} pixels tall.<br>\n"; } if($image_size_array[1] < $height) { $err_text .= "Image is too short. It is {$image_size_array[1]} pixels tall.<br>\n"; } //check the type of the image switch($image_size_array['mime']) { case 'image/gif': if($type != "GIF") { $err_text .= "Image is wrong type. It is a GIF and should be a {$type}.<br>\n"; } break; case 'image/jpeg': if($type != "JPG") { $err_text .= "Image is wrong type. It is a JPG and should be a {$type}.<br>\n"; } break; case 'image/vnd.microsoft.icon': if($type != "ICO") { $err_text .= "Image is wrong type. It is a ICO and should be a {$type}.<br>\n"; } break; case 'image/bmp': if($type != "BMP") { $err_text .= "Image is wrong type. It is a BMP and should be a {$type}.<br>\n"; } break; default: $err_text .= "Image is wrong type. It is a {$image_size_array['mime']} and should be a {$type}.<br>\n"; break; } } return $err_text; } This function is called in this type of manner: $error_txt .= validateGraphic($_FILES['upload1'], '142', '114', 'ICO'); Expected result: ---------------- When function is called in manner described and the ICO image that matches is uploaded I expect no error messages to be produced, the file to be uploaded, and the entry to be added into my DB. I'm expecting the GetImageSize function to handle the ICO file type and the image/vnd.microsoft.icon mime type, but because it can't this is breaking my validation function. Actual result: -------------- Instead I get the following error messages: Image is too narrow. It is pixels wide. Image is too short. It is pixels tall. Image is wrong type. It is a and should be a ICO. -- Edit bug report at http://bugs.php.net/?id=35783&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35783&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35783&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35783&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=35783&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35783&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35783&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35783&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35783&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35783&r=support Expected behavior: http://bugs.php.net/fix.php?id=35783&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35783&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35783&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35783&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35783&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35783&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35783&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35783&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35783&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35783&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35783&r=mysqlcfg