php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #23747 GD-PNG fatal error
Submitted: 2003-05-22 02:33 UTC Modified: 2004-04-03 11:02 UTC
From: rryda at mgedata dot cz Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.2RC4 OS: Windows 2000
Private report: No CVE-ID: None
 [2003-05-22 02:33 UTC] rryda at mgedata dot cz
Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: IDAT: CRC error in .....

The error appears only if PHP is run as CGI (php.exe).

This functionality was used in 4.3.2RC3 successfully.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-22 05:56 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2003-05-22 06:15 UTC] rryda at mgedata dot cz
More info:

- PHP is run as CGI
- using original windows binary pack
- php_gd2.dll from original windows binary pack
- web server: Apache 2.0.45

Imagecreatefrompng() is used in following code:

//$image_file_url ... URL to the source 24-bit PNG file

	$image_base = ImageCreateTrueColor($map_width, $map_height);
	$white = ImageColorExact($image_base, 255, 255, 255);
	ImageFill($image_base, 0, 0, $white);

	// ........

	$input = fopen($image_file_url, "rb");
	$image_data = fread($input, 2000000);
	fclose($input);

	$image_file = tempnam("", "gd".rand(0, 10000));
	$output = fopen($image_file, "w+b");
	fwrite($output, $image_data);
	fclose($output);

	$image_tmp = ImageCreateFromPNG($image_file); // ERROR

	// ........
 [2003-05-22 08:13 UTC] derick@php.net
It just looks like your image is broken, can you put up a runnable script + image in a tarball (or send it to me by mail) to verify?

Derick
 [2003-05-23 06:49 UTC] wez@php.net
Not really a bug; fread() will now (correctly!) return data in packet sized chunks when reading from network streams, as it did in PHP 4.2.x and earlier.

Technically, your script is broken; you should either do this:

<?php
$data = "";
$fp = fopen("http://....");
do {
   $chunk = fread($fp, 8192);
   if (strlen($chunk) == 0) {
      break;
   }
   $data .= $chunk;
} while (true);
fclose($fp);
?>

this:
<?php
$data = file_get_contents("http://...");
?>

or this:
<?php
copy("http://...", tempnam("", "gd"));
?>

I'm making this a documentation problem, because the fread() manual page has never mentioned this fact, despite it being the behaviour since forever.

One final note; the file_get_contents() and copy() functions were themselves suffering from a similar problem to that of your script; I've committed a fix to CVS, so you need to either use the fread() loop approach, or get the next stable snapshot (due in an hour or so).

 [2003-05-23 06:52 UTC] wez@php.net
of course, the copy() version should look like this:
<?php
$local = tempnam("", "gd");
copy("http://", $local);
?>
otherwise you don't know where you copied it to...
 [2003-08-29 09:45 UTC] simon at simonwheatley dot co dot uk
I have also intermittently encountered this error.

Running PHP on Xcalibre.co.uk
http://daffy.xcalibre.co.uk/phpinfo.php
I believe they run Slackware.

My images were created by the imagepng() and are edited by php only.

My first thought was that two instances of the script were accessing the same image?
 [2004-04-03 11:02 UTC] nlopess@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.


 [2004-05-18 03:11 UTC] free_2_cheat1990 at yahoo dot com
i made a script to add dots to an image and if you run it to many times you also get the error "Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: IDAT: CRC"

i run mandrake linux 9.2
apache 2
php 4.3.3
gdlib 2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 03:01:28 2024 UTC