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 669854 - gdk-pixbuf fails to recognize svg images when they have long comments above the root tag
gdk-pixbuf fails to recognize svg images when they have long comments above t...
Status: RESOLVED NOTGNOME
Product: gdk-pixbuf
Classification: Platform
Component: general
2.24.x
Other Linux
: Normal normal
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2012-02-11 03:27 UTC by Walter Mundt
Modified: 2013-12-19 05:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
SVG file that can't be loaded via gdk_pixbuf_new_from_file but will load using a loader specifying the SVG file type (11.49 KB, image/svg+xml)
2012-02-11 03:27 UTC, Walter Mundt
Details

Description Walter Mundt 2012-02-11 03:27:41 UTC
Created attachment 207314 [details]
SVG file that can't be loaded via gdk_pixbuf_new_from_file but will load using a loader specifying the SVG file type

See https://bugs.launchpad.net/ubuntu/+source/gdk-pixbuf/+bug/926019 for a bug filed with Ubuntu about this.  Tested on Ubuntu 11.10.  Paste of the relevant text: (the icon I'm referring to is attached for reference/testing).

Gdecrypt was failing to launch; I checked into it, and it is attempting to load /usr/share/icons/hicolor/scalable/apps/gdecrypt.svg and failing.

The file loads up just fine in eog and inkscape, and appears to be perfectly a valid svg. In Python, you can try to load it directly:
$ cd /usr/share/icons/hicolor/scalable/apps
$ python
>>> import gtk
>>> gtk.gdk.pixbuf_new_from_file("gdecrypt.svg")
Traceback (most recent call last):
  • File "<stdin>", line 1 in <module>
glib.GError: Couldn't recognize the image file format for file 'gdecrypt.svg'
>>> gtk.gdk.pixbuf_get_file_info("gdecrypt.svg")
>>> gtk.gdk.pixbuf_get_file_info("gnome-panel.svg")
({'is_writable': False, 'extensions': ['svg', 'svgz', 'svg.gz'], 'mime_types': ['image/svg+xml', 'image/svg', 'image/svg-xml', 'image/vnd.adobe.svg+xml', 'text/xml-svg', 'image/svg+xml-compressed'], 'name': 'svg', 'description': 'Scalable Vector Graphics'}, 48, 48)

Comparing the two leads to one important difference. gnome-panel.svg starts with:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
...

gdecrypt.svg, on the other hand:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<!-- Copyright (C) 2007 Kjell Braden
      Permission is granted to copy, distribute and/or modify this
      document under the terms of the GNU General Public License,
      Version 3 or any later version published by the Free Software
      Foundation. -->
<svg
...


Using a loader with the svg file type specified loads the icon just fine even with the comment, so the actual loading code is fine; it is only the image type detection that is failing.

If the copyright notice is removed, the icon loads just fine and everything works. However, the comment is well-formed and there's nothing I'm aware of forbidding svg files from containing comments of any length ahead of the document root tag. As such, it is not generally safe to use MIME magic that only looks at the beginning of the file to detect the svg format. I have no suggestions as to how to solve this in the general case, but I suspect that it is what is happening here, and there's no good reason not to use the file extension to determine the type of the icon right when a filename is available, as it is in pixbuf_new_from_file.

While I ran into this in trying out gdecrypt, I believe this is clearly a gdk-pixbuf issue that is merely negatively affecting that package, so I'm filing this bug against the latter package.
Comment 1 Matthias Clasen 2012-02-13 03:37:47 UTC
gdk-pixbuf is using gio for file type detection nowadays, which in turn uses shared-mime-info data.
Comment 2 Chandni Verma 2012-04-03 19:30:24 UTC
Ok, that needs a trivial fix.
I too faced this and have filed https://bugs.freedesktop.org/show_bug.cgi?id=48264 for resolution