PNG Security and Privacy: Hidden Data to Check

November 08, 2026 · PNG.now Editorial · PNG Essentials

Review active content, parser risks and hidden metadata before opening or sharing PNG files.

Chunk-Level Active Content: tEXt, zTXt, and iTXt

PNG text chunks store keyword-value pairs that viewers never render as pixels. The specification defines three variants, each capable of carrying strings that downstream applications may interpret as executable code.

  • tEXt uses Latin-1 encoding with null-separated keyword and text fields. Both fields accept arbitrary bytes except the null terminator in the keyword. An attacker can place JavaScript, HTML fragments, or shell commands directly in the text field. If a web service extracts this chunk and injects its content into a page without sanitization, the result is stored cross-site scripting (XSS). Desktop viewers that pass metadata to shell scripts create command injection paths.
  • zTXt compresses the text field with zlib after the keyword. The compression layer hides payloads from string searches and casual hex inspection. Decompression is required before the text becomes usable, but the risk surface is identical to tEXt: the decompressed string is raw and unsanitized by the format.
  • iTXt adds UTF-8 support, a language tag, and an optional compression flag. The structured fields include keyword, compression flag, compression method, language tag, translated keyword, and text. Each text-bearing field is a potential injection point. The compression method byte must be 0 (zlib); any other value violates the specification and signals a malformed or crafted file.

Observable Validation for Text Chunks

Run pngcheck -v file.png to list every chunk by type, length, and CRC status. For deeper inspection, exiftool -png:all file.png prints the content of all text chunks. Look for these indicators:

  • HTML tag sequences (<script, <iframe, <img, onerror=)
  • URI schemes (javascript:, data:text/html, file://)
  • Shell metacharacters (;, |, `, $(), &&)
  • Base64 strings exceeding 100 characters with no whitespace
  • Compression method bytes in iTXt that are not 0x00

Any match means the file carries active content. Treat it as untrusted for browser rendering, document preview, or automated metadata extraction pipelines.

Exif and Color-Management Metadata as Leak Vectors

PNG embeds metadata that can identify the creator, device, location, and software toolchain. Unlike JPEG, where Exif stripping is common, PNG metadata often survives editing and sharing workflows.

eXIf Chunk

The eXIf chunk stores a complete Exif profile in TIFF IFD format. It can contain GPS coordinates, camera serial numbers, lens specifications, timestamps with sub-second precision, and software version strings (Lightroom, Photoshop, GIMP). The chunk is optional but preserved by many editors. A PNG exported from a raw photo file may carry the full Exif record of the original capture.

Check: exiftool -eXIf:all file.png dumps every Exif field. Look for GPSLatitude, GPSLongitude, CameraSerialNumber, Software, and ModifyDate. If any of these fields appear in an image intended for anonymous distribution, the file leaks identity or location.

gAMA and cHRM Chunks

The gAMA chunk stores a single 4-byte unsigned integer representing the file gamma value multiplied by 100,000. The cHRM chunk stores 8×4-byte integers for white point and RGB primaries, each scaled by 100,000. These values are not executable, but their precision and specific combinations fingerprint the creation software. Adobe products write gamma 45455 (1/2.2); sRGB profiles use distinct chromaticity coordinates. In combination with tEXt software tags, these chunks narrow the originating toolchain to a specific version and platform.

Check: pngcheck -v file.png | grep -E "gAMA|cHRM" prints the raw integers. Cross-reference with known software signatures if the image must remain untraceable. Strip these chunks with pngcrush -rem gAMA -rem cHRM when anonymity is required.

sBIT and tRNS: Fixed-Length Chunks as Data Carriers

Two ancillary chunks have tightly specified lengths that parsers rely on for buffer allocation. Malformed versions can carry hidden data or trigger memory-safety bugs.

sBIT (Significant Bits)

sBIT declares the number of significant bits in the original source data. For grayscale, it is 1 byte; for RGB, 3 bytes; for indexed-color, 3 bytes; for grayscale+alpha, 2 bytes; for RGB+alpha, 4 bytes. The length is determined by the color type in IHDR. A crafted PNG can write an sBIT chunk with a length that does not match the color type, or fill the bytes with arbitrary payload data. Parsers that allocate a fixed buffer based on the expected length and then read the declared length from the chunk are vulnerable to buffer over-reads.

Check: Dump the sBIT length with pngcheck -v file.png and compare it against the color type in the IHDR line. Color type 0 expects 1 byte; type 2 expects 3; type 3 expects 3; type 4 expects 2; type 6 expects 4. Any mismatch is a specification violation.

tRNS (Transparency)

For indexed-color images (color type 3), tRNS provides alpha values for up to 256 palette entries, one byte per entry. The chunk length must not exceed the number of entries in PLTE. A tRNS chunk longer than the palette, or present when PLTE is absent, violates the specification. Parsers that copy tRNS data into a fixed 256-byte array without checking the actual PLTE size can overflow the buffer.

Check: Verify that tRNS appears only when PLTE is present, and that its length is ≤ the PLTE entry count (PLTE length ÷ 3). pngcheck flags these violations with invalid tRNS length or tRNS without PLTE.

Steganography in Text and Ancillary Chunks

PNG’s chunk structure makes steganography straightforward. Arbitrary data fits inside tEXt, zTXt, or iTXt chunks under innocuous keywords like Comment, Description, or Copyright. The image renders normally; the payload is invisible.

A single tEXt chunk can hold up to 2³¹−1 bytes (the maximum chunk length). Multiple text chunks multiply this capacity. High-entropy content—data that appears random rather than linguistic—indicates an embedded file, archive, or ciphertext.

Observable checks:

  • Count text chunks: pngcheck -v file.png | grep -cE "tEXt|zTXt|iTXt". More than two text chunks in a photograph or screenshot is anomalous.
  • Measure entropy per chunk: extract text content and compute byte-value distribution. Near-uniform distribution across 0–255 suggests compressed or encrypted data.
  • Run binwalk file.png to detect known file signatures (ZIP, RAR, JPEG, PE) embedded within chunk data.
  • Check the total compressed size of IDAT against the image dimensions. A small image with disproportionately large text chunks warrants manual extraction.

Parser Exploitation: Chunk Length and CRC Attacks

Each PNG chunk begins with a 4-byte length field (big-endian unsigned integer), followed by a 4-byte type code, the data, and a 4-byte CRC. Parsers that trust the length field without bounds checking are vulnerable to several attacks.

Oversized Length Declarations

A chunk length that exceeds the remaining file size forces the parser to read past the IEND chunk. In C-based parsers, this can cause buffer overflows if the parser allocates memory based on the declared length before verifying available data. Versions of libpng prior to 1.6.39 had documented overflows in ancillary chunk handling.

Negative or Wrapped Lengths

The length field is unsigned, but parsers that cast it to a signed integer may interpret values ≥ 2³¹ as negative. A subsequent memory allocation with the negative size can produce a small buffer, leading to heap corruption when the data is copied.

CRC Mismatches

A correct CRC is required for all chunks except IDAT in streaming scenarios. Some parsers silently ignore CRC errors, allowing an attacker to modify chunk content—such as text payloads or color metadata—without detection. A CRC mismatch on IHDR is especially dangerous because it can change the image dimensions, causing a decompression bomb where a small file expands to gigabytes in memory.

Validation commands:

  • pngcheck -v file.png reports every CRC error and length violation. Any output containing CRC error, invalid chunk length, or chunk data length too large means the file is malformed.
  • pngcheck -7 file.png performs a stricter check that enforces chunk ordering rules from the W3C specification (Section 5.6): IHDR must be first, PLTE must precede IDAT if present, IEND must be last. Out-of-order chunks are specification violations and a sign of deliberate crafting.

Hard Limits and Specification Boundaries

The W3C PNG specification defines fixed constraints that serve as validation checkpoints:

Constraint Value Reference
Maximum chunk length 2³¹−1 bytes (2,147,483,647) Section 5.2
Maximum image width/height 2³¹−1 pixels per dimension Section 11.1.2
IHDR chunk length Exactly 13 bytes Section 11.1.1
IEND chunk length Exactly 0 bytes Section 11.2.1
PLTE entry count 1–256 entries (3–768 bytes) Section 11.2.2
gAMA chunk length Exactly 4 bytes Section 11.3.3.2
cHRM chunk length Exactly 32 bytes Section 11.3.3.1
sBIT chunk length 1, 2, 3, or 4 bytes (color-type-dependent) Section 11.3.3.3
tRNS chunk length ≤ PLTE entry count (color type 3) Section 11.3.2.1
Compression method in iTXt/zTXt Must be 0 (zlib deflate) Section 11.3.4.3

Any chunk whose length falls outside these bounds is a specification violation. Treat such files as malicious regardless of whether a viewer opens them without error.

Verification Sequence

Run these checks in order before opening or sharing a PNG from an untrusted source:

  1. Structural integrity: pngcheck -v file.png. Confirm no CRC errors, no length violations, and correct chunk ordering.
  2. Text chunk extraction: exiftool -png:all file.png. Review every text chunk for active content signatures.
  3. Exif and color metadata: exiftool -eXIf:all file.png and pngcheck -v file.png | grep -E "gAMA|cHRM". Strip if anonymity is required.
  4. Chunk count anomaly: pngcheck -v file.png | grep -c "chunk". More than 10 chunks beyond the required IHDR/IDAT/IEND sequence signals extra metadata or hidden data.
  5. Entropy and embedded files: binwalk file.png. Flag any detected file signatures inside chunk data.

If any check produces a warning, error, or unexpected content, isolate the file. Do not open it in a browser, mail client, or document viewer that may interpret chunk content as active markup.

Technical basis for PNG Security and Privacy

Format-level claims use the primary PNG reference.