php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36726 imagecreatefromjpeg() crahes PHP
Submitted: 2006-03-13 22:37 UTC Modified: 2006-03-20 23:26 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: christoph at ziegenberg dot com Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 5.1.2 OS: Suse Linux 9.3
Private report: No CVE-ID: None
 [2006-03-13 22:37 UTC] christoph at ziegenberg dot com
Description:
------------
Using imagecreatefromjpeg() lets PHP crash without an error message. also using @imagecreatefromjpeg() doesn't help - it's not possible to check the returning value.

I the user comments a user already described problems with jpegs created by "Canon PowerShot S70", my image (uploaded by a user) was created by a "Canon PowerShot A400". So this seems to be the problem.

It worked on my Windows XP without any problem, but on Suse it crashed...

Reproduce code:
---------------
I'll ask the user to upload the picture here. Then simply call imagecreatefromjpeg() with this image.

Expected result:
----------------
No crash, but an error message and an empty return value.

Actual result:
--------------
Crash

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-13 22:59 UTC] pajoye@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


Please give us an image to reproduce your problem.
 [2006-03-18 18:40 UTC] christoph at ziegenberg dot com
I uploaded the images and a testscript.

Look here: http://www.ziegenberg.com/jpegbug/
 [2006-03-18 23:24 UTC] pajoye@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

All images work well for me. You can try yourself with this script, put all your images in a 36726 folder and run this script:

$basedir = "./36726/";
$images = array('14844.jpg', '18925.jpg', '21987.jpg');
foreach ($images as $a) {
    $im = imagecreatefromjpeg($basedir . $a);
    imagejpeg($im, $basedir . "$a.2.jpeg");
    echo "$a done\n";
}

Be sure to use the bundled GD ("configure --with-gd").
 [2006-03-20 18:45 UTC] christoph at ziegenberg dot com
It is the bundled GD. I added two additional files for you to compare - one working fine and one producing the expected error, because it could not be opened by imagecreatefromjpeg().

And I added a link to allow you a look on the basic phpinfo() output. I will provide you with further information, if needed.

As I already mentioned it seems to work on other systems. And as also mentioned another user had the same problem - so there seems to be something wrong, doesn't it?
 [2006-03-20 18:58 UTC] pajoye@php.net
Sorry I do not trace your changes :) which files did you add?

Cannot be opened by imagecreatefromjpeg? What does that mean? It crashes or you have an error message?

The phpinfo you provide is useless as it does not show the GD informations...
 [2006-03-20 19:33 UTC] christoph at ziegenberg dot com
I added the following images: 21839.jpg, 21494.jpg, 7737.jpg, 22086.jpg, 11848.jpg

You can see the GD information on the main page (gd_info() output), but now you will also see the output from the phpinfo() (filtered to not publish more information than needed).

"cannot be opened by imagecreatefromjpeg" means that the function imagecreatefromjpeg() will return an empty string and create an error for some of the new image - try it and you'll see what I mean. This is what I expect for the first uploaded images if there is something wrong with the format (although I don't know what this is for the example images)...
 [2006-03-20 19:42 UTC] pajoye@php.net
Sorry, can you provide me *one* archive with all the images inside? 

FYI, I tried "11848.jpg" and it works well.

I feel like your system is broken or you are doing something wrong in your setup.
 [2006-03-20 20:16 UTC] christoph at ziegenberg dot com
Download it here:
http://www.ziegenberg.com/jpegbug/images.zip

Maybe the setup is the problem, but 99% of the uploaded images work fine. Nevertheless you should get an error you can work with...
 [2006-03-20 21:05 UTC] pajoye@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

21839.jpg:
Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 121 extraneous bytes before marker 0xd9

7737.jpg:
Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 135 extraneous bytes before marker 0xd9

These two jpeg images are not valid. From php 5.1.3 (try using snapshot.php.net 5.1.x), you can ignore the warnings or minor errors using this command:

ini_set("gd.jpeg_ignore_warning", true);

I set to "expected behavior". By the way, you should use error_reporting(E_ALL); when you develop.

 [2006-03-20 22:22 UTC] christoph at ziegenberg dot com
Thanks, got the reason... error_reporting was active, but display_errors wasn't and the error has not been logged. I changed it and got the following error for image 18925.jpg: 

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1600 bytes)

I didn't expect that PHP needs so much memory for an image less than 200 KB - and I do NOT think that this is a normal behaviour, because there are much larger images (e.g. the new test image "99992.jpg" with about 1.5 MB) which work fine with the recommended value 8M... Changing it to 16M works for all images.

I think that this error should not occur for the mentioned example image and that there is an error with the image processing wasting all the memory. So I changed this bug again to open... hope you agree.
 [2006-03-20 22:28 UTC] christoph at ziegenberg dot com
Bye the way: I added the additional information to the phpinfo() output with the error_reporting, memory_limit,... settings.
 [2006-03-20 22:34 UTC] pajoye@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

the file size of a JPEG data has nothing to do with the size of the *uncompressed* pixel data in memory.

For example, your images is 1600x1200, true colors (4bytes per pixel):
== 7680000 bytes
add to that the whole memory that your script or php may need and you are out of the 8M.

Now please, keep this bug as closed as there is obviously no bug. If you need support feel free to use our numerous support possibilies.
 [2006-03-20 22:58 UTC] christoph at ziegenberg dot com
Thanks a lot, I understand what you mean. 

I only want to add (for other users) that all images are 24 Bit = 3 Byte per pixel, so the calculation isn't as simple as that (to multiply the dimension and channel values from getimagesize()).
 [2006-03-20 23:26 UTC] pajoye@php.net
"I only want to add (for other users) that all images are 24 Bit = 3 Byte per pixel"

No. GD True color buffer uses *four* bytes, red, green, blue and alpha, and *always* :-)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 18:01:36 2024 UTC