[plug] MIME Types by file contents
Onno Benschop
onno at itmaze.com.au
Sat Jul 3 05:37:04 WST 2004
On Fri, 2004-07-02 at 22:55, Bernd Felsche wrote:
> Using "file -bi ~/* | sort -u"
Note of caution. I once had the same problem, but in PHP. My solution
was also to use the file command, but it wasn't working in Solaris. Then
I found out that there are multiple version of file.
On the way I learnt roughly how the magic file works and I confess that
it is a pure work of evil. Basically it is a huge list of patterns, so
the code can build a switch() that ends up looking like this:
if byte[4]=aa and byte[6]=b0 and byte[42]=11 then return bob/type
if byte[22]=be and byte[11]=00 and byte[12]=00 then return music/type
etc.
(Of course there is pattern matching in there also, but it's all based
on certain character orders.) So, if you carefully craft legitimate
data, that matches one of those things, then it will be mis-identified.
All I'm saying is that while I also used file as a solution, it's evil,
bad, subject to breaking and cause for palpitations.
Onno Benschop
Connected via Optus B3 at S27°52'30" - E151°16'25" (Millmerran, QLD)
--
()/)/)() ..ASCII for Onno..
|>>? ..EBCDIC for Onno..
--- -. -. --- ..Morse for Onno..
Proudly supported by Skipper Trucks, Highway1, Concept AV, Sony Central, Dalcon
ITmaze - ABN: 56 178 057 063 - ph: 04 1219 8888 - onno at itmaze dot com dot au
More information about the plug
mailing list