Skip to content
Memory corruption Disclosed report Advanced CVE-2026-16402

Integer overflow in nsJXLDecoder CMYK K-buffer sizing -> heap out-of-bounds read

The CMYK K-plane buffer in the JPEG XL decoder was sized with an unchecked 32-bit multiplication, so a crafted image with dimensions whose product overflows int32 causes a far-too-small allocation. The decoder then reads past the end of that buffer, a heap out-of-bounds read.

Kai Martin Follow

Originally disclosed on Mozilla

  • Fixed in 37 hours
  • Paid in 38 days
  • Disclosed after 37 hours
Text
Created attachment 9604514
ASan+UBSan PoC (harness poc_m1_kbuffer.cpp + sanitizer log asan_m1.txt) reproducing the CMYK K-buffer int32 overflow → heap OOB read.

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Steps to reproduce:

Affected code: `image/decoders/nsJXLDecoder.cpp`, `nsJXLDecoder::AllocateFrameBuffers()`.

The CMYK "K" (black) plane buffer is sized with an unchecked 32-bit multiplication, while the pixel
buffer immediately above it correctly uses `mozilla::CheckedInt`:

'''cpp
// pixel buffer: CHECKED (64-bit)
CheckedInt<size_t> bufferSize =
    CheckedInt<size_t>(size.width) * size.height * BytesPerPixel();
... mPixelBuffer.resize(bufferSize.value()) ...

// K buffer: UNCHECKED  (size is OrientedIntSize -> IntSize = BaseSize<int32_t>)
if (mPixelFormat.value() == PixelFormat::Cmyk8 &&
    !mKBuffer.resize(size.width * size.height))    // int32 * int32 -> int (32-bit)
    return NS_ERROR_FAILURE;
'''

`size.width`/`size.height` are int32_t. A CMYK image whose width*height exceeds INT32_MAX overflows
this product (signed overflow), so `mKBuffer` is allocated far too small. `WritePixelRowsToPipe()`
then reads the K plane per row with only a null check, not a bounds check:

'''cpp
const uint8_t* kRow = mKBuffer.begin() + y * size.width;
... out[x*4+3] = kRow ? (255 - kRow[x]) : 0;   // reads mKBuffer[y*width + x]
'''

Repro dimensions: width=65536, height=65537. Both pass the per-dimension INT32_MAX check, but
65536*65537 = 4,295,032,832 wraps (mod 2^32) to 65536, so mKBuffer is 65536 bytes while the loop reads
65537 rows x 65536 bytes.

Attached `poc_m1_kbuffer.cpp` is a self-contained ASan+UBSan harness faithfully reproducing the two
vulnerable statements plus the consumer loop. Build:
`clang++ -std=c++17 -fsanitize=address,undefined -fno-sanitize-recover=address -g poc_m1_kbuffer.cpp -o poc_m1`


Actual results:

UBSan: signed integer overflow: 65536 * 65537 cannot be represented in type 'int32_t'   (poc line 41)
ASan:  heap-buffer-overflow READ of size 1 at the kRow[x] read                           (poc line 57)
       "located 0 bytes after 65536-byte region"  (the under-allocated mKBuffer)
'''
Full log attached (`asan_m1.txt`).

Honest scope: end to end, the pixel buffer (`CheckedInt<size_t>`, 64-bit) computes the true ~4.3 GB
size and must allocate first, so on typical RAM the decode OOMs before reaching the K-buffer line ->
the bug is OOM-adjacent ("OOM-triggered memory corruption" / Moderate), reachable on high-memory /
memory-overcommit systems. Not a cross-origin leak (canvas CORS tainting). The attached PoC is a
harness-level proof of the mechanism; I can build an end-to-end image/jxl testcase against a
JXL-enabled ASan build on request. Dedup: no public Bugzilla match (checked 2026-07-05).


Expected results:

Size the K buffer with overflow protection, exactly like the pixel buffer above it:
'''cpp
CheckedInt<size_t> kSize = CheckedInt<size_t>(size.width) * size.height;
if (mPixelFormat.value() == PixelFormat::Cmyk8 &&
    (!kSize.isValid() || !mKBuffer.resize(kSize.value())))
    return NS_ERROR_FAILURE;
'''
so an oversized/overflowing CMYK image is rejected rather than under-allocating mKBuffer. Optionally
also bounds-check `kRow` indexing in `WritePixelRowsToPipe` as defense in depth.

The original report as published on Mozilla's Bugzilla, by Kai Martin. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The K-plane buffer size was computed with an unchecked int32 multiplication instead of the checked 64-bit arithmetic used for the pixel buffer.

Impact

On typical RAM the earlier pixel-buffer allocation OOMs first, so the corruption is only reachable on high-memory or memory-overcommit systems; it is not a cross-origin leak because canvas CORS tainting applies.

What the attacker needed

A crafted CMYK JPEG XL image; high-memory or overcommit system

The fix

The K buffer should be sized with CheckedInt<size_t> like the pixel buffer, rejecting oversized images, and optionally the row indexing should be bounds-checked.

How it was found

  1. Craft a CMYK JPEG XL image with width 65536 and height 65537, both within the per-dimension limit.
  2. The product wraps to 65536, so the K buffer is allocated at only 65536 bytes.
  3. The decoder then reads 65537 rows of 65536 bytes from that buffer, going out of bounds.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When an image is decoded, the program reserves memory for its pixels by multiplying width by height. Here that multiplication was done in a small number type that wraps around for huge images, so the program reserved almost no memory but then read as if it had. That mismatch lets it read memory it never reserved, which is a memory-safety bug.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.