php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45799 imagepng() crashes on empty image
Submitted: 2008-08-12 13:29 UTC Modified: 2009-03-14 16:34 UTC
From: amelek32 at gmail dot com Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 5.2.8, 5.3CVS, 6CVS (2008-12-09) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: amelek32 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-12 13:29 UTC] amelek32 at gmail dot com
Description:
------------
imagepng *crashes* when no color was alocated.

I see no point in rendering blank images, but this functions behavior is buggy. 

All other functions (imagejpeg, imagegif) AND imagepng on true scale images return black image. This is most likely expected result.

Instead, this function flushes some part of header and then crashes with warnings when trying to convert non existing color palette.

GD Version  bundled (2.0.34 compatible)  

Reproduce code:
---------------
<?
$img = imagecreate(500,500);
//header("Content-type: image/png"); // skip this to see the problem, else browser will ignore corrupted image.
imagepng($img);
imagedestroy($img);
?>

Expected result:
----------------
blank black image (like other image* functions) or E_WARNING without junk.

Actual result:
--------------
?PNG  IHDR???M?
Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: Invalid number of colors in palette in C:\usr\apache\httpd\html\draw.php on line 21

Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in C:\usr\apache\httpd\html\draw.php on line 21

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-12 13:37 UTC] pajoye@php.net
That's libpng behaviors. A PNG palette image must have colors to be saved.

By the way, warnings are not crashes.
 [2008-08-12 13:45 UTC] amelek32 at gmail dot com
shouldn't it return warning without putting part of header to output?
 [2008-08-12 14:25 UTC] pajoye@php.net
> shouldn't it return warning without putting part of header to output?

Hm, good point. I may add a check before calling the png function and avoid to much troubles later. I will do it for 5.3+
 [2008-11-30 22:52 UTC] pajoye@php.net
Well, after a 2nd look, the warning will remain anyway. Whether it is raised by libgd or php does not change anything > won't fix
 [2008-12-01 11:00 UTC] amelek32 at gmail dot com
then

<?
$img = imagecreate(500,500);
@imagepng($img);
imagedestroy($img);
?>

should return empty page..

However, it do not ;)
 [2008-12-01 11:02 UTC] pajoye@php.net
My bad, you are right!
 [2009-03-10 11:25 UTC] mmcnicklebugs at googlemail dot com
[PATCH]

A to see if there are any colors associated with the image before outputting the image header.

http://whompbox.com/patches/php/libgd.patch
 [2009-03-14 16:34 UTC] tabe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for your patch, from which I made a fix in 5.3 and 6CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC