TEX
application/x-tex
Magic Bytes
Offset: 0
5C 69 6E 70 75 74
TEX is a programmable typesetting system file format created by Donald Knuth and currently maintained by the TeX Users Group. This format is primarily utilized for producing technical scientific documents, complex mathematical formulas, and academic publications through systems like LaTeX. While the format itself is plain text and inherently safe, security risks may arise if the underlying compiler is configured to permit unrestricted shell command execution during the document compilation process.
Validation Code
How to validate .tex files in Python
Python
def is_tex(file_path: str) -> bool:
"""Check if file is a valid TEX by magic bytes."""
signature = bytes([0x5C, 0x69, 0x6E, 0x70, 0x75, 0x74])
with open(file_path, "rb") as f:
return f.read(6) == signature
How to validate .tex files in Node.js
Node.js
function isTEX(buffer: Buffer): boolean {
const signature = Buffer.from([0x5C, 0x69, 0x6E, 0x70, 0x75, 0x74]);
return buffer.subarray(0, 6).equals(signature);
}
Go
func IsTEX(data []byte) bool {
signature := []byte{0x5C, 0x69, 0x6E, 0x70, 0x75, 0x74}
if len(data) < 6 {
return false
}
return bytes.Equal(data[:6], signature)
}
API Endpoint
GET
/api/v1/tex
curl https://filesignature.org/api/v1/tex