Upload semi-corrupt JPEG imagecreatefromjpeg error

Rasmus Vind

Well-known member
I have uploaded a semi-corrupt JPEG file to my installation of XenForo. This gives me the following exception:

Code:
ErrorException: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 51 extraneous bytes before marker 0xd9 in /var/www/html/library/XenForo/Image/Gd.php on line 78

I got the exception out by using var_dump() in the catch { } statement in XenForo_Image_Gd.

I Googled around and found that I had to set the following php.ini setting:
Code:
gd.jpeg_ignore_warning = 1

This allows gd to move on and emits a warning which XenForo unfortunately interprets as an exception, otherwise I would have gotten the image.

I had to replace (in XenForo_Image_Gd):
Code:
$image = imagecreatefromjpeg($fileName);
with
Code:
$image = @imagecreatefromjpeg($fileName);

To actually get my image.

I have attached a .zip of the image and the image too. XenForo.com apparently did not have a problem interpreting the image.

Can you please enlighten me as to what is wrong with my PHP setup? Is it error_reporting? Could you perhaps share copies of your php.ini where this works? Are you using gd?
 

Attachments

If that image works here on this forum but not on your forum then your image library is probably more stringent about these "extra bytes".

What GD version do you have? Visit admin.php?tools/phpinfo to check.

My recommendation is to simply upgrade your GD. Or you can also try ImageMagick if it's available to you:

Admin CP -> Home -> Options -> Attachments -> Default Image Processor
 
I am back with results.

I upgraded to PHP 7 (by compiling it myself) and it did the same thing, also gd was still version 2.1.0 (it's bundled by PHP). I set gd.jpeg_ignore_warning = 1 again and that did not help.

Then I installed PHP 7 using Debian and it would install a recent version of gd which was 2.1.1 but it did not work. Then I set gd.jpeg_ignore_warning = 1 and it finally worked.

I wonder why PHP does not have a more recent version of gd. 2.1.1 is the latest but it's still more than a year old.

I suspect that XenForo.com also has this setting gd.jpeg_ignore_warning = 1 in your phpinfo?

Thank you for helping me out.
 
Well. That is super weird. However, mine works at 2.1.1 with gd.jpeg_ignore_warning = 1 without any code changes to XenForo, so I am a happy camper. Now we have a thread about this too so if people have the same problem, they can (ideally) find this thread.
 
Back
Top Bottom