php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77195 Incorrect error handling of imagecreatefromjpeg function with corrupt jpeg
Submitted: 2018-11-23 15:11 UTC Modified: 2018-11-23 23:16 UTC
From: peehaa@php.net Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
 [2018-11-23 15:11 UTC] peehaa@php.net
Description:
------------
The imagecreatefromjpeg function improperly handles errors when passing a corrupt jpeg image.

Not only does it still output an error (coming from gd directly I guess), but it also spits out 3 PHP errors (1 notice and 2 warnings).



Test script:
---------------
Test image can be found at https://pieterhordijk.com/broken-mspaint.jpeg

@imagecreatefromjpeg('/path/to/broken-mspaint.jpeg');

imagecreatefromjpeg('/path/to/broken-mspaint.jpeg');

Expected result:
----------------
First call with the STFU operator should output nothing.

Second call without the STFU operators should probably just give one single php error instead of 3

Actual result:
--------------
First call with the STFU operator:

JPEG datastream contains no image

Second call without the STFU operator:

PHP Notice:  imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 947 extraneous bytes before marker 0xd9
 in /path/to/test.php on line 5
PHP Warning:  imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error:  in /path/to/test.php on line 5
JPEG datastream contains no image
PHP Warning:  imagecreatefromjpeg(): '/path/to/image/broken-mspaint.jpeg' is not a valid JPEG file in /path/to/test.php on line 5


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-23 17:42 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-11-23 17:42 UTC] cmb@php.net
This looks like a duplicate of bug #75888.
 [2018-11-23 20:00 UTC] peehaa@php.net
How is this a dupe?

I am getting unexpected output (even when using the STFU operator).

The dupe is about getting an unexpected fatal error.

Am I missing something here?
 [2018-11-23 20:10 UTC] peehaa@php.net
Also note I am using the bundled gd lib
 [2018-11-23 23:16 UTC] cmb@php.net
-Status: Duplicate +Status: Open
 [2018-11-23 23:16 UTC] cmb@php.net
> Also note I am using the bundled gd lib

Ah, then the other ticket is certainly unrelated.
 [2018-11-24 12:02 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=60a9f7a3a3502bfb7118f7fc5c06f9fdf713efad
Log: Fix #77195: Incorrect error handling of imagecreatefromjpeg()
 [2018-11-24 12:02 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 28 09:01:28 2024 UTC