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 758315 - GIF extractor crashes on maliciously crafted gif
GIF extractor crashes on maliciously crafted gif
Status: RESOLVED FIXED
Product: tracker
Classification: Core
Component: Extractor
1.6.x
Other Linux
: Normal normal
: ---
Assigned To: tracker-extractor
tracker-extractor
: 749137 771184 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-11-18 22:56 UTC by Anthony Ryan
Modified: 2016-10-09 13:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
another sample image causing this (428 bytes, image/gif)
2016-04-17 13:23 UTC, Felix Riemann
  Details
patch proposal (1.74 KB, patch)
2016-04-17 13:49 UTC, Felix Riemann
accepted-commit_now Details | Review

Description Anthony Ryan 2015-11-18 22:56:52 UTC
If this file: https://github.com/php/php-src/blob/master/ext/gd/tests/bug37360.gif

Is saved on the system, tracker-extract (1.6.0) will crash, I see giflib is used so my relevant version of that is 4.2.3.

It looks like it's trying to allocate ~16 EiB of memory to extract that gif on my system.
Comment 1 Felix Riemann 2016-04-17 13:23:32 UTC
Created attachment 326198 [details]
another sample image causing this

This is an image (id:000245,src:000000,op:havoc,rep:4.gif) from the American Fuzzy Lop suite (http://lcamtuf.coredump.cx/afl/demo/) that is causing the same crash for me as the image referenced above.

Backtrace:
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff6824183 in _g_log_abort (breakpoint=1) at gmessages.c:325
325	    G_BREAKPOINT ();
(gdb) bt
  • #0 _g_log_abort
    at gmessages.c line 325
  • #1 g_logv
    at gmessages.c line 1080
  • #2 g_log
    at gmessages.c line 1119
  • #3 g_malloc
    at gmem.c line 99
  • #4 read_metadata
    at tracker-extract-gif.c line 152
  • #5 tracker_extract_get_metadata
    at tracker-extract-gif.c line 679
  • #6 get_file_metadata
    at tracker-extract.c line 332
  • #7 tracker_extract_get_metadata_by_cmdline
    at tracker-extract.c line 796
  • #8 run_standalone
    at tracker-main.c line 271
  • #9 main
    at tracker-main.c line 333

Comment 2 Felix Riemann 2016-04-17 13:49:15 UTC
Created attachment 326200 [details] [review]
patch proposal

The fault is a signed integer overflow that occurs when the memory for the image data is about to be malloc'd. Although the crash itself could be avoided by switching to g_malloc_n() it would overflow again afterwards when calling the giflib.

This patch tries to avoid both overflows by reading/skipping over the image data line by line. This might be a bit slower but besided avoiding the overflow also avoids tracker allocating close to 4GB of memory in the worst case (which could cause an abort() or OOM kill again).
Comment 3 Carlos Garnacho 2016-05-06 12:05:48 UTC
Comment on attachment 326200 [details] [review]
patch proposal

Thanks so much for the patch :). I see nothing wrong with it really, although I'm ultimately wondering why do we bother to read pixel data from the gif, it's effectively going nowhere, and I'd trust libgif gives up earlier than that on not-quite-gifs.
Comment 4 Carlos Garnacho 2016-05-06 12:07:44 UTC
Thanks to both for the sample images btw, they're going to my test folder.
Comment 5 Felix Riemann 2016-05-07 13:34:23 UTC
(In reply to Carlos Garnacho from comment #3)
> Comment on attachment 326200 [details] [review] [review]
> patch proposal
> 
> Thanks so much for the patch :). I see nothing wrong with it really,
> although I'm ultimately wondering why do we bother to read pixel data from
> the gif, it's effectively going nowhere, and I'd trust libgif gives up
> earlier than that on not-quite-gifs.

I was wondering about that too and IIRC it turned out that giflib reads GIFs sequentially and to skip the frame data to the next data block (next frame, metadata?,...) one has to "consume" it. Not sure if there's a way to do it without decompressing the image though.
Comment 6 Carlos Garnacho 2016-05-07 16:01:38 UTC
Comment on attachment 326200 [details] [review]
patch proposal

Ugh, APIs from the 80s... :). I tested here and that's indeed the case, so this is fine to go. Thanks again for the patch :)
Comment 7 Carlos Garnacho 2016-05-08 01:54:56 UTC
*** Bug 749137 has been marked as a duplicate of this bug. ***
Comment 8 Felix Riemann 2016-05-08 12:40:55 UTC
Thanks for the review Carlos. :)
I pushed the fix to master. Would it be possible to cherrypick it for 1.8 and maybe even 1.6 (not sure about 1.4; that branch seems active as well)?

commit 369fdc9c1c1c1c8bb74b6dcb3a095392c40e0526
Author: Felix Riemann <>
Date:   Sun Apr 17 15:42:38 2016 +0200

    tracker-extract-gif: Avoid possible integer overflow
    
    Fix integer overflow when skipping over the decoded image data
    of extremely large or specifically prepared images.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758315
---
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.
Comment 9 Carlos Garnacho 2016-05-09 07:56:05 UTC
(In reply to Felix Riemann from comment #8)
> Thanks for the review Carlos. :)
> I pushed the fix to master. Would it be possible to cherrypick it for 1.8
> and maybe even 1.6 (not sure about 1.4; that branch seems active as well)?

It indeed makes sense to backport this patch. I'll take care of that when doing releases. There should be at least a 1.8 one soon :).
Comment 10 Carlos Garnacho 2016-10-09 13:15:46 UTC
*** Bug 771184 has been marked as a duplicate of this bug. ***