|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-09-19 22:00 UTC] chupaka at gmail dot com
Description:
------------
When using imagecreatefromjpeg on empty file, PHP generates Fatal error instead of warning, so it's impossible to handle the error.
Test script:
---------------
<?php
touch('emptyfile');
imagecreatefromjpeg('notexist');
imagecreatefromjpeg('emptyfile');
echo "Continue with error handling";
Expected result:
----------------
PHP Warning: imagecreatefromjpeg(notexist): failed to open stream: No such file or directory in /var/www/test.php on line 5
PHP Warning: imagecreatefromjpeg(emptyfile): gd-jpeg: JPEG library reports unrecoverable error: Empty input file in /var/www/test.php on line 6
Continue with error handling
Actual result:
--------------
PHP Warning: imagecreatefromjpeg(notexist): failed to open stream: No such file or directory in /var/www/test.php on line 5
PHP Fatal error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Empty input file in /var/www/test.php on line 6
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Seems the usual dichotomy between bundled and standalone gd library in: ``` /* Called by the IJG JPEG library upon encountering a fatal error */ static void fatal_jpeg_error(j_common_ptr cinfo) { jmpbuf_wrapper *jmpbufw; - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message)(cinfo, buffer); - gd_error_ex(GD_ERROR, "gd-jpeg: JPEG library reports unrecoverable error: %s", buffer); + php_gd_error("gd-jpeg: JPEG library reports unrecoverable error: "); + (*cinfo->err->output_message) (cinfo); jmpbufw = (jmpbuf_wrapper *)cinfo->client_data; jpeg_destroy(cinfo); if(jmpbufw != 0) { longjmp(jmpbufw->jmpbuf, 1); - gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating\n"); + php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating"); } else { - gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating\n"); + php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating"); } exit(99); } ``` Different error handling in bundled GD library. Nothing packagers can do about.Rolled back to 5.6.22 - and it works without fatal error: # php -v PHP 5.6.22 (cli) (built: May 26 2016 13:54:01) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies # php test.php PHP Warning: imagecreatefromjpeg(notexist): failed to open stream: No such file or directory in /test.php on line 5 PHP Unknown error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Empty input file in Unknown on line 0 PHP Warning: imagecreatefromjpeg(): 'emptyfile' is not a valid JPEG file in /test.php on line 6 Continue with error handling #Are there chances, that your patch [1] gets merged into the 5.6-branch so it finds its way into distributions like Debian? On Debian the problem still exists because it has only the patch [2] which does not work with shared libgd [3]. ``` # php -v PHP 5.6.27-0+deb8u1 (cli) (built: Oct 15 2016 15:53:28) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies # touch test.jpg # php -r "imagecreatefromjpeg('test.jpg');" PHP Fatal error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Empty input file in Command line code on line 1 ``` [1] <http://git.php.net/?p=php-src.git;a=commit;h=432e16cb> [2] <http://git.php.net/?p=php-src.git;a=commitdiff;h=6cb75fb1e8208d79f58351340923059d0d077ee6;hp=8b905e337c0e88ec66a25e4b7dbbd5c87279ea75> [3] <http://sources.debian.net/src/php5/5.6.27%2Bdfsg-0%2Bdeb8u1/ext/gd/gd.c/#L72>