php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72278 getimagesize returning FALSE on valid jpg
Submitted: 2016-05-27 20:45 UTC Modified: 2016-08-13 16:25 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: bfarber at invisiopower dot com Assigned: cmb (profile)
Status: Closed Package: GetImageSize related
PHP Version: 5.6.22 OS: AWS / Windows
Private report: No CVE-ID: None
 [2016-05-27 20:45 UTC] bfarber at invisiopower dot com
Description:
------------
The documentation for getimagesize() indicates the function returns FALSE on failure, so the function is behaving as described, however I cannot find any reason getimagesize() should be failing to parse this particular image. A client has supplied a valid jpeg image and I can read the EXIF data from it with a standalone parser, but getimagesize() fails to parse it.

We have tested on multiple versions and have seen the same behavior on all environments we've tested on. I have not tested PHP7 yet. I have tested on Amazon's hosting environment, as well as my local WAMP stack.

http://bfarber.com/getimagesize_test/test.php
Image can be found here: http://bfarber.com/getimagesize_test/image.jpg

Test script:
---------------
<?php

ini_set('display_errors',1);
error_reporting(E_ALL);

print "PHP version is " . PHP_VERSION . "<br>";
var_dump( getimagesize('image.jpg') );
exit;

Expected result:
----------------
I should see an array output with the image width, height, etc.

Actual result:
--------------
boolean false is returned

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-27 22:28 UTC] requinix@php.net
-Status: Open +Status: Analyzed
 [2016-05-27 22:28 UTC] requinix@php.net
The image has some extra bytes in it that are messing up the detection, but there's not much technical information about JPEGs out there and the standard itself is paywalled so I can't verify if it's technically legal or just a vendor quirk. If I open the image in GIMP it warns me about the extra bytes and recovers.

Those extra bytes are part of the 0xE1 Exif frame starting at offset 0x15. It says length 0x7D08/32008 but there are then 260 bytes of 0x00 unaccounted for until the next 0xFFED. Image suggests it's from Photoshop CS2?

Could image.c's php_next_marker gracefully handle this situation? Automatically consume any "leading" nulls it finds?
 [2016-05-28 04:01 UTC] pajoye@php.net
-Status: Analyzed +Status: Feedback
 [2016-05-28 04:01 UTC] pajoye@php.net
Can you upload the image somewhere pls or send it to me pls?
 [2016-06-05 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2016-06-05 04:47 UTC] requinix@php.net
-Status: No Feedback +Status: Open
 [2016-06-05 04:47 UTC] requinix@php.net
@bfarber uploaded one to http://bfarber.com/getimagesize_test/image.jpg, which is still accessible. (I've tried a couple free hosting places but they reprocess images.)
 [2016-06-05 04:47 UTC] requinix@php.net
-Status: Open +Status: Analyzed
 [2016-08-06 23:34 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-08-13 12:59 UTC] cmb@php.net
While fixing this issue, I've stumbled upon bug #13213, which has
been fixed for that very special case only. IMO, it would have
been better to follow mul at rentapacs dot com's suggestion to
simply skip any extraneous bytes (plus raising a warning). That
appears also the solution chosen by ImageMagick, but not by ext/gd
(I'll have a closer look at that later).
 [2016-08-13 14:40 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82df4e263886a0da21a00c98189649287666ba5c
Log: Fix #72278: getimagesize returning FALSE on valid jpg
 [2016-08-13 14:40 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2016-08-13 16:25 UTC] cmb@php.net
> That appears also the solution chosen by ImageMagick, but not by
> ext/gd.

For the record: the behavior of ext/gd depends on the ini setting
gd.jpeg_ignore_warnings. If this is enabled, the corrupted image
can be read; otherwise imagecreatefromjpeg() returns FALSE when
build against classic libjpeg. Apparently, libjpeg-turbo doesn't
even report an unrecoverable error here, so the image could always
be read.
 [2016-10-17 10:09 UTC] bwoebi@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82df4e263886a0da21a00c98189649287666ba5c
Log: Fix #72278: getimagesize returning FALSE on valid jpg
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC