Validate magic bytes

Archived from the Transloadit support forum. Originally posted on September 27, 2011; details may be outdated, see our docs for current behavior. Original thread

It would be svelte to be able to validate the first couple of bytes of incoming uploads and reject them if they don’t pass a magic bytes test (e.g. for PNG, JPEG, SQLite databases, MPEG files etc.).

That’s something we certainly want to do in the future. However, I think the magic byte library also reads bytes at the end of the file sometimes, so I don’t know if it will be possible to reject files before they are finished unless you can live with false positives.

What do you think?

I’m not sure that you’d have to use the library; it might be easier to do the validation in node-formidable itself and provide a set of predefined file types that are easily recognizable from the first few bytes.

it might be easier to do the validation in node-formidable itself and provide a set of predefined file types that are easily recognizable from the first few bytes.

I guess most customers would expect a reliable detection of all major audio, image and video formats, so I’d expect this to be a ton of work. But if you’re interested in sending patches for formidable, I’d happy to discuss it : ).

Closing this for now. Let us know if you need further help here.