php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35498 GD cannot open majority of jpeg images
Submitted: 2005-12-01 01:18 UTC Modified: 2005-12-07 00:57 UTC
From: paniemin at cc dot hut dot fi Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 5.1.0 OS: Redhat Linux 7.3
Private report: No CVE-ID: None
 [2005-12-01 01:18 UTC] paniemin at cc dot hut dot fi
Description:
------------
I tryed to upgrade from 5.0.4 to 5.1. I use blunded GD version with freetype2, jpeg and png libraries. First I tried with old libraries that I used to build 5.0.4. Next I downloaded new version from freetype2. Next I downloaded GD 2.0.33 and tryed with it. I tried to find the problematic part but I failed to locate it outside php :(

I found that imagecreatefromjpeg() fails to open jpeg files that older php version opened without problems. The failure to open seems to be random but about 60-70% images are 'corruped' for gd library.


here is one of corrupted images:
http://antin.net/imageshu/7363_1.jpg

I will continue searching the real reason for this bug. I hope someone else can confirm same problem with 5.1 and GD.

Reproduce code:
---------------
$file = getFileForPerson($id, $imageNumber);

$img = imagecreatefromjpeg($file);



Expected result:
----------------
I excepted imagecreatefromjpeg to load the image so next steps in code can manipulate it.



Actual result:
--------------
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/customers/antin/public_html/huippu/ranki_dev.cgi on line 110

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../imageshu/7363_1.jpg' is not a valid JPEG file in /home/customers/antin/public_html/huippu/ranki_dev.cgi on line 110

With GD 2.0.33 the first warning is skipped which seems natural for me.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-01 10:24 UTC] tony2001@php.net
Try with the bundled GD, it's known to be less buggy and well maintained.
 [2005-12-01 10:45 UTC] paniemin at cc dot hut dot fi
First I tryed to us blunded but when that failed I tested external library. I will try to find the location of bug  in php source later today when I will be back home.

Btw, corect version is 5.1.0 (the public release).
 [2005-12-01 12:29 UTC] tony2001@php.net
Assigned to the maintainer.
 [2005-12-01 19:07 UTC] paniemin at cc dot hut dot fi
Problem is in jpeg library but problems is that there isn't enought memory! But I haven't enabled memory limit.

jmemmgr.c:

in alloc_large function:
  hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
                                            SIZEOF(large_pool_hdr));
  if (hdr_ptr == NULL)
    out_of_memory(cinfo, 4);    /* jpeg_get_large failed */

jpeg_get_large is just system specifig warepper for malloc call.


The problem is in jpeg_start_decompress call from php GD library in gdImageCreateFromJpegCtx function (gd_jpeg.c).


But when I try to run the php code in shell there is no problems. I quess that maybe some limits in apache that is runnig php in cgi mode.
 [2005-12-07 00:57 UTC] iliaa@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.

If malloc in libjpeg is failing it has nothing to do with PHP. PHP's memory limit only affects PHP and not the underlying libraries like libjpeg.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 06:00:03 2025 UTC