-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The check fires on the half of overflow that crosses the sign bit\n\nThe pre-patch function, in full, from Netty 4.2.12.Final:\n\n```java\nprivate static int getChunkSize(byte[] hex, int start, int length) {\n // trim the leading bytes of white spaces, if any\n final int skipped = skipWhiteSpaces(hex, start, length);\n if (skipped == length) {\n // empty case\n throw new NumberFormatException();\n }\n start += skipped;\n length -= skipped;\n int result = 0;\n for (int i = 0; i < length; i++) {\n final int digit = StringUtil.decodeHexNibble(hex[start + i]);\n if (digit == -1) {\n // uncommon path\n final byte b = hex[start + i];\n if (b == ';' || isControlOrWhitespaceAsciiChar(b)) {\n if (i == 0) {\n // empty case\n throw new NumberFormatException(\"Empty chunk size\");\n }\n return result;\n }\n // non-hex char fail-fast path\n throw new NumberFormatException(\"Invalid character in chunk size\");\n }\n result *= 16;\n result += digit;\n if (result < 0) {\n throw new NumberFormatException(\"Chunk size overflow: \" + result);\n }\n }\n return result;\n}\n```\n\nThe accumulator is `int result = 0`. Each iteration multiplies by sixteen, adds the next hex digit, and asks whether the value has become negative. The final line returns the accumulator. This is the function CVE-2026-42580 names.\n\nIn Java, signed-integer multiplication does not throw on overflow. `int * int` produces an `int`, and bits beyond bit 31 are discarded. Multiplying by sixteen is a left shift by four. Any of the operand's top four bits that were set are gone. Whether the post-shift value has the sign bit set depends entirely on what bit 27 of the operand was before the shift.\n\nFor any operand `x` reaching the multiplication:\n\n* If bit 27 of `x` is set, the left-shift puts that bit at position 31. The result is negative. `if (result < 0)` fires.\n* If bit 27 of `x` is clear, the left-shift puts a zero at position 31. The result is non-negative. The check is silent.\n\nBit 27 is a coin flip across the operand space the accumulator can reach. Roughly half of the integer-overflow events on this loop produce a negative `result`. Roughly half do not. The check is a coin flip on whether overflow is caught.\n\n## What `100000004` parses to\n\nThe regression test the patch ships against is the chunk-size string `100000004`. Nine hex digits. The accumulator walks through them:\n\n| step | digit | pre-multiply `result` | post-multiply | post-add | `result < 0`? |\n|------|-------|-----------------------|---------------|----------|----------------|\n| 1 | `1` | `0x00000000` | `0x00000000` | `0x00000001` | no |\n| 2 | `0` | `0x00000001` | `0x00000010` | `0x00000010` | no |\n| 3 | `0` | `0x00000010` | `0x00000100` | `0x00000100` | no |\n| 4 | `0` | `0x00000100` | `0x00001000` | `0x00001000` | no |\n| 5 | `0` | `0x00001000` | `0x00010000` | `0x00010000` | no |\n| 6 | `0` | `0x00010000` | `0x00100000` | `0x00100000` | no |\n| 7 | `0` | `0x00100000` | `0x01000000` | `0x01000000` | no |\n| 8 | `0` | `0x01000000` | `0x10000000` | `0x10000000` | no |\n| 9 | `4` | `0x10000000` | `0x00000000` | `0x00000004` | no |\n\nStep 9 is the silent overflow. The operand is `0x10000000`. Bit 28 is set, bit 27 is clear. Multiplying by sixteen left-shifts by four. Bit 28 leaves the integer entirely. The new bit 31 is whatever bit 27 was, which is clear. The post-multiply value is `0x00000000`. Adding the digit `4` gives `0x00000004`. The check evaluates `4 < 0`, which is false. The loop ends, and the function returns `4`.\n\nThe chunk size on the wire is `100000004` in hexadecimal, evaluating to 4,294,967,300 in true arithmetic. Netty interprets it as 4.\n\n## The fix is one keyword\n\nThe May 4 patch widens the accumulator from `int` to `long`:\n\n```diff\n- int result = 0;\n+ long result = 0;\n for (int i = 0; i < length; i++) {\n final int digit = StringUtil.decodeHexNibble(hex[start + i]);\n if (digit == -1) {\n // uncommon path\n final byte b = hex[start + i];\n if (b == ';' || isControlOrWhitespaceAsciiChar(b)) {\n if (i == 0) {\n // empty case\n throw new NumberFormatException(\"Empty chunk size\");\n }\n- return result;\n+ return (int) result;\n }\n // non-hex char fail-fast path\n throw new NumberFormatException(\"Invalid character in chunk size\");\n }\n result *= 16;\n result += digit;\n- if (result < 0) {\n+ if (result > Integer.MAX_VALUE) {\n throw new NumberFormatException(\"Chunk size overflow: \" + result);\n }\n }\n- return result;\n+ return (int) result;\n```\n\nThree changes, one mechanism. The accumulator is now a 64-bit signed type. The check tests against `Integer.MAX_VALUE` directly, because that ceiling is now representable inside the accumulator without itself overflowing. The two return points narrow back to `int`, because the function's contract with the rest of the codec stays a 32-bit chunk size.\n\nThe predicate moves from `if (result < 0)`, a test for one of overflow's two visible signatures, to `if (result > Integer.MAX_VALUE)`, a direct test against the ceiling the function is allowed to return. The latter is what the original commit message thought it had written.\n\nThis is **sign-bit-is-not-overflow**: a check authored honestly against the threat model, implemented as a comparison against zero, that captures the subset of overflows where the multiplication or addition flips the sign bit, and is silent on the subset where the high bits leave the integer cleanly. The name of the check matches the name of the threat. The implementation matches one of the threat's two arithmetic manifestations.\n\n## The check was added by someone fixing the chunk-size overflow\n\nThe line `if (result < 0) throw new NumberFormatException(\"Chunk size overflow: \" + result)` was not in Netty 4.1.99 or earlier. It was added on January 3, 2024 in commit `78639fa5`, PR [#13735](https://github.com/netty/netty/pull/13735), by Jonas Konrad of Oracle. The PR title:\n\n> Fix exception on HTTP chunk size overflow (#13735)\n\nThe commit motivation:\n\n> If there is an overflow in the chunk size calculation, it would throw an exception on the pipeline instead of an invalid chunk like other number format errors. In particular:\n>\n> ```\n> Caused by: java.lang.IllegalArgumentException: minimumReadableBytes : -1932735284 (expected: >= 0)\n> at io.netty.util.internal.ObjectUtil.checkPositiveOrZero(ObjectUtil.java:144)\n> at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)\n> at io.netty.buffer.AbstractByteBuf.readRetainedSlice(AbstractByteBuf.java:887)\n> at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:480)\n> ```\n>\n> Modification: Check for negative chunk size, and throw a NumberFormatException early.\n\nThe author traced the bug correctly. A chunk-size overflow had produced the value `-1932735284`, which propagated downstream as a `minimumReadableBytes` argument, which then triggered an `IllegalArgumentException` from `ObjectUtil.checkPositiveOrZero`. The stack trace anchored the failure at `HttpObjectDecoder.decode`. The author walked the trace back to the parser, added a check at the parser site, and shipped it.\n\n`-1932735284` is `0x8CCCCCCC`. The sign bit is set. The check the author added catches the case the stack trace named. The case the stack trace did not name, overflow that produces a positive integer, is the case CVE-2026-42580 represents. The check the author added does not catch `0x00000004`.\n\nThe commit shipped in Netty 4.1.105 in January 2024. It stayed in production for sixteen months. The replacement landed in 4.2.13.Final on May 8, 2026. The 2024 commit and the 2026 commit are not adversarial. They are sequential drafts of the same check, written by different authors looking at different halves of the same overflow.\n\n## Smuggling, by way of a chunk size of four\n\nThe regression test the patch appends to `HttpRequestDecoderTest`:\n\n```java\n@Test\npublic void mustRejectChunkSizeThatWouldCauseOverflow() {\n String requestStr = \"POST / HTTP/1.1\\r\\n\" +\n \"Host: localhost\\r\\n\" +\n \"Transfer-Encoding: chunked\\r\\n\\r\\n\" +\n \"100000004\\r\\n\" +\n \"test\\r\\n\" +\n \"0\\r\\n\" +\n \"\\r\\n\" +\n \"GET /smuggled HTTP/1.1\\r\\n\" +\n \"Host: localhost\\r\\n\" +\n \"Content-Length: 0\\r\\n\" +\n \"\\r\\n\";\n\n EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());\n assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII)));\n\n HttpRequest request = channel.readInbound();\n assertTrue(request.decoderResult().isSuccess());\n HttpContent content = channel.readInbound();\n assertFalse(content.decoderResult().isSuccess());\n assertThat(content.decoderResult().cause()).hasMessageContaining(\"Chunk size overflow\");\n}\n```\n\nTwo HTTP/1.1 requests concatenated on a single connection. The first declares `Transfer-Encoding: chunked`, announces a chunk of size `100000004` hex, supplies four bytes of content (`test`), and terminates with a zero chunk. The second is a `GET /smuggled` with no body.\n\nPre-patch Netty reads `100000004`, calls `getChunkSize`, gets back `4`. It reads four bytes of body, reaches the terminating `0` chunk, treats the first request as complete, and parses the next bytes on the same socket as a fresh pipelined request. Those bytes are `GET /smuggled HTTP/1.1\\r\\n...`. Netty's pipeline emits two `HttpRequest` objects from the same input.\n\nFor the smuggling to land in the field, the front-end ahead of Netty must disagree with Netty about where the first request ends. A reverse proxy that parses `100000004` as the full 36-bit hex value reads a chunk declared as 4,294,967,300 bytes, accepts the ~100 bytes of payload the client actually sends, forwards them as part of a single in-flight request, and waits for the rest. The proxy thinks one request is being delivered. Netty has already emitted two.\n\nThe shape is standard HTTP request smuggling: front-end and back-end disagree on where a message ends. The novel substrate is that the back-end disagrees with itself about arithmetic.\n\n## Three smuggling fixes, one CVE, one disclosure wave\n\nNorman Maurer landed the chunk-size patch on May 4, 2026, as commit `b7f7bfc`. The merge-commit message is `Merge commit from fork`, Netty's convention for security fixes coordinated through a private fork. Two adjacent commits landed on the same branch from the same fork on the same day:\n\n* `84530fa`: adds `ContentLengthNotAllowedException` and `TransferEncodingNotAllowedException`. Rejects HTTP/1.1 messages that ship both `Transfer-Encoding` and `Content-Length`. Cites RFC 9112's prohibition.\n* `977661f`: enforces that `chunked` is the last value in `Transfer-Encoding`. Also cites RFC 9112.\n\nBoth are smuggling-relevant. Neither carries an independent CVE. The GitHub Security Advisory Database tagged one of the three Netty smuggling fixes from May 4 as CVE-2026-42580: the chunk-size one. The other two ship in the same 4.2.13.Final release without their own advisories.\n\nA fourth Netty advisory in the same disclosure wave covers QPACK on the HTTP/3 codec. CVE-2026-42582, where the same reporter (`violetagg`) found one allocation site, patched three, and the advisory text propagated her first finding. [The earlier post in this sequence](/posts/netty-qpack-cve-2026-42582-patch-closes-three-advisory-names-one) reads that one. The QPACK bug is a different pattern, outer-frame-doesn't-bound-inner-length rather than sign-bit-as-overflow-check, but both belong to the same May 4 audit cycle and both ship in the same release.\n\nPoC: [advisories/GHSA-m4cv-j2px-7723](https://github.com/netty/netty/security/advisories/GHSA-m4cv-j2px-7723)\n","closing_line":"`int` to `long` is the diff. Sixteen months is the rest of it.","hook_md":"Netty's HTTP/1 chunk-size parser accumulates hex digits into a 32-bit signed `int` and guards the accumulator with `if (result < 0) throw new NumberFormatException(\"Chunk size overflow: \" + result)`. The check fires when the multiplication tips the value into negative territory. It is silent when the top bits leave the integer cleanly and the result remains positive.\n\nCVE-2026-42580 is the chunk size that takes the second path. The commit that introduced the bug into Netty is titled `Fix exception on HTTP chunk size overflow`.","post_id":386,"slug":"netty-chunk-size-cve-2026-42580-overflow-check-caught-half","title":"CVE-2026-42580: Netty's Chunk-Size Overflow Check Caught Half the Overflows","type":"initial","unreadable_sentence":"The commit that introduced the bug into Netty is titled `Fix exception on HTTP chunk size overflow`."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCalkYZAAKCRDeZjl4jgkQ Jk0IAQCmGRI3qK9TY0M3tnzsrQxKHgceUU12G+MCekflXeEcHgD/U9DzU8LIm86F nBZYQjBMa3re6+OAkzwhCmoWsMKxNgc= =LIi7 -----END PGP SIGNATURE-----