From:             polone at townnews dot com
Operating system: RedHat Linux 7.3
PHP version:      4.3.11
PHP Bug Type:     GetImageSize related
Bug description:  getimagesize() fails to detect width/height on certain JPEGs

Description:
------------
The getimagesize() function fails on specific JPEG files. The reason is
that php_next_marker() in:

ext/standard/image.c

has an artificial limit of 10 imposed on the number of 0xFF records that
are found in sequential order. As far as I can tell ... the JPEG file
format standards impose no such limit (see,
http://www.jpeg.org/public/jfif.pdf). The proper behaviour should be to
continue to read for the next marker until:

(1) M_SOS is found, in which case, image data has begun and no more
headers will occur
(2) M_EOI has occurred (End of Image header) - this is the proper behavior
in a properly encoded image
(3) EOF - something's wrong - but, at least it's not getimagesize()

I've provided an example of a JPEG file that will fail using
getimagesize() online at:

http://www.townnews.com/contrib/premature.jpg

A fix is easily added by removing the artificial limit and just
incrementing "a" in the marker's main loop around line 404:

if (++a > 10)
{
    /* who knows the maxim amount of 0xff? though 7 */
    /* but found other implementations              */
    return M_EOI;

}

I realize this may be in place to prevent infinite loops, but the reality
is EOF will do that for us anyway. To fix the problem, just switch that
code hunk too:

a++;

Reproduce code:
---------------
<?php

$sURL = "http://www.townnews.com/contrib/premature.jpg";;
print_r(getimagesize($sURL));

?>

Expected result:
----------------
Array
(
    [0] => 350
    [1] => 603
    [2] => 2
    [3] => width="350" height="603"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)



-- 
Edit bug report at http://bugs.php.net/?id=33210&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33210&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33210&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33210&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33210&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33210&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33210&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33210&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33210&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33210&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33210&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33210&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33210&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33210&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33210&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33210&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33210&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33210&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33210&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33210&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33210&r=mysqlcfg

Reply via email to