File Signatures (Magic Numbers)
Relying solely on file extensions to determine file formats is unreliable. Instead, systems and applications often inspect the raw bytes at specific offsets within a file header to identify its true format. These unique byte sequences are known as magic numbers or file signatures. A comprehensive resource for these signatures is maintained by Gary Kessler.
Below is a restructured mapping of common file signatures. Instead of formatting offsets and hex sequences as comma-separated strings, the data is organized into explicit objects for better parsing and readability:
{
"image/jpeg": {
"extensions": ["jpg", "jpeg"],
"signatures": [
{ "offset": 0, "hex": "FFD8" }
]
},
"image/png": {
"extensions": ["png"],
"signatures": [
{ "offset": 0, "hex": "89504E470D0A1A0A" }
]
},
"image/gif": {
"extensions": ["gif"],
"signatures": [
{ "offset": 0, "hex": "474946383961" }
]
},
"application/pdf": {
"extensions": ["pdf"],
"signatures": [
{ "offset": 0, "hex": "25504446" }
]
},
"application/zip": {
"extensions": ["zip", "docx", "xlsx", "pptx", "odt"],
"signatures": [
{ "offset": 0, "hex": "504B0304" }
]
},
"application/x-msdownload": {
"extensions": ["exe", "dll"],
"signatures": [
{ "offset": 0, "hex": "4D5A" }
]
},
"application/gzip": {
"extensions": ["gz", "tgz"],
"signatures": [
{ "offset": 0, "hex": "1F8B08" }
]
},
"application/x-rar-compressed": {
"extensions": ["rar"],
"signatures": [
{ "offset": 0, "hex": "526172211A0700" }
]
},
"audio/mpeg": {
"extensions": ["mp3"],
"signatures": [
{ "offset": 0, "hex": "FFFB" },
{ "offset": 0, "hex": "494433" }
]
},
"video/webm": {
"extensions": ["webm"],
"signatures": [
{ "offset": 0, "hex": "1A45DFA3" }
]
}
}
MIME Types Configuration
When web servers like Nginx or Apache serve a file, they include a Content-Type HTTP header to inform the browser about the nature of the data. This mapping between file extensions and MIME types is defined in configuration files such as mime.types.
The official registry for Internet Media Types is maintained by IANA, following the registration guidelines established in RFC 4288 and the syntax rules defined in RFC 6838.
types {
text/html html htm shtml;
text/css css;
text/xml xml;
application/json json;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
image/jpeg jpeg jpg;
image/png png;
image/gif gif;
image/svg+xml svg svgz;
image/webp webp;
image/x-icon ico;
application/octet-stream bin exe dll;
application/pdf pdf;
application/zip zip;
application/x-rar-compressed rar;
application/x-7z-compressed 7z;
application/gzip gz;
application/vnd.ms-excel xls;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.ms-powerpoint ppt;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
application/msword doc;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
audio/mpeg mp3;
audio/ogg ogg;
video/mp4 mp4;
video/webm webm;
video/quicktime mov;
}