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 50187 - Robustness audit on pixbuf loader modules
Robustness audit on pixbuf loader modules
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other All
: Normal critical
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2000-12-17 01:09 UTC by Havoc Pennington
Modified: 2010-07-10 04:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
my replacement for io-gif.c (36.46 KB, text/plain)
2001-04-11 05:49 UTC, Michael Hore
  Details
test-cases and fixes for pixbuf loaders (50.01 KB, application/octet-stream)
2001-05-27 19:37 UTC, Soren Sandmann Pedersen
  Details
Makes .ICO loader more robust, minor fix for JPEG, and test images for wbmp (16.15 KB, patch)
2001-07-10 21:54 UTC, Soren Sandmann Pedersen
none Details | Review
small fixes to the jpeg and tiff loaders (3.23 KB, patch)
2001-08-20 12:47 UTC, Matthias Clasen
none Details | Review
test for TGA loader. always return FALSE for wbmp check (123.20 KB, patch)
2001-08-24 10:43 UTC, Soren Sandmann Pedersen
none Details | Review
more tests and improvements for several loaders (365.21 KB, patch)
2001-09-01 19:04 UTC, Soren Sandmann Pedersen
none Details | Review
more robustness fixes for the xpm loader (2.96 KB, patch)
2001-09-03 14:07 UTC, Matthias Clasen
none Details | Review
the patch (4.30 KB, patch)
2002-02-05 13:51 UTC, Matthias Clasen
none Details | Review
the patch (14.75 KB, patch)
2002-02-11 00:16 UTC, Matthias Clasen
none Details | Review
ras / pnm patch (41.78 KB, patch)
2002-03-13 01:06 UTC, Matthias Clasen
none Details | Review
JPEG file making gdk-pixbug crash badly (10.55 KB, multipart/appledouble)
2002-08-24 18:17 UTC, jwarnier
  Details

Description Havoc Pennington 2000-12-17 01:09:47 UTC
The pixbuf loader modules need to be audited for robustness against
hostile or broken image files. This is a potential security issue so
can't really be punted, has to be done before stable release. We can
possibly punt some of the image loaders and only audit the most important
ones if there's a time crunch.
Comment 1 Havoc Pennington 2001-01-29 19:38:58 UTC
Put all GTK 1.3.x bugs on 2.0.0 milestone
Comment 2 Michael Hore 2001-04-11 05:49:33 UTC
Created attachment 459 [details]
my replacement for io-gif.c
Comment 3 Michael Hore 2001-04-11 05:54:15 UTC
for your viewing displeasure I rewrote the gif decoder, this one
should be fast, robust, accurate and portable indeed.
Comment 4 Jonathan Blandford 2001-04-13 10:31:47 UTC
Helmethead:  Can you briefly mention what you changed between your
version of io-gif.c and the one in cvs?
Comment 5 Michael Hore 2001-04-13 12:54:46 UTC
I can't say for sure since I rewrote it from scratch, though it's
quite similar to gtk's one. Gtk's io-gif.c code is a bit of a mess,
and also I decided to rewrite as a little project for myself.

There are no great claims to fame for my version, apart from mostly
having clean code. It's better in some small ways (bit faster and
despite that, sometimes more accurate) and it should be robust against
any dodgyness you can feed it.
Comment 6 Soren Sandmann Pedersen 2001-05-27 19:37:58 UTC
Created attachment 569 [details]
test-cases and fixes for pixbuf loaders
Comment 7 Soren Sandmann Pedersen 2001-05-27 19:47:31 UTC
I have uploaded a file with test cases for some of the GdkPixbuf
loaders.  They are the result of feeding random data to the loaders. 
A particularly nasty test was taking a valid image and modifying the
bytes in it at random.  Only the JPEG loader survived this treatment.

The tarball also contains a patch that fixes some, but far from all,
of the crashes.  The changes also implements 'incremental' loading for
TIFF images without saving to a temporary file.  It also stops libpng
from spewing messages to stderr; however, it also introduces even more
memory leaks than there already are.

See the comments in test-loaders.c for more details.
Comment 8 Havoc Pennington 2001-06-01 20:06:19 UTC
You left out the file test-random.c - for now I'm just not putting it
in CVS, send it along if it was supposed to be included.
Comment 9 Havoc Pennington 2001-06-01 23:07:17 UTC
I checked in the test-loaders patch with some tweaks, thanks, very
useful. Unfortunately it reveals that we aren't even close to being
able to close this bug...

