Skip to main content
Menu
Advisories

Unbounded allocation in DDS decoder from attacker-controlled mipMapCount

GHSA-FWP7-38WP-MMXWPublished Updated GitHub

Description

DDSHeader.addDimensions (DDSHeader.java:137) allocates a Dimension[] array sized directly from the dwMipMapCount field in the DDS file header, with no upper bound or sanity check:

dimensions = new Dimension[mipMapCount];

A crafted 38-byte DDS file can set dwMipMapCount to a large value, causing the reader to attempt a multi-gigabyte allocation. This results in OutOfMemoryError: Java heap space which terminates the JVM in typical deployments.

Any Java application that calls ImageIO.read() on untrusted input is affected, since TwelveMonkeys registers its DDS reader as an ImageIO SPI plugin.

Steps to reproduce:

  1. Save the following base64 as poc.dds (38 bytes):
RERTIHwAAAAHEAA2ODk3NDY3MjE5NjMwMjQ5MDA3AAIAAAACAAA=
  1. Decode: echo 'RERTIHwAAAAHEAA2ODk3NDY3MjE5NjMwMjQ5MDA3AAIAAAACAAA=' | base64 -d > poc.dds
  2. Run with TwelveMonkeys on the classpath:
import javax.imageio.ImageIO;
import java.io.*;
ImageIO.read(new File("poc.dds"));
// -> java.lang.OutOfMemoryError: Java heap space
//    at DDSHeader.addDimensions (DDSHeader.java:137)

SHA-256: ae2028d887f7f6db22d18e5fecb1b835f366f5dcec40491a729e0f70a9cc4efb

Tested against version 3.14.0, commit 64f27db0502b7260cd49ac34816fbfeda4e4976b.

Suggested fix: Validate mipMapCount against a reasonable cap (DDS spec allows at most ~16 mip levels for typical texture sizes) or against the remaining stream length before allocating.

Found by coverage-guided fuzzing.

Affected versions

References

GitHub · haraldk/TwelveMonkeys