# Decoder state corruption on malformed streams

Decoders that conflate error with need-more-input, or reset sizes without revalidating

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

## How it works
A decoder must track three outcomes: success, need-more-input, and malformed. When the code collapses these into one value (a boolean, a shared error code, or an ignored return), the caller can no longer tell a truncated stream from a hostile one. Two failure shapes follow. First, an ambiguous return lets a malformed stream be treated as incomplete, so parsing continues into a state the format never allows and a write lands out of bounds [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md). Second, a decoder re-parses an attacker-controlled header offset and reassigns size fields from unvalidated values, skipping the resource check that ran only on the first open [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-g842-9rc4-69pw.md). The broken assumption is that "the header was validated once" or "a false return means retry" holds for every path.

## Where it shows up
- Decoder functions returning a boolean or a single error code for error/need-more-input/ok [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md)
- Fast paths that discard a helper's return value entirely [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md)
- Multi-frame or sub-image formats where seek/tile/sub-open reassigns size or dimensions [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-g842-9rc4-69pw.md)
- Resource or bomb checks run only in the initial open, not on alternate size-setting paths [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-g842-9rc4-69pw.md)
- Row-fill or packing loops whose byte count depends on sample precision and component geometry [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)
- Upload handlers that hand files to native converters (ImageMagick, Ghostscript) out of sight [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)

## How to review
For each decoder entry point, confirm the return type distinguishes all three outcomes and that every caller checks it, including fast paths. For multi-frame formats, enumerate every path that reassigns size/dimension fields and verify the resource check re-runs on each. For pixel/sample loops, verify the buffer size is computed from the same geometry (precision, component resolution) the loop writes with. The invariant: no write or allocation may be sized by one interpretation of the header while filled by another.

## Variants seen
- Boolean return conflating malformed with need-more-input, plus an unchecked fast path [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md)
- Header offset re-parse resetting size without re-running the bomb check [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-g842-9rc4-69pw.md)
- Sub-byte precision with mismatched component resolutions overflowing a packed row buffer [E1](https://bugbountylibrary.com/r/blog%3Awordfence-com-blog-2026-10-wordfence-argus-discovers-critical-vulnerability-in-ghostscript-the-program-that-turns-upload.md)

## Impact and severity
Outcomes ranged from a ~6.4GB allocation DoS from a sub-1KB file [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-g842-9rc4-69pw.md) to heap overflow and RCE reachable through a mundane PDF-thumbnail upload path [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 OOB write in widely used Brotli bindings [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md). Severity rises when the decoder sits behind an upload feature and native converters, hiding the trigger in internal geometry [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 when the flaw ships in a common library dependency [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md).

## 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-g842-9rc4-69pw.md
- E3: https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-python-packages-vulnerable-node2shell-brotli-cve-2026-111497.md