Soren, can you tell us how you created test-images.h so we can add
images to it in the future?
Comment 10 Soren Sandmann Pedersen 2001-06-02 10:58:19 UTC
Everytime a loader crashed, I reran the test with the same seed
recording (using the verbose parameters) what bytes actually made the
loader crash.  Then I added these to test-images.h (by hand).

The file test-random.c used to be a separate program to generate
random data; I don't use it anymore, all of its functionality is
included in test-loaders.c now.
Comment 11 Soren Sandmann Pedersen 2001-07-10 21:54:11 UTC
Created attachment 737 [details] [review]
Makes .ICO loader more robust, minor fix for JPEG, and test images for wbmp
Comment 12 Matthias Clasen 2001-08-20 06:48:24 UTC
I have committed that patch now. I'm leaving this bug open as
holding pen for further robustness audit.
Comment 13 Matthias Clasen 2001-08-20 12:47:53 UTC
Created attachment 917 [details] [review]
small fixes to the jpeg and tiff loaders
Comment 14 Matthias Clasen 2001-08-20 12:50:27 UTC
The attached patch makes it less likely that the jpeg loader crashes
in low-memory situations and keeps the tiff loader from stumbling
over its own feet in some cases (ie forgetting to free global_error).
Comment 15 Soren Sandmann Pedersen 2001-08-24 10:43:43 UTC
Created attachment 949 [details] [review]
test for TGA loader. always return FALSE for wbmp check
Comment 16 Soren Sandmann Pedersen 2001-09-01 19:04:01 UTC
Created attachment 5040 [details] [review]
more tests and improvements for several loaders
Comment 17 Matthias Clasen 2001-09-03 14:07:44 UTC
Created attachment 5046 [details] [review]
more robustness fixes for the xpm loader
Comment 18 Matthias Clasen 2001-09-14 22:07:03 UTC
I have committed the outstanding patches, since they seemed 
uncontroversial enough to not provoke a single comment in a full
month.
Comment 19 Yanko Kaneti 2001-09-25 00:06:18 UTC
jsut trying to use bugzilla in a better way
this bug depends on 56837

please correct me if i am wrong
Comment 20 Yanko Kaneti 2001-09-25 23:27:19 UTC
the ico crash with 32bit icons is  resolved

Comment 21 Matthias Clasen 2002-01-15 08:19:58 UTC
Hey Kristian, the patches have all been applied, therefore I removed 
the PATCH keyword. It is my understanding that PATCH should be 
added only if the bug report has *outstanding* patches for review.

