GNOME Bugzilla – Bug 669854
gdk-pixbuf fails to recognize svg images when they have long comments above the root tag
Last modified: 2013-12-19 05:40:28 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):
+ Trace 229643
>>> 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.
gdk-pixbuf is using gio for file type detection nowadays, which in turn uses shared-mime-info data.
Ok, that needs a trivial fix. I too faced this and have filed https://bugs.freedesktop.org/show_bug.cgi?id=48264 for resolution