How the checker identifies a file
The extension is just part of the name, and anyone can change it. The contents are harder to fake. Most binary formats start with a fixed run of bytes, called a magic number or file signature, so the program that opens the file can check it is the right kind. A PNG always begins 89 50 4E 47 0D 0A 1A 0A. A PDF begins with the text %PDF-. A Windows program begins MZ.
The checker reads the first 64 KB and the last 66 KB of the file with your browser's File API and tests them in this order:
- Trailers: a few formats are marked at the end, such as an Apple disk image's
kolyblock 512 bytes from the end. - Containers with a type field: RIFF files carry WAVE, AVI or WEBP at byte 8, and MP4, MOV, HEIC and AVIF carry a brand after
ftypat byte 4. - Fixed signatures, longest first, so the 8-byte RAR 5 header wins over the 7-byte RAR 4 one. Some sit far from the start:
ustarat byte 257 for tar,CD001at byte 32,769 for an ISO disc image. - A look inside: ZIP files are opened to read their entry names, Matroska files to read the DocType, and Office 97-2003 files to find their stream names.
- Text heuristics when nothing else matches: no NUL bytes, valid UTF-8, then a check for JSON, XML, SVG or HTML.
The table on this page lists all 98 signatures and 35 container rules, drawn mainly from Gary Kessler's File Signatures Table, with MIME names from the IANA Media Types registry.