GNOME Bugzilla – Bug 123979
gnome-vfs thinks some of my zip files are mp3s
Last modified: 2004-12-22 21:47:04 UTC
That'd probably be because the gnome-vfs functions to search for an MPEG header actually go quite deep in the file, and these were zipped mp3s. Patch attached.
Created attachment 20518 [details] [review] gnome-vfs mp3 zip fix
How does that happen exactly (ie using which function)? Iirc, gnome-vfs uses looks_like_mp3 only if the file didn't match any other mime sniffing pattern. Is your zip file properly sniffed as a zip file, or is it only recognised by looking at its extension?
from gnome-vfs-mime-magic: # Disable zip because detecting StarOffice files correctly is more imporant in the release # than detecting the occasional zip file without an extension Zip files, just like .gz files, aren't detected by content.
(Probably a good idea to move that code, although simple, to a looks_like_zip) or something.
There is special handling for application/x-gzip files in gnome-vfs-mime.c, maybe zip files should be handled the same way, things would still be ugly, but at least this would be consistent :)
Created attachment 21472 [details] [review] proposed fix
If you reenable zip sniffing in gnome-mime-data and apply this patch, I think your zip files will no longer be misdetected as mp3s (sorry about the patch, there are some indentation changes mixed with the real changes :-/)
I thought that zip detection could bring up false positives, as some formats rely on zip compression (like some StarOffice files are tar.gz with a different extension). If you can disprove that, the fix looks good to me.
Yeah, you can get some false detection (though .tar.gz files won't be detected as zip files imo), that's why files which are sniffed as application/x-gzip or application/zip are special cased. When such a file is found, gnome-vfs tries to guess its mime type using its extension, and returns this mime type if it finds any. Currently, only gzip files are special cased in this way. The patch also special cases zip files.
"though .tar.gz files won't be detected as zip files imo" But StarOffice files won't be detected as StarOffice files but zip files...
I was referring to your "(like some StarOffice files are tar.gz with a different extension)" comment, it looks like you actually meant "zip with a different extension" What the patch does is "if we mime sniff a zip or gzip file, don't return application/(x-g)zip, but guess the mime type using the extension, and return that mime type instead". I guess this would properly identify StarOffice files, and other zip compressed file formats.
Shouldn't it be: result = gnome_vfs_mime_type_from_name_or_default (file_name, "application/x-zip"); and the likes?
Created attachment 21493 [details] [review] updated patch
Good point, this simplifies the code a bit, here is another patch.
Never got around to committing that, is it still happening now that gnome-vfs is using the shared mime database ?
*** Bug 131828 has been marked as a duplicate of this bug. ***
I committed this patch to the 2-4 branch, this is already fixed in HEAD