Skip to content

CGM

image/cgm

Safe

Magic Bytes

Offset: 0
42 45 47 4D 46

Computer Graphics Metafile (CGM) is an international standard maintained by ISO and IEC for the representation of 2D vector and raster graphics. It is widely utilized in technical fields such as aeronautics, engineering, and architectural design for exchanging complex CAD illustrations and high-precision diagrams between disparate computer systems. Although largely superseded by modern standards like SVG, CGM persists as a critical legacy format for industrial documentation and specialized scientific visualization due to its robust stability.

Extension

.cgm

MIME Type

image/cgm

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .cgm files in Python

Python
def is_cgm(file_path: str) -> bool:
    """Check if file is a valid CGM by magic bytes."""
    signature = bytes([0x42, 0x45, 0x47, 0x4D, 0x46])
    with open(file_path, "rb") as f:
        return f.read(5) == signature

How to validate .cgm files in Node.js

Node.js
function isCGM(buffer: Buffer): boolean {
  const signature = Buffer.from([0x42, 0x45, 0x47, 0x4D, 0x46]);
  return buffer.subarray(0, 5).equals(signature);
}

How to validate .cgm files in Go

Go
func IsCGM(data []byte) bool {
    signature := []byte{0x42, 0x45, 0x47, 0x4D, 0x46}
    if len(data) < 5 {
        return false
    }
    return bytes.Equal(data[:5], signature)
}

API Endpoint

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

Related Formats

Frequently Asked Questions

What is a .cgm file?

A .cgm file is a CGM file. Computer Graphics Metafile (CGM) is an international standard maintained by ISO and IEC for the representation of 2D vector and raster graphics. It is widely utilized in technical fields such as aeronautics, engineering, and architectural design for exchanging complex CAD illustrations and high-precision diagrams between disparate computer systems. Although largely superseded by modern standards like SVG, CGM persists as a critical legacy format for industrial documentation and specialized scientific visualization due to its robust stability.

What are the magic bytes for .cgm files?

The magic bytes for CGM files are 42 45 47 4D 46 at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .cgm file?

To validate a .cgm file, read the first bytes of the file and compare them against the known magic bytes (42 45 47 4D 46) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .cgm files?

The primary MIME type for .cgm files is image/cgm.

Is it safe to open .cgm files?

CGM (.cgm) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.