Can a JPEG Have Multiple Comment Markers?
The JPEG file format fully supports embedding multiple Comment (COM) markers within a single image file. This article explores how the JPEG specification defines comment markers, the structural rules governing their placement, the data limits associated with each marker, and how different software applications interpret multiple comments.
The JPEG COM Marker Specification
In the JPEG standard (ISO/IEC 10918-1 / ITU-T T.81), markers are
two-byte codes beginning with the byte 0xFF followed by a
byte that indicates the marker type. The Comment marker is assigned the
byte value 0xFFFE.
Following the marker code, a two-byte length field specifies the length of the comment segment, including the two length bytes themselves. Because this field is a 16-bit integer, the maximum total size of a single COM segment is 65,535 bytes, leaving up to 65,533 bytes for the actual text or binary payload.
Embedding Multiple Comments
The standard does not restrict a file to a single COM marker. An encoder can write as many COM markers as needed, subject only to the overall file size limits of the medium or filesystem.
These markers can be placed almost anywhere within the JPEG stream
between the Start of Image (SOI, 0xFFD8) marker and the
Start of Scan (SOS, 0xFFDA) marker, alongside other
metadata markers like APP segments (such as Exif or XMP). While it is
technically legal according to the specification for comments to appear
after the scan data or between scans in progressive JPEGs, best practice
dictates placing them in the header region before the image data
starts.
Practical Advantages
Using multiple COM markers provides distinct technical advantages:
- Overcoming Segment Size Limits: If a text description exceeds 65,533 bytes, the text can be divided sequentially across multiple COM segments.
- Separation of Concerns: Distinct pieces of information—such as copyright notices, processing logs, and human-readable image descriptions—can be stored in dedicated markers rather than concatenated into a single block.
- Non-destructive Appending: Software tools can append an additional comment segment to the metadata stream without needing to parse and modify existing comments.
Software Compatibility and Behavior
Although multiple COM markers are syntactically valid according to the JPEG standard, how they are displayed depends on the software reading the file:
- Concatenation: Some image viewers and parsers read all COM segments in sequence and concatenate their text into a single unified block.
- Array or List Display: Advanced metadata utilities (such as ExifTool) can distinguish between each individual comment and display them as separate entries.
- First or Last Only: Basic viewers with limited JPEG decoders often read only the first COM marker encountered and discard the rest, or overwrite previous values so only the last marker remains visible in the user interface.
Because reader behavior varies, relying on multiple COM markers for critical application metadata requires testing with the target toolchain, though the file itself remains fully standards-compliant.