1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Upload semi-corrupt JPEG imagecreatefromjpeg error

Discussion in 'Troubleshooting and Problems' started by Ralle, Jan 25, 2016.

  1. Ralle

    Ralle Active Member

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

    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:
    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):
    $image = imagecreatefromjpeg($fileName);
    $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?

    Attached Files:

  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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
  3. Ralle

    Ralle Active Member

  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    We have 2.1.1 on this forum. You have 2.1.0. You can try upgrading.
  5. Ralle

    Ralle Active Member

    Okay thank you for providing this information. Can you also share xenforo.com's error_reporting value?
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Local Value: 32767
    Master Value: 24575
  7. Ralle

    Ralle Active Member

    Okay, thank you for that. I will try updating to the latest GD when I get back home.
  8. Ralle

    Ralle Active Member

    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.
  9. Brogan

    Brogan XenForo Moderator Staff Member

    No, we have it set to 0 here.
  10. Ralle

    Ralle Active Member

    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.
  11. Ralle

    Ralle Active Member

    Interestingly the XenGallery has this line:
    @ini_set('gd.jpeg_ignore_warning', 1);
    in XenGallery_Helper_Image

Share This Page