Bug #73986 [Opn->Dup]: imagecreatefromstring now gives Fatal Error instead of Warning and return false

From: Date: Tue, 24 Jan 2017 13:22:27 +0000
Subject: Bug #73986 [Opn->Dup]: imagecreatefromstring now gives Fatal Error instead of Warning and return false
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206918@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73986&edit=1 ID: 73986 Updated by: cmb@php.net Reported by: greg at gregoriol dot net Summary: imagecreatefromstring now gives Fatal Error instead of Warning and return false -Status: Open +Status: Duplicate Type: Bug Package: GD related Operating System: Ubuntu 16.04 PHP Version: 7.0.15 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > This could be related to #73479 and #73514, Actually, this issue has the same cause as bug #73479, and would have to be resolved in libgd, see <https://github.com/libgd/libgd/issues/338>. Previous Comments: ------------------------------------------------------------------------ [2017-01-24 13:10:27] fortin81 at gmail dot com This could be related to #73479 and #73514, but is not exactly the same as these two are about GD and JPEGs while here we have more of GD and PNG. ------------------------------------------------------------------------ [2017-01-24 13:07:36] greg at gregoriol dot net 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 this bug report at https://bugs.php.net/bug.php?id=73986&edit=1

« previous php.bugs (#206918) next »