Portable Graymap Graphic

image/x-portable-graymap

Safe

Magic Bytes

Offset: 0
50 32

The Portable Graymap Graphic (PGM) is a grayscale image format created by Jef Poskanzer as part of the Netpbm project. It is primarily utilized in academic research and software development for basic image processing tasks due to its minimalist, uncompressed structure. Although largely considered a legacy format replaced by modern standards like PNG, its architectural simplicity makes it inherently safe and resistant to common buffer overflow vulnerabilities found in more complex encoders.

Extension

.pgm

MIME Type

image/x-portable-graymap

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .pgm files in Python

Python
def is_pgm(file_path: str) -> bool:
    """Check if file is a valid PGM by magic bytes."""
    signature = bytes([0x50, 0x32])
    with open(file_path, "rb") as f:
        return f.read(2) == signature

How to validate .pgm files in Node.js

Node.js
function isPGM(buffer: Buffer): boolean {
  const signature = Buffer.from([0x50, 0x32]);
  return buffer.subarray(0, 2).equals(signature);
}
Go
func IsPGM(data []byte) bool {
    signature := []byte{0x50, 0x32}
    if len(data) < 2 {
        return false
    }
    return bytes.Equal(data[:2], signature)
}

API Endpoint

GET /api/v1/pgm
curl https://filesignature.org/api/v1/pgm

Related Formats