Masking in the MIME magic spec

David Faure faure at kde.org
Tue Mar 19 06:28:03 PDT 2013


On Sunday 10 March 2013 12:51:41 Thomas Kluyver wrote:
> The spec [1] says that the mask is applied to the value from the file
> before comparing it with the value from the magic database.
> 
> However, looking for examples, I find image/vnd.adobe.photoshop [2], where
> bytes 5-6 of the mask are \x00\x00, while bytes 5-6 of the value are
> \x20\x20 (two spaces). By my reading, the test is therefore [value & 0x0000
> == 0x2020], which can never be true.
> 
> It looks like the mask should be applied to both the value from the file
> and the value in the magic database, so where the mask is \x00, the magic
> value is ignored. This appears to be what xdgmime does [3]. 

Right. This is what I implemented in Qt as well.

> Is this correct, and is it worth updating the spec to clarify it?

Well, that's one solution.

The other would be to write code that detects the cases where the database has 
values such that  (value & mask) != value, and fixing the database to specify 
(value & mask) as value from now on. This would allow implementations to avoid 
having to mask the value at runtime, which would lead to a minor speedup (and 
to the spec being correct after all).
Such code would be easy to write, as part of any of the existing 
implementations, I would think.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5



More information about the xdg mailing list