file/type list/libmagic overhaul
James Cloos
cloos+file at jhcloos.com
Sun Aug 24 02:15:27 EEST 2008
>>>>> "Gravis" == Gravis <filemaillist at adaptivetime.com> writes:
Gravis> i did some investigating using your provided sample and found
Gravis> something interesting. whatever the default magic file is, it's
Gravis> not the correct magic file.
I just tried my installed instance of file(1) (gentoo box, compiled via
the ebuild using gcc 4.2; box is x86) against a text magic(5) file.
Specifically, I unpacked the 4.25 tar.gz and pointed file at the images
file in Magdir. It still cannot detect a PNG file, though everything
else I tested worked as expected: correct detection if in the specified
Magdir file or a default (such as ASCII Text for ppm, pdf, ps files) if
the file was not included in the Magdir file I specified.
The images file says, in part:
,----< excerpt from file-4.25/Magdir/images >
| 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
`----
If I drop the \x0a from the end of the string the detection works.
This, even though:
,----< dd bs=8 count=1 in=foo.png|od -t x1 >
| 0000000 89 50 4e 47 0d 0a 1a 0a
`----
So there seems to be a bug in how file (or libmagic?) handles strings.
That change in the magic(5) file also prevents the segfault when calling
file(1) with the --mime-encoding option. Gdb says about the segv:
,----[ backtrace from »file --mime-encoding foo.png« ]
| #0 0xb7f997a3 in strlen () from /lib/libc.so.6
| #1 0xb80717cf in file_getbuffer () from /usr/lib/libmagic.so.1
| #2 0xb80653ce in file_or_fd () from /usr/lib/libmagic.so.1
| #3 0x08048dbe in process ()
| #4 0x080496d6 in main ()
`----
All works flawlessly with a seven octet string in magic(5) for PNG;
both bugs only show up with the full eight octet string.
-JimC
--
James Cloos <cloos at jhcloos.com> OpenPGP: 1024D/ED7DAEA6
More information about the File
mailing list