If we add PATCH to any bug report which ever had a patch attached,
it will be essentially useless.
Comment 22 Matthias Clasen 2002-02-05 13:50:39 UTC
Here is a new round of fixes for the ico, tga and wbmp loaders.
They are all fixing crashes found by TEST_RANDOMLY_MODIFIED in
test-loaders.
Comment 23 Matthias Clasen 2002-02-05 13:51:10 UTC
Created attachment 6603 [details] [review]
the patch
Comment 24 Owen Taylor 2002-02-10 18:50:41 UTC
Hmm, mostly looks fine to commit. There looks like there is some random
indentation changes in the patch. (We probably should add the
appropriate emacs magic comments to the source files in
gdk-pixbuf since it doesn't match the rest of GTK+)

The error code set seems to be a little funny in some places:

 if (State->DIBoffset < 0) {
+
  g_set_error (error,
+
	       GDK_PIXBUF_ERROR,
+
	       GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+
	       _("Invalid header in icon"));
+
  return;
+
}
+

Shouldn't that be CORRUPT_IMAGE instead?

I sort of wonder if some of the < 0 checks shouldn't actually
be unsigned variables instead, but that would require more
checking for unsigned/signed comparison problems and probably
makes no practical difference.
Comment 25 Matthias Clasen 2002-02-10 19:32:15 UTC
Yes, I very much agree about the emacs magic comments.
I'll go over the patch and filter out irrelevant noise before
committing.

The error codes are just copy-and-paste leftovers. I'll correct
them as well. 

You're probably right about the < 0 vs. unsigned stuff, but 
I aimed for minimally invasive fixes.
Comment 26 Havoc Pennington 2002-02-10 19:45:23 UTC
-Wsign-compare might be good in the gdk-pixbuf subdir, though 
in general it's really irritating because it warns about comparing 
an int to an enum.
Comment 27 Matthias Clasen 2002-02-10 21:08:54 UTC
I have committed the patch after fixing the error codes and
reducing the whitespace noise a bit.
Comment 28 Matthias Clasen 2002-02-11 00:15:02 UTC
More random tests --> more patches...
Apart from fixing tga, ico and wbmp for the random tests, the
following patch also adds one disabled tiff test which provokes
a segfault in TIFFReadDirectory(). Not quite as bad as a double-free
in zlib, but still... 
Comment 29 Matthias Clasen 2002-02-11 00:16:41 UTC
Created attachment 6687 [details] [review]
the patch
Comment 30 Havoc Pennington 2002-02-11 00:37:31 UTC
Should we be saving all the bad random images in some kind of
regression suite?
Comment 31 Matthias Clasen 2002-02-11 08:11:18 UTC
You mean as files, not in the form they're now in in test-images.h ?
Comment 32 Havoc Pennington 2002-02-11 09:26:55 UTC
It doesn't matter what format, I was just wondering if we should be
saving the results each time the random mutation thing finds an image
that breaks a loader.
Comment 33 Matthias Clasen 2002-02-11 14:36:16 UTC
Yes, I agree. Unfortunately, I didn't save the bad seeds, so I'll
have to back out the patch and run test-loaders for some time to
rediscover the crashers... 
Comment 34 Havoc Pennington 2002-02-11 16:13:50 UTC
There's no need to do that, just something to keep in mind 
in the future...
Comment 35 Owen Taylor 2002-02-11 22:29:06 UTC
New patch looks reasonable. (I might suggest a switch instead
of a == foo1 || a == foo2 || a == foo3 || a == foo4....).

[ Actlually, why don't you go ahead and make further fixes as
  you think are appropriate. While I might catch a thing or two, 
  without spending a lot of time, I don't think I have
  significnatly more insight into this code than you
  have, probably significantly less. ]
Comment 36 Matthias Clasen 2002-02-12 19:48:36 UTC
The TIFFReadDirectory problem mentioned above was observed
with libtiff 3.5.5, the current version 3.5.7 doesn't crash.
Comment 37 Matthias Clasen 2002-02-12 23:31:51 UTC
I applied the last patch.
Comment 38 Matthias Clasen 2002-02-13 08:13:53 UTC
Moving this back to the 2.0.0 milestone since the patch is in and
I don't have any outstanding crashes which are not either

a) crashes in an external image library

b) GError trying to strdup in an OOM situation
Comment 39 Owen Taylor 2002-03-03 02:35:34 UTC
Loading untrusted image data will just have to be a post-2.0.0
feature :-(.

Sat Mar  2 21:28:03 2002  Owen Taylor  <otaylor@redhat.com>

        * gdk-pixbuf.c (gdk_pixbuf_new): Bullet-proof against integer
        overflow.

fixes one obvious problem.
Comment 40 Matthias Clasen 2002-03-13 01:05:19 UTC
Here is another round of patches, this time fixing up the pnm and
ras loaders far enough to survive extended random testing. Tests
included.
Comment 41 Matthias Clasen 2002-03-13 01:06:29 UTC
Created attachment 7134 [details] [review]
ras / pnm patch
Comment 42 Matthias Clasen 2002-03-13 11:59:35 UTC
Turns out I was wrong about the TIFFReadDirectory crash, it still
occurs with 3.5.7. Seems like a libtiff bug report is in order.
Comment 43 Matthias Clasen 2002-03-13 14:50:49 UTC
Reported as http://bugzilla.remotesensing.org/show_bug.cgi?id=109
Comment 44 Matthias Clasen 2002-03-13 22:06:05 UTC
The ras / pnm patch has been committed.
Comment 45 Matthias Clasen 2002-04-05 13:33:06 UTC
Move open bugs from milestones 2.0.[012] -- > 2.0.3, since 2.0.2 is already out.
Comment 46 jwarnier 2002-08-24 18:17:57 UTC
Created attachment 10696 [details]
JPEG file making gdk-pixbug crash badly
Comment 47 Matthias Clasen 2002-08-24 22:45:44 UTC
Works fine in head, probably a CMYK jpeg.
Comment 48 Owen Taylor 2002-12-09 22:39:39 UTC
Putting on 2.4.0 since the remaining project here (developing
a standard for a formal audit and doing it) is a rather large
job.
Comment 49 Behdad Esfahbod 2006-05-28 16:43:22 UTC
Shall this be closed after more than three years of inactivity?
Comment 50 André Klapper 2008-11-15 17:53:45 UTC
In reply to comment #49)
> Shall this be closed after more than three years of inactivity?

Yes.
If people still run into issues with gtk 2.12 or later, they can reopen or file a new ticket.