The check fires on the half of overflow that crosses the sign bit
The pre-patch function, in full, from Netty 4.2.12.Final:
private static int getChunkSize(byte[] hex, int start, int length) {
// trim the leading bytes of white spaces, if any
final int skipped = skipWhiteSpaces(hex, start, length);
if (skipped == length) {
// empty case
throw new NumberFormatException();
}
start += skipped;
length -= skipped;
int result = 0;
for (int i = 0; i < length; i++) {
final int digit = StringUtil.decodeHexNibble(hex[start + i]);
if (digit == -1) {
// uncommon path
final byte b = hex[start + i];
if (b == ';' || isControlOrWhitespaceAsciiChar(b)) {
if (i == 0) {
// empty case
throw new NumberFormatException("Empty chunk size");
}
return result;
}
// non-hex char fail-fast path
throw new NumberFormatException("Invalid character in chunk size");
}
result *= 16;
result += digit;
if (result < 0) {
throw new NumberFormatException("Chunk size overflow: " + result);
}
}
return result;
}
The 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.
In 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.
For any operand x reaching the multiplication:
- If bit 27 of
x is set, the left-shift puts that bit at position 31. The result is negative. if (result < 0) fires.
- 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.
Bit 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.
What 100000004 parses to
The regression test the patch ships against is the chunk-size string 100000004. Nine hex digits. The accumulator walks through them:
| step |
digit |
pre-multiply result |
post-multiply |
post-add |
result < 0? |
| 1 |
1 |
0x00000000 |
0x00000000 |
0x00000001 |
no |
| 2 |
0 |
0x00000001 |
0x00000010 |
0x00000010 |
no |
| 3 |
0 |
0x00000010 |
0x00000100 |
0x00000100 |
no |
| 4 |
0 |
0x00000100 |
0x00001000 |
0x00001000 |
no |
| 5 |
0 |
0x00001000 |
0x00010000 |
0x00010000 |
no |
| 6 |
0 |
0x00010000 |
0x00100000 |
0x00100000 |
no |
| 7 |
0 |
0x00100000 |
0x01000000 |
0x01000000 |
no |
| 8 |
0 |
0x01000000 |
0x10000000 |
0x10000000 |
no |
| 9 |
4 |
0x10000000 |
0x00000000 |
0x00000004 |
no |
Step 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.
The chunk size on the wire is 100000004 in hexadecimal, evaluating to 4,294,967,300 in true arithmetic. Netty interprets it as 4.
The fix is one keyword
The May 4 patch widens the accumulator from int to long:
- int result = 0;
+ long result = 0;
for (int i = 0; i < length; i++) {
final int digit = StringUtil.decodeHexNibble(hex[start + i]);
if (digit == -1) {
// uncommon path
final byte b = hex[start + i];
if (b == ';' || isControlOrWhitespaceAsciiChar(b)) {
if (i == 0) {
// empty case
throw new NumberFormatException("Empty chunk size");
}
- return result;
+ return (int) result;
}
// non-hex char fail-fast path
throw new NumberFormatException("Invalid character in chunk size");
}
result *= 16;
result += digit;
- if (result < 0) {
+ if (result > Integer.MAX_VALUE) {
throw new NumberFormatException("Chunk size overflow: " + result);
}
}
- return result;
+ return (int) result;
Three 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.
The 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.
This 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.
The check was added by someone fixing the chunk-size overflow
The 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, by Jonas Konrad of Oracle. The PR title:
Fix exception on HTTP chunk size overflow (#13735)
The commit motivation:
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:
Caused by: java.lang.IllegalArgumentException: minimumReadableBytes : -1932735284 (expected: >= 0)
at io.netty.util.internal.ObjectUtil.checkPositiveOrZero(ObjectUtil.java:144)
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)
at io.netty.buffer.AbstractByteBuf.readRetainedSlice(AbstractByteBuf.java:887)
at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:480)
Modification: Check for negative chunk size, and throw a NumberFormatException early.
The 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.
-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.
The 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.
Smuggling, by way of a chunk size of four
The regression test the patch appends to HttpRequestDecoderTest:
@Test
public void mustRejectChunkSizeThatWouldCauseOverflow() {
String requestStr = "POST / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
"100000004\r\n" +
"test\r\n" +
"0\r\n" +
"\r\n" +
"GET /smuggled HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Content-Length: 0\r\n" +
"\r\n";
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII)));
HttpRequest request = channel.readInbound();
assertTrue(request.decoderResult().isSuccess());
HttpContent content = channel.readInbound();
assertFalse(content.decoderResult().isSuccess());
assertThat(content.decoderResult().cause()).hasMessageContaining("Chunk size overflow");
}
Two 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.
Pre-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.
For 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.
The 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.
Three smuggling fixes, one CVE, one disclosure wave
Norman 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:
84530fa: adds ContentLengthNotAllowedException and TransferEncodingNotAllowedException. Rejects HTTP/1.1 messages that ship both Transfer-Encoding and Content-Length. Cites RFC 9112's prohibition.
977661f: enforces that chunked is the last value in Transfer-Encoding. Also cites RFC 9112.
Both 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.
A 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 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.
PoC: advisories/GHSA-m4cv-j2px-7723