php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75275 imagecreatefrom Functions Not Failing On Corrupt Images
Submitted: 2017-09-28 14:45 UTC Modified: 2017-09-28 17:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: coryldean at gmail dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 7.1.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: coryldean at gmail dot com
New email:
PHP Version: OS:

 

 [2017-09-28 14:45 UTC] coryldean at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.imagecreatefromjpeg
---

When running the Test Script on PHP 5.2.17 it return false - as it should - when trying to load a corrupt image. However, on PHP 7.1.9 the Test Script returns a resource as if the image is fine.

Test script:
---------------
if(!imagecreatefromjpeg($FileSplFileInfo->getRealPath()))
{
    echo 'ERROR - Corrupt Image';
}
else
{
    echo 'SHOULD NOT GET HERE!';
}

Expected result:
----------------
When passing in a valid path to a corrupt .JPEG file, it should echo the error message.

Below is what I get when running the script in PHP 5.2.17

Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
 in PATH_TO_PHP_FILE_THAT_EXECUTED_CODE on line 491

Warning: imagecreatefromjpeg(): 'PATH_TO_FILE.JPEG' is not a valid JPEG file in PATH_TO_PHP_FILE_THAT_EXECUTED_CODE on line 491
ERROR - Corrupt Image


Actual result:
--------------
Below is what I get when running the script in PHP 7.1.9

SHOULD NOT GET HERE!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-28 14:51 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-09-28 14:51 UTC] requinix@php.net
Can you provide a copy of the corrupt image?
 [2017-09-28 14:56 UTC] daverandom@php.net
Please also provide the libgd versions from both the installation where you got the expected result and the installation where it didn't - var_dump(GD_VERSION)

This is likely to be caused by an upstream change in libgd. The difference between the libgd versions that 5.2.17 and 7.1.9 are built against is likely to be huge, and PHP will only report an error if libgd does.
 [2017-09-28 15:11 UTC] coryldean at gmail dot com
-Status: Feedback +Status: Open
 [2017-09-28 15:11 UTC] coryldean at gmail dot com
PHP 7.1.9 -> GD Version -> 2.1.0
PHP 5.2.17 -> GD Version -> 2.0.34
 [2017-09-28 15:13 UTC] coryldean at gmail dot com
How do I attach or provide you an example of a corrupted image?
 [2017-09-28 16:00 UTC] requinix@php.net
Upload it somewhere that does not try to process images - like a file-sharing site but not an image-sharing site. A personal website works too.
 [2017-09-28 16:09 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-09-28 16:09 UTC] requinix@php.net
Actually, before that, try setting gd.jpeg_ignore_warning=0 in 7.1.
 [2017-09-28 17:36 UTC] coryldean at gmail dot com
-Status: Feedback +Status: Open
 [2017-09-28 17:36 UTC] coryldean at gmail dot com
If I could buy you a drink I would! Setting gd.jpeg_ignore_warning=0 worked as I was expecting. Thank you!
 [2017-09-28 17:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-09-28 17:42 UTC] requinix@php.net
Glad it turned out to be something as easy as a different INI setting.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 05:01:30 2024 UTC