After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 358117 - jpeg plugin crashes when opening certain jpg file (crash in libexif)
jpeg plugin crashes when opening certain jpg file (crash in libexif)
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
2.3.x
Other All
: Normal major
: 2.4
Assigned To: GIMP Bugs
GIMP Bugs
: 324302 381182 456645 460466 473556 484809 486620 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-09-28 11:03 UTC by rhi
Modified: 2008-01-15 14:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GIMP message saying the plugin has crashed (29.76 KB, image/png)
2006-09-28 11:04 UTC, rhi
Details
Image causing the jpeg plugin to crash (105.01 KB, image/jpeg)
2006-09-28 11:05 UTC, rhi
Details
Crasher image 1 which loads fine with libexif 0.6.15 and GIMP trunk (531.20 KB, image/jpeg)
2007-06-08 06:29 UTC, Mukund Sivaraman
Details
Crasher image 2 which loads fine with libexif 0.6.15 and GIMP trunk (59.14 KB, image/jpeg)
2007-06-08 06:30 UTC, Mukund Sivaraman
Details
Crasher image 3 which loads fine with libexif 0.6.15 and GIMP trunk (483.20 KB, image/jpeg)
2007-06-08 06:31 UTC, Mukund Sivaraman
Details
Crasher image 4 which loads fine with libexif 0.6.15 and GIMP trunk (105.01 KB, image/jpeg)
2007-06-08 06:31 UTC, Mukund Sivaraman
Details

Description rhi 2006-09-28 11:03:14 UTC
The jpeg plugin crashes when opening a certain jpg file (attached).

If relevant: system libjpeg62 version is 6b-11.
Comment 1 rhi 2006-09-28 11:04:14 UTC
Created attachment 73548 [details]
GIMP message saying the plugin has crashed
Comment 2 rhi 2006-09-28 11:05:18 UTC
Created attachment 73549 [details]
Image causing the jpeg plugin to crash
Comment 3 Sven Neumann 2006-09-28 17:05:30 UTC
Looks a lot like a bug in libexif. I can reproduce the crash:

  • #6 exif_set_sshort
    from /usr/lib/libexif.so.12
  • #7 exif_set_short
    from /usr/lib/libexif.so.12
  • #8 exif_data_set_data_type
    from /usr/lib/libexif.so.12
  • #9 exif_data_set_data_type
    from /usr/lib/libexif.so.12
  • #10 exif_data_save_data
    from /usr/lib/libexif.so.12
  • #11 gimp_metadata_store_exif
  • #12 jpeg_apply_exif_data_to_image

Comment 4 weskaggs 2006-09-28 17:35:13 UTC
This image is from an Olympus C-2500L camera, a 2.5 MPixel digital SLR from 1999 or 2000, and the unusual thing about it is that the jpeg files it creates appear to lack thumbnails.  I have never seen a jpeg file with exif but no thumbnail, and maybe the libexif developers haven't either, because it looks like the code is reading a bogus data size and then trying to do a bogus realloc based on it, leading to the failure.
Comment 5 Sven Neumann 2006-09-28 17:44:26 UTC
This should be reported to the libexif developers then so that they can take appropriate action. Bill, do you think there's anything simple we can do in the JPEG plug-in to work around this problem? Otherwise, we can only ask the bug reporter to inform the libexif guys and close this report as NOTGNOME.
Comment 6 weskaggs 2006-09-28 19:37:53 UTC
If my understanding is correct, then we can work around the problem by avoiding any attempt to load the exif for images that lack a thumbnail.  I have tested by adding the lines

  /* return if there is no thumbnail, to work around bug #358117 */
  if (!exif_data->data || exif_data->size == 0)
    return;

