File signature
A file signature is a specified byte sequence at a defined position used to help identify a file format.
Scope: Media-type registrations can describe magic bytes and filename extensions separately. A format signature identifies a byte pattern; it is neither a checksum of the whole file nor a cryptographic digital signature. [2]
Example: PNG starts with hexadecimal bytes 89 50 4E 47 0D 0A 1A 0A. Those eight bytes alone match the PNG image-type pattern in the MIME Sniffing Standard, but do not form a conforming PNG datastream: required chunks, including IHDR and IEND, are absent. [3] [4]
Validation: Check the selected format's complete structural and data requirements after identification. A filename, declared media type or successful prefix comparison does not establish completeness, authenticity or application suitability. [3] [1]
Ambiguity: Binary polyglots allow multiple formats to coexist in the same bytes. Albertini et al. distinguish these from near polyglots that require byte changes. Validation for one format therefore does not establish a unique interpretation or safety in another consumer. [5]
Relations
- related
- Media type, Data serialization, Checksum, Byte order
Citations
- RFC 9110: Content-Type and media types, sections 8.3 and 8.3.1
- RFC 6838: additional media-type identification information, section 4.12
- W3C PNG Third Edition: file signature and datastream conformance
- WHATWG MIME Sniffing: matching an image type pattern
- Albertini et al., USENIX Security 2022: binary versus near polyglots and format characteristics, sections 4.2-4.4
Further reading
Sources & caveats
- The signature-only PNG case is a specification-derived counterexample, not a measured decoder result.
- The executable example tests only the eight-byte PNG prefix rule; it is not a general MIME sniffer or a PNG validator.