Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Getting File Type using Regular Expressions

by Abigail-II (Bishop)
on Apr 21, 2004 at 16:38 UTC ( #347054=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Getting File Type using Regular Expressions
in thread Getting File Type using Regular Expressions

Perhaps the byte sequence "P100s of Samsung are really cool phones" is a perfectly well-formed 6x6 pixel GIF file.
No, it isn't. I didn't pick my example lightly. It's not a valid GIF or Netpbm PBM file. But even if it would be valid, it strengthens my argument, that looking at the first couple of bytes to guess the type of content is as bug-ridden as just looking at the file name.
That said, malicious users will attack any such heuristic assumptions to their favor. Britney.jpg.exe If your upload code expects web-intended images and only wants to accept web-intended images, it benefits the system to expect that any available heuristic passes muster.
Interesting that you bring up the web. See, the people who initially designed HTTP got it right. Documents delivered over HTTP are tagged with their type. No inspection of a fragment of the data is required. No implied type derived from the URL. Instead, a clear separation of information (the content) and the meta-information (the content type). Simple. Logical. Not error prone. Isn't that what MacOS does with its resource and data forks?


  • Comment on Re: Getting File Type using Regular Expressions

Replies are listed 'Best First'.
Re: Re: Getting File Type using Regular Expressions
by halley (Prior) on Apr 21, 2004 at 17:46 UTC
    The HTTP protocol offers a MIME type. Where does the server get it? In most configurations, it guesses it. Download a RedHat Package Manager (.rpm) file, and you get application/x-realplayer-media (.rpm) mime type. Oops. Why? Because it used an imperfect heuristic scheme to specify the mime type.

    Neither the Windows filesystem nor the Unix filesystem offers typing metadata. Resource forks and Windows .rc/.res resource files offer typing metadata inside their encoded contents.

    It's just another example when you and I are in "violent agreement" over some topic. Metadata and type-determination methods are weak, and usually poorly implemented. In my case, I just suggested that two heuristics are better than one, instead of ranting that it's all futile unless you have God's Gift to Omniscient Filesystems.

    [ e d @ h a l l e y . c c ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://347054]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2020-08-10 11:51 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (57 votes). Check out past polls.