to the function jpeg_apply_exif_data_to_image() in jpeg-exif.c, and the change does allow this image to load successfully (losing the exif, however).  Of course as you say, the proper solution would be to fix this within libexif, but I think the workaround can't do much harm, since exif images without thumbnails are very rare.
Comment 7 Sven Neumann 2006-09-28 19:46:20 UTC
Looks good, but this check could probably be in the metadata plug-in, couldn't it? There it would catch the problem also for other plug-ins using gimp_metadata_store_exif(). And we might even be do this in a way that doesn't loose all the EXIF data.
Comment 8 weskaggs 2006-09-28 20:09:09 UTC
Well, the problematic code only comes into play when we format the exif data into a parasite to attach to the image.  The metadata plug-in is supposed to replace this step eventually, but currently we don't have any other way of saving the exif data.  The metadata plug-in will do it by translating the exif data into XMP/XML, which is nontrivial -- if it weren't, I or Raphael would already have done it.

(If this response doesn't make sense, it is probably because I didn't correctly understand what you are suggesting.)
Comment 9 Sven Neumann 2006-09-28 20:14:54 UTC
Well, according to the stack trace, the crash happens in gimp_metadata_store_exif() and this looked like metadata code to me. I forgot that this is still compiled into the JPEG plug-in.

Perhaps we need to clean this up a bit before 2.4?
Comment 10 rhi 2006-09-28 21:02:02 UTC
Wow, this was really fast!

