php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73986 imagecreatefromstring now gives Fatal Error instead of Warning and return false
Submitted: 2017-01-24 13:07 UTC Modified: 2017-02-27 16:08 UTC
From: greg at gregoriol dot net Assigned: cmb (profile)
Status: Duplicate Package: GD related
PHP Version: 7.0.15 OS: Ubuntu 16.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: greg at gregoriol dot net
New email:
PHP Version: OS:

 

 [2017-01-24 13:07 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-24 13:10 UTC] 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:22 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2017-01-24 13:22 UTC] cmb@php.net
> 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>.
 [2017-02-27 15:54 UTC] greg at gregoriol dot net
Well, maybe it is a GD bug, but why did it work in php 7.0.8 and not anymore in 7.0.13? What did change?
 [2017-02-27 16:08 UTC] cmb@php.net
> […] but why did it work in php 7.0.8 and not anymore in 7.0.13?

Bug #70315 has been fixed with commit d811464[1], and now the
error reported by external libgd is actually treated as PHP error;
formerly it had been erroneously mapped to an unknow PHP error.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=6cb75fb1e8208d79f58351340923059d0d077ee6>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC