Skip to main content
Menu
Advisories

Attacker-controlled excessive allocation in PICT reader via 32-bit opcode payload lengths

GHSA-859W-FQ5P-6C86Published Updated GitHub

Description

Attacker-controlled excessive allocation in the PICT reader via 32-bit opcode payload lengths

Summary

When com.twelvemonkeys.imageio:imageio-pict is present, malformed PICT v2 opcode payload lengths can control the size of a temporary discard array in PICTImageReader.readPICTopcodes. The primary demonstrated path is UncompressedQuickTime (0x8201):

dataLength = pStream.readInt();
pStream.readFully(new byte[dataLength], 0, dataLength);

A 46-byte, 1x1 PICT declaring dataLength = 0x7ffffff0 requests a 2,147,483,632-byte array before the reader checks whether any payload bytes exist. With -Xmx64m, ImageIO.read throws OutOfMemoryError at PICTImageReader.java:1491 on both the exact 3.15.0 release and the reviewed master revision.

The generic reserved-opcode path has the same root cause at line 1530. Source review shows that 0x00d0–0x00fe, 0x8100–0x81ff, and 0xffff read a signed 32-bit length before reaching that allocation. Targeted runtime tests confirmed the lower and upper endpoints of both ranges plus 0xffff.

For clarity, three separate direct branch groups around lines 758, 1424, and 1452, plus the default 0x00a2–0x00af family at line 1497, read an unsigned 16-bit length and are capped at 65,535 bytes. They are not part of this vulnerability. The revised proof patch leaves the three direct groups unchanged. Because 0x00a2–0x00af reaches the same generic discard sink as the vulnerable 32-bit families, its discard implementation changes too, but its length remains 16-bit bounded.

Confirmed revisions and affected package

  • Maven coordinate: com.twelvemonkeys.imageio:imageio-pict
  • twelvemonkeys-3.15.0: 583095bd46c259bd8cb504f6ecda34d54b10ecbc
  • Reviewed master: ef74a9f76f1a03fc9cc0fd57e3dbe0032647fdbf
  • Java: OpenJDK 21.0.12

The vulnerable code dates to commit 4e7316886bcb8686f78f33ef691a9f91cb030379 (2009), so earlier releases are likely affected, but only 3.15.0 and the listed master revision were dynamically confirmed. A conservative advisory range is <= 3.15.0; master was still vulnerable at review time.

Impact

This demonstrates an attacker-controlled excessive allocation request causing OutOfMemoryError; it does not require large raster dimensions or decompression, and it does not claim that the process must first consume the full declared 2 GiB. Applications that include the PICT plugin and pass untrusted image content to ImageIO can expose the condition through ordinary ImageIO.read(File), ImageIO.read(InputStream), or direct ImageInputStream use.

An uncaught OutOfMemoryError can fail image-processing requests and may destabilize or terminate the hosting JVM depending on deployment and error handling. Suggested CVSS remains CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H (7.5), with two qualifications: AV:N assumes a deployment accepting images over a network, and a triager may reasonably choose A:L for deployments that isolate decoder failures.

  • Primary CWE: CWE-789, Memory Allocation with Excessive Size Value
  • Secondary impact CWE: CWE-400, Uncontrolled Resource Consumption
  • Length-validation mechanism: CWE-130, Improper Handling of Length Parameter Inconsistency

Minimal PoC

  • File size: 46 bytes
  • Frame: 1x1
  • Opcode: 0x8201
  • Declared payload: 0x7ffffff0
  • Actual payload: zero bytes
  • SHA-256: f2256c541f8c4375945dfd171423bb6d728946d9a452e9f3bcfabadefec19ed8
  • Base64:
AAAAAAAAAAEAAQARAv8MAP/+AAAASAAAAEgAAAAAAAAAAQABAAAAAIIBf///8A==

With the plugin and normal dependencies on the class path:

ImageIO.read(new File("poc.pct"));

3.15.0 and master both produce:

java.lang.OutOfMemoryError: Java heap space
    at com.twelvemonkeys.imageio.plugins.pict.PICTImageReader.readPICTopcodes(PICTImageReader.java:1491)
    at com.twelvemonkeys.imageio.plugins.pict.PICTImageReader.drawOnto(PICTImageReader.java:356)
    at com.twelvemonkeys.imageio.plugins.pict.PICTImageReader.read(PICTImageReader.java:2648)
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1466)

The same OOM occurs through a MemoryCacheImageInputStream whose length() is -1, and through ImageIO.read(InputStream), including a conventional PICT file prefixed by a 512-byte platform header.

Adversarial and normal controls

All adversarial cases used a fresh -Xmx64m JVM and a 1x1 PICT skeleton.

Case3.15.0Revised local patch
0x8201, length 0x7ffffff0, known-length fileOOM at line 1491IIOException before allocation
0x8201, length 0x7ffffff0, length() == -1OOM at line 1491bounded-buffer EOF → IIOException
0x8201, length 0x80000000NegativeArraySizeException wrapped by ImageIOexplicit IIOException
0x00d0, 0x00fe, 0x8100, 0x81ff, or 0xffff, length 0x7ffffff0OOM at generic sinkIIOException before allocation
Direct 16-bit opcode 0x0092, encoded length 0xffffbounded allocation, then truncated-input IIOExceptionunchanged result
0x8201, declared/actual payload 4 bytes, length() == -1success, 1x1 imagesuccess, 1x1 image
Same valid 4-byte payload with 512-byte header via ImageIO.read(InputStream)success, 1x1 imagesuccess, 1x1 image
Oversized payload with 512-byte header via ImageIO.read(InputStream)OOMIIOException

Remediation and verified proof patch

The revised local patch changes the dedicated 0x8201 discard sink and the shared generic discard sink. The shared sink also services bounded unsigned-16-bit and opcode-derived fixed-length families; the vulnerability claim remains limited to the attacker-sized 32-bit branches identified above.

  1. Reject negative signed lengths.
  2. For streams with a known length, reject a payload larger than the remaining input and seek without allocating a discard array.
  3. For streams whose length is unknown, consume into a fixed buffer of at most 8 KiB so EOF is detected without an attacker-sized allocation.
  4. Leave the unsigned-16-bit direct branches unchanged while preserving the shared generic sink's behavior for valid bounded inputs.

Regression coverage includes known- and unknown-length streams, 0x80000000, lower/upper reserved-long opcodes, direct and shared-sink unsigned-short controls, SPI reachability, 512-byte headers, and valid in-bounds payloads. The PICT module and reactor dependencies passed 2,070 tests with 0 failures and 0 errors (17 skipped).

Duplicate review

  • GHSA-7c3w-m9qh-j2vj / CVE-2026-77429 concerns destination raster allocation driven by width and height. This PoC is 1x1 and faults in an opcode discard buffer.
  • GHSA-fwp7-38wp-mmxw concerns DDS mipMapCount and a Dimension[] allocation in another artifact/parser.
  • PR #1326 validates decoded pixel geometry for CompressedQuickTime (0x8200) in QTRAWDecompressor. This issue is a payload-length allocation in PICTImageReader, primarily demonstrated with UncompressedQuickTime (0x8201).

No matching public issue, pull request, branch, commit, repository advisory, global advisory, or indexed result was found as of the review. This does not rule out a private duplicate.

Affected versions

References

GitHub · haraldk/TwelveMonkeys