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 569671 - gdk_pixbuf_new_from_file() can't open image/x-portable-pixmap
gdk_pixbuf_new_from_file() can't open image/x-portable-pixmap
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-01-29 13:36 UTC by Tyler Lawson
Modified: 2010-07-10 04:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed fix by passing filename to gio (488 bytes, patch)
2009-01-29 13:46 UTC, Tyler Lawson
none Details | Review
Proposed fix by rechecking when mime sniffer is uncertain (646 bytes, patch)
2009-02-09 17:52 UTC, Tyler Lawson
committed Details | Review

Description Tyler Lawson 2009-01-29 13:36:32 UTC
Please describe the problem:
If gtk2 is compiled with GDK_PIXBUF_USE_GIO_MIME set, gdk_pixbuf_new_from_file can't open pixmap files such as .ppm.  This breaks functionality in some existing programs, e.g. Xournal loses the ability to annotate PDF files.

The issue is that gdk_pixbuf_new_from_file() ultimately tries to determine the mime type by reading the file into memory and passing it to gio.  However, the header for these image types is so rudimentary (e.g. "P6") that g_content_type_guess() can't determine the mime type without knowing the file's extension, and reports it as application/octet-stream.

Compiling without the GDK_PIXBUF_USE_GIO_MIME makes everything work correctly.

It seems like the simplest fix would be to change _gdk_pixbuf_get_module() to actually pass its "filename" variable to g_content_type_guess().  I have not tested this.

Steps to reproduce:
1. Compile a problem with this main code:

  pixbuf = gdk_pixbuf_new_from_file(argv[1],&gerror);
  if(!originalpb) {
       printf("error message: %s\n", gerror->message);
        exit(1);
   }
   gdk_pixbuf_unref(originalpb);

2. Try to run it with a ppm file as argument.

Actual results:
An error is output:

error message: Couldn't recognize the image file format for file test.ppm

Expected results:
No output.

Does this happen every time?
Yes.

Other information:
Comment 1 Tyler Lawson 2009-01-29 13:46:47 UTC
Created attachment 127458 [details] [review]
Proposed fix by passing filename to gio
Comment 2 Tyler Lawson 2009-01-29 14:11:42 UTC
The above patch is the one I mentioned in the bugreport.  It fixes the problem on my machine.
Comment 3 Matthias Clasen 2009-01-29 15:22:04 UTC
We did pass the filename initially. That was removed when people started to complain that they could no longer name there png files foo.gif and still have eog load them...

If g_content_type_guess can't correctly sniff ppm files, thats something that should be addressed in shared-mime-info 
Comment 4 Tyler Lawson 2009-01-29 17:07:38 UTC
Well, now that's just silly.

OK.  If that needs to be worked around, then so be it.  It is now reported to shared-mime-info <a href="http://bugs.freedesktop.org/show_bug.cgi?id=19811">here</a>.
Comment 5 Tyler Lawson 2009-02-09 17:51:04 UTC
shared-mime-info has marked this as WONTFIX because the magic for a PPM header is only 2 characters.

I'm attaching another proposed fix for this problem.  It checks if g_content_type_guess() returned an "uncertain" result, and if so then it checks based on the filename.  This hopefully will satisfy everyone except those who want to load misnamed files with malformed headers.
Comment 6 Tyler Lawson 2009-02-09 17:52:29 UTC
Created attachment 128312 [details] [review]
Proposed fix by rechecking when mime sniffer is uncertain
Comment 7 Matthias Clasen 2009-02-12 05:34:29 UTC
Sounds like an acceptable compromise to me.
Comment 8 Tyler Lawson 2009-02-12 14:43:22 UTC
OK.  I don't have access to commit this, can someone else?
Comment 9 Matthias Clasen 2009-03-01 07:39:48 UTC
        * gdk-pixbuf-io.c (_gdk_pixbuf_get_module): If pure sniffing
        yields uncertain results, try again with the filename.
        Patch by Tyler Lawson
Comment 10 Eitan Mosenkis 2009-05-21 17:34:06 UTC
This bug still breaks things such as xscreensaver's webcollage that name various images without an extension.  Perhaps instead of using filename in a case of uncertainty, it could check for the PPM header.  It should only get called when it's expected to be an image and if it fails, it won't be anything that would have worked without this tweak.  This could also be a last resort after the filename fix when that doesn't work either.