Bug #73986 [NEW]: imagecreatefromstring now gives Fatal Error instead of Warning and return false

From: Date: Tue, 24 Jan 2017 13:07:43 +0000
Subject: Bug #73986 [NEW]: imagecreatefromstring now gives Fatal Error instead of Warning and return false
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206916@lists.php.net to get a copy of this message
From: greg at gregoriol dot net Operating system: Ubuntu 16.04 PHP version: 7.0.15 Package: GD related Bug Type: Bug Bug description:imagecreatefromstring now gives Fatal Error instead of Warning and return false Description: ------------ In a script, we are using PHP and GD function imagecreatefromstring to read image files and check if they are valid images. We don't know at this point if it is a jpeg/png/..., it could be a base64 encoded string too. This gave us a return value of true if the image was valid, and false if the image was invalid, which was grat. Now, the same code PHP gives a Fatal Error, and we can't find a way to implement the same check as before... We don't really care about the warnings GD emits: we know some of the files will be "invalid". But we really care about the bool(false) result as this was our way to check the file. NB: invalid images could be Apple crushed PNGs like in the test script file. Test script: --------------- <?php $b = file_get_contents('https://www.gregoriol.net/tmp/AppIcon.png'); $r = imagecreatefromstring($b); var_dump($r); Expected result: ---------------- $ php -v PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies $ php test-imagecreatefromstring.php PHP Unknown error: imagecreatefromstring(): gd-png: fatal libpng error: CgBI: unknown critical chunk in Unknown on line 0 PHP Parse error: imagecreatefromstring(): gd-png error: setjmp returns error condition 1 in test-imagecreatefromstring.php on line 5 PHP Warning: imagecreatefromstring(): Passed data is not in 'PNG' format in test-imagecreatefromstring.php on line 5 PHP Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in test-imagecreatefromstring.php on line 5 bool(false) Actual result: -------------- $ php -v PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies $ php test-imagecreatefromstring.php PHP Fatal error: imagecreatefromstring(): gd-png: fatal libpng error: CgBI: unknown critical chunk in test-imagecreatefromstring.php on line 5 -- Edit bug report at https://bugs.php.net/bug.php?id=73986&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73986&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73986&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73986&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73986&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73986&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73986&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73986&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73986&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73986&r=support Expected behavior: https://bugs.php.net/fix.php?id=73986&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73986&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73986&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73986&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73986&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73986&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73986&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73986&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73986&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73986&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73986&r=mysqlcfg

« previous php.bugs (#206916) next »