# Decoder dimension mismatch allocation

Header dimensions sizing a buffer differ from those driving the copy, fill or scanline loop

_Area: Memory corruption and native code. Seen in 3 disclosed reports; latest 2026-10-22. Updated 2026-11-21._

## How it works
A decoder reads dimensions from an untrusted header and uses them twice: once to size a buffer, once to drive a copy, row fill or scanline scan. The bug is that the two uses disagree. The size may be truncated (32-bit to 16-bit), remapped (a full-resolution plane pointed at a smaller buffer), or a format case may be missing from the allocation pass. The copy still uses the original value, so it writes or reads past the allocation. The assumption that breaks is "the number I allocated with is the number I copy with."

## Where it shows up
- Allocation sized from a narrowed field (16-bit DIB header) while the copy uses full-width values [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md)
- Channel/plane remapping fields (JPEG2000 cdef Asoc) letting a large plane target a small buffer [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md)
- Sub-byte sample precision where the row-fill loop writes one byte per sample instead of packing [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)
- Signed 32-bit bounding-box dimensions stored with no positivity or range check [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md)

## How to review
For every decoder, find each place a header dimension reaches an allocation and each place it reaches a copy, fill or scanline loop. The invariant: the byte count used to allocate must equal or exceed the byte count the copy can produce, for every header value, including truncated, negative, wrapped and remapped ones. Check that narrowing conversions are range-checked, that sub-byte sample loops pack rather than write one byte per sample, and that plane-remapping fields cannot point a full-resolution source at a smaller destination.

## How finders spotted it
- Traced an uploaded file past the PHP upload handler through Imagick and ImageMagick into Ghostscript's JPEG 2000 decoder, hypothesizing a mundane upload feature reaches native parsing several layers down, then reduced to a 1,029-byte PDF differing from a control by one byte in the transparency component's resolution field (the trigger, not the root cause) [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)
- Traced vLLM's video_url path into cv2.VideoCapture and its bundled FFmpeg, then studied JPEG2000 cdef channel-remapping semantics and saw a full-res Y plane could map into the smaller U plane buffer [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md)
- Noticed the EMF branch stores signed 32-bit bounding-box dimensions with no range check, then compared the 16-bit DIB allocation fields against the full-width copy length in display.c [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md)

## Variants seen
- Sub-byte sample packing mismatch with component resolution mismatch [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)
- Channel remap to smaller plane buffer [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md)
- 16-bit truncation of 32-bit dimensions [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md)

## Impact and severity
Heap OOB write leading to RCE in Ghostscript [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md) and via vLLM's video path [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md); heap over-read in Pillow WMF/EMF [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md). Impact rises when chained with an info leak defeating ASLR [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md), and the overflow size scales with image dimensions [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md). Build-matched exploits succeeded across setups sharing one executable, so a single container image widens the blast radius [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md).

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **Pillow (pip)** < 13.0.0, fixed in 13.0.0: Pillow: Heap over-read in WMF/EMF rendering via 16-bit dimension truncation (Windows builds) (CVE-2026-96644). Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md. Fix: https://github.com/python-pillow/Pillow/commit/4cf46bee338304c5c8968fd7f132ba0d40c428b7
- **Ghostscript** (JPEG 2000 decoder (OpenJPEG)) 9.21 through 10.07.1, fixed in 10.08.0: Wordfence Argus Discovers Critical Vulnerability in Ghostscript, the Program That Turns Uploaded PDFs into Thumbnails on (CVE-2026-39919). Report: https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md
- **vllm (pip)** >= 0.8.3, < 0.14.1, fixed in 0.14.1: vLLM has RCE In Video Processing (CVE-2026-22778). Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md. Fix: https://github.com/vllm-project/vllm/pull/31987

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md
- E2: https://bugbountylibrary.com/r/ghsa%3AGHSA-4r2x-xpjr-7cvv.md
- E3: https://bugbountylibrary.com/r/ghsa%3AGHSA-9v9v-9qvf-h2hj.md
