# Integer underflow to negative length

Unsigned size math that wraps before memcpy, allocation, or buffer length is used

_Area: Memory corruption and native code. Seen in 3 disclosed reports; one confirmed bounty: $40,000; latest 2026-11-18. Updated 2026-12-05._

## How it works
A length is computed by subtraction or padding math on an unsigned type (size_t, off_t, unsigned int). When the subtrahend exceeds the minuend — invalid padding, a refunded credit, a negative size passed in — the result wraps to a huge value or becomes negative. That value is then trusted as a buffer length, so a copy, allocation or write uses a size far larger than the real buffer. The broken assumption is that "length = total - consumed" is always non-negative; nothing checks it before it reaches memcpy or buffer metadata [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md)[E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md)[E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).

## Where it shows up
- Length computed as `total - padding`, `window - credit`, or `size - offset` on unsigned types, with no lower-bound check [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md)[E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).
- Signed/unsigned mismatch between related counters (e.g. a size_t connection window vs an ssize_t stream window) [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md).
- Credit or capacity "refunded" on cleanup, cancel or error paths without re-checking the protocol maximum [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md).
- Error handlers that terminate only a stream (`continue`) instead of the connection, leaving a corrupted counter live [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md).
- SIMD/accelerated decoders that strip padding before computing output length [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).
- APIs that accept a signed size and silently convert it (negative size into a container) [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md).

## How to review
For every length that reaches a copy or allocation, find its definition and prove it cannot go below zero or above the buffer's real capacity. The invariant: any value used as a copy length or buffer size must be validated against both a lower bound (>= 0) and the actual allocated capacity, on every path including cleanup and error. Check that a counter can never exceed its protocol maximum, and that violating it kills the whole connection, not just one stream [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md). Check signed/unsigned conversions at each boundary [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md). For decoders, verify padding is validated before it is subtracted from the length [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).

## How finders spotted it
- Read the guest kernel module to enumerate opcodes, then set breakpoints and watchpoints to trace the async queue to the host handler, and reversed each handler's virtual method for input-controlled bugs [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md).
- Code review of flow-control accounting: noticed the size_t/ssize_t mismatch, a refund without a MAX check, and an error path that only terminated the stream [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md).
- Traced the decoder to the upstream optimization PR, forked at that commit, and reviewed the padding edge case [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).

## Variants seen
- Negative size into a container API causing a 0xffffffff-byte memcpy [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md).
- Flow-control double-refund underflowing a window to a negative response length [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md).
- Invalid padding subtraction producing an all-ones SIMD mask and a 64-byte overwrite [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md).

## Impact and severity
Guest-to-host VM escape and host code execution [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md); unauthenticated worker-context RCE in nginx [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md); RCE in OpenJDK [E3](https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md). Impact rose when chained with an info leak for ASLR bypass and a second bug to disable the exception handler [E1](https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md)[E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md), and when reachable pre-auth [E2](https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.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.
- **nginx** (HTTP/2 flow-control (ngx_http_v2_filter_module.c, ngx_http_v) (version not stated): CVE-2026-123007: Critical NGINX HTTP/2 Integer Underflow Leads to RCE (CVE-2026-123007). Report: https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md
- **OpenJDK** (Base64 decoder (AVX-512 VBMI path)) 17.0.21.1, 21.0.13.1, 25.0.5.1, and 27.0.1.1, fixed in 17.0.21.1, 21.0.13.1, 25.0.5.1, and 27.0.1.1: Aikido's Deep Review finds Java4Shell in the PR that introduced it (CVE-2026-114938). Report: https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md
- **Parallels Desktop** (Tg2OtgImpl, CDragAndDropBase) fixed in 49187: Exploiting an Unbounded memcpy in Parallels Desktop: A Pwn2Own 2021 Guest-to-Host Virtualization Escape. Report: https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Ablog-ret2-io-2022-05-19-pwn2own-2021-parallels-desktop-exploit.md
- E2: https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed.md
- E3: https://bugbountylibrary.com/r/blog%3Aaikido-dev-blog-deep-review-finds-java4shell-in-pr.md
