Req #29482 [Opn->Csd]: imagecreatefrompng() throws fatal error (no warning) when opening broken images

From: Date: Sun, 03 Apr 2016 17:37:29 +0000
Subject: Req #29482 [Opn->Csd]: imagecreatefrompng() throws fatal error (no warning) when opening broken images
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200324@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=29482&edit=1

 ID:                 29482
 Updated by:         krakjoe@php.net
 Reported by:        troublegum at woltlab dot de
 Summary:            imagecreatefrompng() throws fatal error (no warning)
                     when opening broken images
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            *General Issues
+Package:            GD related
 Operating System:   Windows XP Professional
 PHP Version:        5.0.0
-Assigned To:        
+Assigned To:        krakjoe
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2004-08-04 13:49:41] 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

------------------------------------------------------------------------
[2004-08-04 02:46:38] 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 02:06:08] 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-01 15:55:51] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=29482&edit=1


Thread (5 messages)

« previous php.bugs (#200324) next »