Reference 04

File signatures

A recognizable byte sequence can support identification. It does not prove that the rest of the file is valid, safe, or even consistently encoded.

FormatOffsetExpected bytesMeaning and caveat
PNG089 50 4E 47 0D 0A 1A 0AThe fixed eight-byte PNG signature. A decoder still needs to validate chunk order, lengths, and checksums.
JPEG0FF D8 FFBegins with the Start of Image marker followed by another marker prefix. Full marker parsing is required.
WebP0, 852 49 46 46 ···· 57 45 42 50RIFF at offset 0 and WEBP at offset 8. RIFF alone also identifies other container families.
ZIP050 4B 03 04A common local-file-header signature. Empty and spanned archives can start with other PK signatures.
gzip01F 8BThe two fixed identification bytes. The next byte identifies the compression method; Deflate is method 8.
PDF025 50 44 46 2DASCII %PDF- starts the header of a conforming PDF, followed by a version number.
JSON / CSV / TXT—No required magic bytesText structure, encoding metadata, and actual parsing are needed; a leading brace or comma is not a reliable signature.

Reading the table

Offsets matter. Some signatures include length fields or container identifiers between fixed byte sequences.

OFFSET

Where to look

Zero means the first byte. A later offset means preceding fields are part of the identification context.

FIXED BYTES

What to compare

Compare only bytes defined as fixed. Wildcards and length fields should not be matched as constants.

PARSER

What comes next

After tentative identification, parse the complete structure and enforce size and recursion limits.

Primary references