Bug #70276 [NEW]: gd-png: fatal libpng error: bad parameters to zlib

From: Date: Sat, 15 Aug 2015 12:36:08 +0000
Subject: Bug #70276 [NEW]: gd-png: fatal libpng error: bad parameters to zlib
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195229@lists.php.net to get a copy of this message
From:             bugs dot php dot net at spectrumcs dot net
Operating system: FreeBSD 10.0-RELEASE-p17
PHP version:      5.6.12
Package:          GD related
Bug Type:         Bug
Bug description:gd-png:  fatal libpng error: bad parameters to zlib

Description:
------------
I'm migrating a Wordpress site from one server another and I've run to
to a problem with some of the images not being displayed. The images are
being piped though a PHP script to dynamically resize them. After some
investigation I've noticed that the issue is only effecting PNG images
and found errors relating to gd-png in the webserver logs. As a test I
created a simple php script which just opens a PNG with
imagecreatefrompng and every time access the script via a browser I get
the following errors...

PHP Warning:  imagecreatefrompng(): gd-png:  fatal libpng error: bad
parameters to zlib in .../test.php on line 10

PHP Warning:  imagecreatefrompng(): gd-png error: setjmp returns error
condition in .../test.php on line 10

PHP Warning:  imagecreatefrompng(): 'test.png' is not a valid PNG file
in .../test.php on line 10

I have tried several different png's from several different sources in
case the png's where the problem, but alias it seems to effect all png's
regardless of origin.

Most interestingly, if I run the same script from the command line (su'd
to the webserver user!) I do not get the errors (I get the raw PNG but
that's expected).

I'm not sure if that makes it a PHP problem of an webserver problem, but
I can't think of any reason why running the script via the webserver
should cause such a problem. No permission issues are in play. 

I have two webservers setup very similar, both experience the same
problem.

My apologies if this is not the correct place to report such a problem.

Note, I spent quite a few hours on this yesterday evening and was
running PHP 5.6.11 but I have this morning upgraded to 5.6.12 and the
problem persists. 

# uname -a
FreeBSD indigo 10.0-RELEASE-p17 FreeBSD 10.0-RELEASE-p17 #0: Tue Jan 27
13:45:18 UTC 2015

# httpd -V
Server version: Apache/2.4.16 (FreeBSD)
Server built:   Aug 14 2015 23:52:56
Server's Module Magic Number: 20120211:47
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses disabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr/local"
 -D SUEXEC_BIN="/usr/local/bin/suexec"
 -D DEFAULT_PIDLOG="/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="/var/run/apache_runtime_status"
 -D DEFAULT_ERRORLOG="/var/log/httpd-error.log"
 -D AP_TYPES_CONFIG_FILE="etc/apache24/mime.types"
 -D SERVER_CONFIG_FILE="etc/apache24/httpd.conf"

# php -i
phpinfo()
PHP Version => 5.6.12

System => FreeBSD indigo 10.0-RELEASE-p17 FreeBSD 10.0-RELEASE-p17 #0:
Tue Jan 27 13:45:18 UTC 2015    
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
Build Date => Aug 15 2015 12:38:40
Configure Command =>  './configure'  '--with-layout=GNU'
'--localstatedir=/var' '--with-config-file-scan-dir=/usr/local/etc/php'
'--disable-all' '--enable-libxml' '--enable-mysqlnd'
'--with-libxml-dir=/usr/local' '--with-pcre-regex=/usr/local'
'--with-zlib-dir=/usr' '--program-prefix=' '--enable-fpm'
'--with-fpm-user=www' '--with-fpm-group=www' '--with-regex=php'
'--with-zend-vm=CALL' '--prefix=/usr/local' '--mandir=/usr/local/man'
'--infodir=/usr/local/info/' '--build=amd64-portbld-freebsd10.0'
'build_alias=amd64-portbld-freebsd10.0' 'CC=cc' 'CFLAGS=-O2
'-pipe'
'-fstack-protector' '-fno-strict-aliasing'' 'LDFLAGS=
'-fstack-protector'' 'LIBS=-lpthread' 'CPPFLAGS='
'CPP=cpp' 'CXX=c++'
'CXXFLAGS=-O2 '-pipe' '-fstack-protector'
'-fno-strict-aliasing''
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php
Additional .ini files parsed => /usr/local/etc/php/extensions.ini

PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,NTS
PHP Extension Build => API20131226,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => disabled

Registered PHP Streams => compress.bzip2, php, file, glob, data, http,
ftp, https, ftps, compress.zlib, zip, phar
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3,
sslv2, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters => bzip2.*, string.rot13, string.toupper,
string.tolower, string.strip_tags, convert.*, consumed, dechunk,
convert.iconv.*, mcrypt.*, mdecrypt.*, zlib.*
...
...
...
gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.6.0
T1Lib Support => enabled
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.6.17
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
JIS-mapped Japanese Font Support => enabled
...
...
...
zlib

ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.8
Linked Version => 1.2.8

Any advice gratefully received!

Regards

Steve

Test script:
---------------
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = imagecreatefrompng($imgname);

    /* See if it failed */
    if(!$im)
    {    // create error image
        $im  = imagecreatetruecolor(1500, 30);  $bgc =
imagecolorallocate($im, 255, 255, 255);  $tc  = imagecolorallocate($im,
0, 0, 0);
        imagefilledrectangle($im, 0, 0, 1500, 30, $bgc);
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/png');

$img = LoadPNG('test.png');

imagepng($img);
imagedestroy($img);
?>


Expected result:
----------------
I'd expect the script to open the images and display it in the web
browser. It works for jpegs (using imagecreatefromjpeg obviously)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=70276&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70276&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70276&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70276&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70276&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70276&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70276&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70276&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70276&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70276&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70276&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70276&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70276&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70276&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70276&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70276&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70276&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70276&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70276&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70276&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70276&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#195229) next »