php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29482 imagecreatefrompng() throws fatal error (no warning) when opening broken images
Submitted: 2004-08-01 15:55 UTC Modified: 2016-04-03 17:37 UTC
Votes:11
Avg. Score:3.7 ± 1.4
Reproduced:8 of 9 (88.9%)
Same Version:3 (37.5%)
Same OS:1 (12.5%)
From: troublegum at woltlab dot de Assigned: krakjoe (profile)
Status: Closed Package: GD related
PHP Version: 5.0.0 OS: Windows XP Professional
Private report: No CVE-ID: None
 [2004-08-01 15:55 UTC] troublegum at woltlab dot de
Description:
------------
imagecreatefrompng() should not throw a fatal error
when opening broken image files. Instead, a warning would be much more useful. 

The following code is useless as the scripts dies without any output. If I remove the @, it throws the following message: 
---
Fatal error: imagecreatefrompng() [function.imagecreatefrompng]: gd-png: fatal libpng error: Invalid chunk length. in F:\htdocs\bug\read.php on line 3
---

imagecreatefrompng throws a warning when opening files that are no png files ('broken.png' is not a valid PNG file) but not when the image file is a png image, bug is broken for whatever reason. 


---
OS: Windows XP Professional
Apache: 2.0.49
PHP: 5.0.0 as apache module
GD: bundled (2.0.23 compatible)
PNG Support: enabled


Reproduce code:
---------------
<?php
$filename = 'broken.png';
$imageResource = @imagecreatefrompng($filename);
if (!$imageResource) {
	die('could not read ' . $filename . ' image');	
}
else {
	echo 'image ' . $filename . ' successfully read';	
}
?>

Expected result:
----------------
could not read broken.png image

Actual result:
--------------
Fatal error: imagecreatefrompng() [function.imagecreatefrompng]: gd-png: fatal libpng error: Invalid chunk length. in F:\htdocs\bug\read.php on line 3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-04 02:06 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Use the getimagesize() function to validate the image first 
if you are unsure about the file's contents. 
 [2004-08-04 02:46 UTC] troublegum at woltlab dot de
I got a PNG image, that works perfectly fine with getimagesize() (means the correct values for width and height are being extracted), but imagecreatefrompng() fails to open it (with the above error message). So this is definately not an option to sort out images, that can't be open with imagecreatefrompng().

If it's not a bug, then it's certainly an improvement for future php versions.
 [2004-08-04 13:49 UTC] troublegum at woltlab dot de
# The mentioned image can be downloaded at:
http://webpm.woltlab.info/misc/bugs.php.net/29482_broken.png

# The appropriate testcase here:
http://webpm.woltlab.info/misc/bugs.php.net/29482_test1.php.txt

# A demo of this behavior (running php4.3.5 with gd 2.0.17 (compatible))
http://webpm.woltlab.info/misc/bugs.php.net/29482_test1.php
 [2016-04-03 17:34 UTC] krakjoe@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2016-04-03 17:37 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: *General Issues +Package: GD related -Assigned To: +Assigned To: krakjoe
 [2016-04-03 17:37 UTC] krakjoe@php.net
The only E_ERROR raised by libgd is in the case of an actual terminal error.

As far as I can tell, the behaviour was changed, or is no longer applicable.

I don't know when that happened, sorry about the wait.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC