GPS eXchange file
application/octet-stream
Magic Bytes
Offset: 58
3C 6B 39 73 65 74 74 69 6E 67 73
The GPS Exchange Format (GPX) is an XML-based schema developed by TopoGrafix for the interchange of GPS data between applications and web services. It is the standard open format used to store waypoints, tracks, and routes, facilitating compatibility across diverse GPS hardware and mapping software. Since the format relies on plain text XML, it is inherently safe, although standard precautions regarding XML parsing vulnerabilities apply when processing data from untrusted sources.
Validation Code
How to validate .gpx files in Python
Python
def is_gpx(file_path: str) -> bool:
"""
Check if file is a valid GPX by magic bytes.
Signature offset: 58 bytes
"""
signature = bytes([0x3C, 0x6B, 0x39, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6E, 0x67, 0x73])
with open(file_path, "rb") as f:
f.seek(58)
return f.read(11) == signature
How to validate .gpx files in Node.js
Node.js
function isGPX(buffer: Buffer): boolean {
// Signature offset: 58 bytes
const signature = Buffer.from([0x3C, 0x6B, 0x39, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6E, 0x67, 0x73]);
if (buffer.length < 69) return false;
return buffer.subarray(58, 69).equals(signature);
}
Go
func IsGPX(data []byte) bool {
// Signature offset: 58 bytes
signature := []byte{0x3C, 0x6B, 0x39, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6E, 0x67, 0x73}
if len(data) < 69 {
return false
}
return bytes.Equal(data[58:69], signature)
}
API Endpoint
GET
/api/v1/gpx
curl https://filesignature.org/api/v1/gpx