php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77982 Valid PNG file does not resize and outputs a strange error
Submitted: 2019-05-07 15:10 UTC Modified: 2019-05-19 04:22 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mark at kreine dot com Assigned: cmb (profile)
Status: No Feedback Package: GD related
PHP Version: 7.3.5 OS: CentOS 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mark at kreine dot com
New email:
PHP Version: OS:

 

 [2019-05-07 15:10 UTC] mark at kreine dot com
Description:
------------
I'm trying to resize a PNG file. Instead of an actual resizing, I can see a very strange error, which perhaps has nothing to do with my code. 

The file that I use is here: https://imgur.com/vjnDpJq
I have myself opened GIMP and draw this, so this cannot be invalid PNG file. 

This is the error that's being always reproduced:
[Tue May 07 16:58:42.573572 2019] [php7:warn] [pid 7539:tid 140392702551808] [client 127.0.0.1:42140] PHP Warning:  imagecreatefrompng(): gd-png error: cannot allocate libpng main struct in /var/www/sites/photogallery/index.php on line 7


Here is a configure string, which was used in order to compile PHP:

./configure --prefix=/soft/php --with-apxs2=/soft/httpd/bin/apxs --with-libxml-dir=/soft/libxml --with-png-dir=/soft/libpng --with-curl=shared,/soft/curl --with-bz2=shared,/soft/bzip --with-mysqli=shared,/soft/mysql/bin/mysql_config --with-gettext=shared,/soft/gettext --with-pcre-dir=/soft/pcre --with-jpeg-dir=/soft/libjpeg --with-gd=shared --with-zlib=shared,/soft/zlib --with-pdo-mysql=shared,/soft/mysql --enable-calendar --enable-mbstring --enable-bcmath --enable-ftp --enable-zip --enable-soap --enable-exif --enable-intl --enable-sockets 



Test script:
---------------
function resizePng($new_width, $new_height)
{
	$file = "/var/www/sites/photogallery/image.png";
	$im = imagecreatefrompng($file);
	$imnew = imagecreatetruecolor($new_width, $new_height);
	imagecopyresized($imnew, $im, 0, 0, 0, 0, $new_width, $new_height, 1920, 1080);
	header("Content-type: image/png");
	imagepng($imnew);
}



Expected result:
----------------
Resized PNG which is to be outputted in browser.

Actual result:
--------------
An error as follows: 

[Tue May 07 16:58:42.573572 2019] [php7:warn] [pid 7539:tid 140392702551808] [client 127.0.0.1:42140] PHP Warning:  imagecreatefrompng(): gd-png error: cannot allocate libpng main struct in /var/www/sites/photogallery/index.php on line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-07 18:24 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2019-05-08 07:13 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2019-05-08 07:13 UTC] cmb@php.net
The error message is raised by libgd, because
png_create_read_struct() returns NULL to signal failure[1].  A
possible reason for this failure is that the libpng version PHP
has been built against is incompatible with the libpng version
that is used at runtime.  Make sure that this is not the case.

[1] <https://github.com/php/php-src/blob/php-7.3.5/ext/gd/libgd/gd_png.c#L154-L162>
 [2019-05-19 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC