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 592860 - gdk_pixbuf_new_from_file() [etc] guesses wrong file types and breaks
gdk_pixbuf_new_from_file() [etc] guesses wrong file types and breaks
Status: RESOLVED WONTFIX
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2009-08-24 07:17 UTC by David Sainty
Modified: 2016-12-19 17:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Revert back to letting g_content_type_guess do its job (595 bytes, patch)
2009-08-24 07:17 UTC, David Sainty
none Details | Review
Screen capture without patch (21.71 KB, image/png)
2009-08-24 07:34 UTC, David Sainty
  Details
Screen capture with patch (91.40 KB, image/png)
2009-08-24 07:35 UTC, David Sainty
  Details

Description David Sainty 2009-08-24 07:17:51 UTC
Created attachment 141527 [details] [review]
Revert back to letting g_content_type_guess do its job

This is visible in the game crack-attack, which has a GTK front-end with .tga
format screen dumps.  For some time the screen dumps have been replaced with a
broken image icon.  The fault comes down to
gdk-pixbuf/gdk-pixbuf-io.c:_gdk_pixbuf_get_module() - which goes to
considerable effort to not let g_content_type_guess() do the job it is trying
to do.

The code used to work.  The change is apparently in response to "bug"
http://bugzilla.gnome.org/show_bug.cgi?id=566862

The logic in that bug report is deeply questionable.  And the final applied
patch (as presciently questioned in Bug#566862 comment 5) is even more
questionable.  g_content_type_guess() can do a better job if the file name is
provided.

g_content_type_guess() could reasonably be expected to do more.  For example,
"bug" 566862 could be fixed in g_content_type_guess() by using the extension
.jpg, double checking against the magic for .jpg, and if it doesn't match it
could fall back onto the matching magic for .png.

But matching only by magic is fraught with danger.  It may usually do the
right thing for most of the file formats that GTK supports.  But in the case
of crack-attack it mistakes .tga files for Win32 cursor files, and tries in
vain to parse the file with the "ico" loader rather than the "tga" loader.

Whether "bug" 566862 is a real problem or not is debatable.  But of course
it's obvious that gdk-pixbuf-io.c:_gdk_pixbuf_get_module() shouldn't be trying
to do (getting in the way of) g_content_type_guess()'s job.  The current code
thinks that it can do a better job than g_content_type_guess() by calling it
multiple times with different parameters.

If _gdk_pixbuf_get_module()'s algorithm is correct, it should be in
g_content_type_guess().  But, as demonstrated by the .tga/.cur format problem,
it's not correct.

This patch fixes the .tga file display in the crack-attack front-end.

The problem is that:

1. The .tga files start with the magic "\0  \0 002  \0  \0"

2. This matches the TGA mime rule in
   /usr/pkg/share/mime/packages/freedesktop.org.xml (or, rather, in the binary
   files generated from that source), but it ALSO matches the
   image/x-win-bitmap Windows cursor magic, with a higher priority.

3. The higher priority match is probably correct, since more bytes are
   checked.  Arguably devel/glib2/gio/gcontenttype.c:g_content_type_guess()
   should flag that the match is uncertain - but it doesn't.

4. gdk-pixbuf/gdk-pixbuf-io.c calls g_content_type_guess() without a filename
   first, and only passes the filename if the magic check is "uncertain".

5. devel/glib2/gio/gcontenttype.c:g_content_type_guess() only ever finds the
   topmost match via magic, so the "uncertain" check almost never flags as
   uncertain - certainly not if there multiple magic matches.

6. Note that in the case of .tga files, there is only one registered file type
   - TGA images, so the filename check would easily determine the right file
   type.

7. The end result is that the wrong image loader is loaded, and fails to parse
   the image (/usr/pkg/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-ico.so
   instead of /usr/pkg/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-tga.so).
   The application displays a broken image icon.
Comment 1 David Sainty 2009-08-24 07:34:09 UTC
Created attachment 141528 [details]
Screen capture without patch
Comment 2 David Sainty 2009-08-24 07:35:01 UTC
Created attachment 141529 [details]
Screen capture with patch
Comment 3 Bastien Nocera 2016-12-19 17:55:07 UTC
We're actually more likely to simply remove TGA support (as per bug 721372) rather than make any more changes to the magic handling in gdk-pixbuf.

Please file a bug against shared-mime-info instead, and try to fix the problem for the files generated by this game there.