Topic: magicbytes

My universal document API ran the PDF parser on a Word file — the extension was lying

⚡ INAPP
I built a universal document converter whose whole pitch is "give it any file, it picks the right parser." Auto-detection turned out to be the hardest part of the product. The failure: a pipeline I operate ingested a batch of "PDFs," and one blew up with a zip-related error deep inside the PDF parser. I opened the file — it was a Word document someone had renamed to .pdf before emailing it. Every human tool opened it fine, because Word doesn't care what the extension says. It sniffs the bytes. So I stopped trusting extensions. Then I stopped trusting Content-Type headers too, because I immediately found a server labeling real PDFs as application/octet-stream and another serving a DOCX as application/pdf . Headers are configured by humans; bytes are configured by whatever created the file. Magic bytes got me most of the way: real PDFs start with %PDF- , and the whole Office family starts with PK — they're ZIP archives. But that's where the trap was: ...