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 136071 - xdgmimemagic.c fix
xdgmimemagic.c fix
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Jonathan Blandford
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-03-03 14:58 UTC by Carlos Romero
Modified: 2011-02-04 16:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
xdgmimemagic.c order fix (798 bytes, patch)
2004-03-03 15:04 UTC, Carlos Romero
none Details | Review
my fix (3.21 KB, patch)
2004-03-03 19:15 UTC, Christophe Fergeau
none Details | Review

Description Carlos Romero 2004-03-03 14:58:13 UTC
bring sanity to mime detection, you sawit here first folks
Comment 1 Carlos Romero 2004-03-03 15:04:38 UTC
Created attachment 25102 [details] [review]
xdgmimemagic.c order fix
Comment 2 Owen Taylor 2004-03-03 16:45:33 UTC
Explanation please....
Comment 3 Christophe Fergeau 2004-03-03 19:14:28 UTC
I investigated and wrote a patch for the same problem in gnome-vfs. I
sent it to jrb so that he can review it, but he didn't have time to
look at it yet. Here is the mail I sent him, I hope the explanation
will be clear enough for someone not familiar with the code. 

« The attached patch fixes a bug with the xdgmime code where any elf
executable file would be sniffed as an application/x-core file. This
happens because of a bug in xdgmimemagic.c when the magic for a mime
type is composed of several 'indented' patterns.
xdgmimemagic.c reads the patterns one by one, and each time it has read
one pattern, it prepends them at the beginning of a list. With a file
created from
<match .... />         <- indent 0
<match ....>           <- indent 0
  <match ....>         <- indent 1
     <match ... />     <- indent 2
  </match>
</match>
you'd have in memory a list composed of
(pattern with indent 2), (pattern with indent 1), (pattern with indent
0), (pattern with indent 0)

On the other hand, the code in _xdg_mime_magic_matchlet_compare_level
assumes that the list it processes contains the parsed indented patterns
in the same order as the magic file, which caused the misdetection of
the mime type of those elf executables.

I fixed that by mirroring the list of patterns, the place where I'm
doing it may not be appropriate, but files in /bin are now properly
identified as executable files. »

Comment 4 Christophe Fergeau 2004-03-03 19:15:56 UTC
Created attachment 25122 [details] [review]
my fix
Comment 5 Christophe Fergeau 2004-03-03 19:17:38 UTC
Both patches are doing the same thing, they make sure the list of
patterns are stored in memory in the same order as they were in the
file. My version prepend each patterns to the list of already read
patterns, and the mirror that list, while the first patch attached to
that bug appends patterns to the list of already read patterns.
In real world, this shouldn't matter much from a performance point of
view, since the number of patterns for a given mime type will be
pretty small.
Comment 6 Christophe Fergeau 2004-03-03 19:31:23 UTC
(the change in gnomevfs-info.c obviously doesn't have anything to do
with that bug)
Comment 7 Christophe Fergeau 2004-03-03 19:31:53 UTC
I also filed
http://freedesktop.org/cgi-bin/bugzilla/show_bug.cgi?id=264 about this
issue
Comment 8 Jonathan Blandford 2004-03-11 03:51:46 UTC
Fixed upstream and in GTK+.  Sorry this took so long to get in.