Bug #73116 [Ver]: imagecreatefromjpeg fatal error on empty file
| From: | cmb@php.net | Date: | Tue, 18 Oct 2016 15:19:01 +0000 |
| Subject: | Bug #73116 [Ver]: imagecreatefromjpeg fatal error on empty file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204898@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73116&edit=1
ID: 73116
Updated by: cmb@php.net
Reported by: chupaka at gmail dot com
Summary: imagecreatefromjpeg fatal error on empty file
Status: Verified
Type: Bug
Package: GD related
Operating System: Fedora 24
PHP Version: 5.6.26
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> Seems the usual dichotomy between bundled and standalone gd
> library in:
> [â¦]
There shouldn't be a problem, as gd_error() is supposed to forward
to php_gd_error() anyway[1]. I've nonetheless improved that
recently[2].
Anyhow, with regard to the actual issue I'm at a loss. It seems
that libjpeg-turbo always raises a fatal error if it detects empty
input files[3]. I can't reproduce this, however, with "plain"
libjpeg-turbo builds.
[1] <https://github.com/php/php-src/blob/PHP-7.0.12/ext/gd/gd.c#L1054-L1056>
[2] <http://git.php.net/?p=php-src.git;a=commit;h=432e16cb>
[3] <https://github.com/libjpeg-turbo/libjpeg-turbo/search?utf8=%E2%9C%93&q=JERR_INPUT_EMPTY>
Previous Comments:
------------------------------------------------------------------------
[2016-10-05 14:52:29] cmb@php.net
> PHP Unknown error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error:
> Empty input file in
Exactly that issue (namely that the severity of GD errors has not
been mapped correctly to PHP errors) has been fixed as of PHP
5.6.25.
Maybe this issue is related to the libjpeg version/variant. I'll
have another look at it.
------------------------------------------------------------------------
[2016-10-05 12:56:00] chupaka at gmail dot com
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
#
------------------------------------------------------------------------
[2016-10-05 12:30:29] cmb@php.net
Even with an "official" external libgd I couldn't reproduce the
issue, so this might be a packaging issue.
I think it has to do with commit 6cb75fb1[1] which is supposed to
be available as of PHP 5.6.25.
[1] <https://github.com/php/php-src/commit/6cb75fb1>
------------------------------------------------------------------------
[2016-10-05 11:57:34] ondrej@php.net
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.
------------------------------------------------------------------------
[2016-10-05 11:30:11] cmb@php.net
OndÅej, can you have a look at this issue please?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=73116
--
Edit this bug report at https://bugs.php.net/bug.php?id=73116&edit=1