php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75778 Corrupt PNG image causes non-recoverable fatal PHP error
Submitted: 2018-01-08 12:00 UTC Modified: 2018-01-08 13:47 UTC
From: info at e-abi dot ee Assigned: cmb (profile)
Status: Not a bug Package: GD related
PHP Version: 5.6.33 OS: Debian GNU/Linux 9 (stretch)
Private report: No CVE-ID: None
 [2018-01-08 12:00 UTC] info at e-abi dot ee
Description:
------------
Corrupt PNG image causes non-recoverable fatal PHP error.
PHP Fatal error:  imagecreatefrompng(): gd-png: fatal libpng error: Read Error

Also affected:
PHP 7.0.26
PHP 7.1.13
PHP 7.2.1


Test script:
---------------
<?php
ini_set('display_errors', 1);
#actual image location: http://www.knoraki.se/media/ACME_191101_440x440_1.png

echo print_r(gd_info(), true);

$image = false;
$filename = 'ACME_191101_440x440_1.png';
$image = imagecreatefrompng($filename);
//$image = getimagesize($filename);
if (!$image) {
	$image = 'failed';
}
echo print_r($image, true);


Expected result:
----------------
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [WebP Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

Warning: imagecreatefrompng(): gd-png:  fatal libpng error: Read Error: truncate
d data in D:\Bill-Data\tmp\php-gd-bug\image-test.php on line 8

Warning: imagecreatefrompng(): gd-png error: setjmp returns error condition in D
:\Bill-Data\tmp\php-gd-bug\image-test.php on line 8

Warning: imagecreatefrompng(): 'ACME_191101_440x440_1.png' is not a valid PNG fi
le in D:\Bill-Data\tmp\php-gd-bug\image-test.php on line 8
failed


Actual result:
--------------
root@vmi137424:/var/www/magento.eabi.ee/php-gd-bug# php7.1 image-test.php
Array
(
    [GD Version] => 2.2.4
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [WebP Support] => 1
    [JIS-mapped Japanese Font Support] =>
)
PHP Fatal error:  imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
 in /var/www/magento.eabi.ee/php-gd-bug/image-test.php on line 8

Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
 in /var/www/magento.eabi.ee/php-gd-bug/image-test.php on line 8

#notice how the final "failed" statement is not displayed because the script is halted.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-08 13:47 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-01-08 13:47 UTC] cmb@php.net
> [GD Version] => 2.2.4

Actually, this is not a PHP bug, but a problem of GD which has
been fixed as of GD 2.2.5, see
<https://github.com/libgd/libgd/issues/338>.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jul 04 12:03:36 2022 UTC