Shall I report this issue to the libexif developer? Maybe it's better when you do this because I don't have much experience with this library and how it works together with the jpeg plugin.
Comment 11 weskaggs 2006-09-29 18:57:48 UTC
Please go ahead an report the bug to libexif (http://sourceforge.net/projects/libexif), making sure to give a pointer to this bug report.  Their maintenance doesn't seem to be very active, so I'm not sure how much response there will be.

I will commit the change from comment #6, so at least your files will be openable.  Regarding comment #9, I'm not sure what my attitude is -- the code does look a bit odd, but on the other hand any changes made now are going to have to be unwound once a proper implementation of gimp_metadata_store_exif exists.

For HEAD:

2006-09-29  Bill Skaggs  <weskaggs@primate.ucdavis.ed>

	* plug-ins/jpeg/jpeg-exif.c: don't let libexif crash us when
	loading image with exif data but no thumbnail.  Works around
	bug #358117.

Resolving as NOTGNOME.
Comment 12 rhi 2006-09-29 21:15:54 UTC
Oh, this was already reported to the libexif bug tracker:
https://sourceforge.net/tracker/index.php?func=detail&aid=1525770&group_id=12272&atid=112272

But indeed it doesn't seem very active...
Comment 13 Raphaël Quinet 2007-04-12 16:35:05 UTC
*** Bug 381182 has been marked as a duplicate of this bug. ***
Comment 14 Raphaël Quinet 2007-04-12 16:37:55 UTC
Although the problem is not in our code, I am tentatively re-opening this bug report in case we can find a workaround before GIMP 2.4 is released.  It does not seem very likely that everybody will have an updated version of libexif in time for the release.
Comment 15 Sven Neumann 2007-05-02 12:58:59 UTC
Bill added a workaround for this bug (see comment #11). Thus I don't see a need to keep it open, closing as NOTGNOME again.
Comment 16 Raphaël Quinet 2007-05-02 13:08:52 UTC
Unfortunately, the workaround is not sufficient.  It is still possible to get a crash (or libexif hanging and consuming insane amounts of memory) with the image attached to bug #428037 (attachment #86111 [details]).
Comment 17 Sven Neumann 2007-05-06 18:41:50 UTC
I tried applying the patch from https://sourceforge.net/tracker/index.php?func=detail&aid=1457501&group_id=12272&atid=112272 to libexif, but it doesn't fix our problem. Note that the fix in the bug report is also not complete as the code continues with j=25 which is out of bounds of the elem array.
Comment 18 Sven Neumann 2007-05-07 10:29:02 UTC
*** Bug 324302 has been marked as a duplicate of this bug. ***
Comment 19 Jan Patera 2007-05-08 10:07:15 UTC
This bug report and the bug #1255770 at sf.net actually mix 3 images.
I was not able to reproduce any crash on the 1st two images. I just added a heuristical fix to deal with the 3rd image (attachment #86111 [details]). 
Note: all three images have corrupted EXIF data.
Could you please try GIMP with the latest libexif from CVS?
Details here:
https://sourceforge.net/tracker/index.php?func=detail&aid=1525770&group_id=12272&atid=112272
Comment 20 Raphaël Quinet 2007-05-08 18:09:29 UTC
There should really be a way to tell libexif to avoid even looking at EXIF fields that GIMP is not interested in.  GIMP does not use MakerNote and most of the crashes that have been reported recently were related to libexif getting stuck while parsing MakerNote.
Comment 21 Jan Patera 2007-05-09 12:34:13 UTC
Modifying EXIF but not modifying MakerNote is not a good idea. Many MakerNotes
actually use offsets relative to the start of EXIF marker and not makernote.
Many tools do ignore the MakerNote and therefore we have zillions of corrupted
files around. For an example, go to bug #428037.
However this morning I checked in an enhancement to libexif:
Saving unmodified makernote no longer controlled at compile time by #ifdef
EXIF_DONT_CHANGE_MAKER_NOTE, but at run-time by newly introduced option EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE.

Comment 22 Mukund Sivaraman 2007-06-08 06:28:02 UTC
The crashers seem to have gone with libexif 0.6.15. I can't reproduce the crashes with the user-provided test cases which used to crash before.

I'm attaching the test cases to this bug so that people can test more easily, as some critical crashers are in bugs marked as dups and are not easily findable.

Comment 23 Mukund Sivaraman 2007-06-08 06:29:37 UTC
Created attachment 89589 [details]
Crasher image 1 which loads fine with libexif 0.6.15 and GIMP trunk
Comment 24 Mukund Sivaraman 2007-06-08 06:30:13 UTC
Created attachment 89590 [details]
Crasher image 2 which loads fine with libexif 0.6.15 and GIMP trunk
Comment 25 Mukund Sivaraman 2007-06-08 06:31:06 UTC
Created attachment 89591 [details]
Crasher image 3 which loads fine with libexif 0.6.15 and GIMP trunk
Comment 26 Mukund Sivaraman 2007-06-08 06:31:49 UTC
Created attachment 89592 [details]
Crasher image 4 which loads fine with libexif 0.6.15 and GIMP trunk
Comment 27 Mukund Sivaraman 2007-06-11 13:40:54 UTC
Bumped required libexif version to 0.6.15 in changeset 22752. Closing bug
(raphael's killer duck image also works now).

2007-06-11  Mukund Sivaraman  <muks@mukund.org>

        * configure.in: bumped required libexif version to 0.6.15. This
        seems to fix #358117 for the various test images that were reported
        in it, and its duplicates. This version is in Debian testing and
        Fedora 7.
Comment 28 Raphaël Quinet 2007-07-15 21:22:22 UTC
*** Bug 456645 has been marked as a duplicate of this bug. ***
Comment 29 Raphaël Quinet 2007-07-17 20:15:02 UTC
The EXIF reading code has been reorganized in SVN (revision 22949).  The new code is simpler and successfully loads all images attached here.  The workaround described in comment #6 has been removed because we depend on a more robust libexif now.  This allows the plug-in to read EXIF blocks without a thumbnail image.
Comment 30 Sven Neumann 2007-07-26 06:40:23 UTC
*** Bug 460466 has been marked as a duplicate of this bug. ***
Comment 31 Raphaël Quinet 2007-08-14 09:06:19 UTC
Note for those who assign duplicates:

There is a new bug #466044 that also occurs with a photo taken by an Olympus camera, but that bug is different because it affects libexif 0.6.16 and it causes it to allocate endless amounts of memory instead of crashing.  Please pay attention to the differences and assign the duplicates correctly.  Thanks in advance.
Comment 32 Raphaël Quinet 2007-09-06 12:16:08 UTC
*** Bug 473556 has been marked as a duplicate of this bug. ***
Comment 33 Raphaël Quinet 2007-10-09 17:06:16 UTC
*** Bug 484809 has been marked as a duplicate of this bug. ***
Comment 34 Manish Singh 2007-10-14 21:28:58 UTC
*** Bug 486620 has been marked as a duplicate of this bug. ***