DelimiterBasedFrameDecoder non-line delimiter causes quadratic CPU exhaustion via trickled delimiter-free input
Description
DelimiterBasedFrameDecoder configured with a non-line delimiter (for example Delimiters.nulDelimiter() or any custom delimiter) calls ByteBufUtil.indexOf for every delimiter on every decode() call, scanning the whole accumulated buffer from the reader index. It keeps no scan-progress offset, so an unauthenticated remote peer that streams delimiter-free bytes one per TCP segment forces a full buffer scan on each byte, producing O(n^2) CPU work up to the configured maxFrameLength. The common line-delimited configuration is delegated to LineBasedFrameDecoder, which persists a scan offset and is not affected; only the generic-delimiter branch carries this behaviour.
Root Cause
The generic-delimiter branch has no field that records how far the buffer has already been searched. When no delimiter is found, and while the buffer is below maxFrameLength, the decoder returns without consuming any bytes, so the reader index does not advance. The next inbound fragment enlarges the buffer and the decoder rescans it in full from the reader index. The maxFrameLength check only discards data once the buffer already exceeds the limit and therefore bounds memory rather than scan progress. The line-delimiter path avoids this because it is routed to LineBasedFrameDecoder, which resumes searching from a persisted offset and stays linear.
codec-base/src/main/java/io/netty/handler/codec/DelimiterBasedFrameDecoder.java
line 229 decode(ctx, buffer): non-line branch (lineBasedDecoder == null)
line 236-242 loops each delimiter calling indexOf(buffer, delim) => full scan from readerIndex
line 277-294 below maxFrameLength nothing is consumed; returns null with no reader-index advance
(the class has no scan-offset field)
Affected function: io.netty.handler.codec.DelimiterBasedFrameDecoder.decodeImpact
An unauthenticated remote peer that can reach a service using DelimiterBasedFrameDecoder with a non-line delimiter can exhaust CPU on the event-loop thread that services the connection. Framing runs before application logic, so no authentication is required. Because the per-attempt cost grows as the square of the buffered length up to maxFrameLength, and maxFrameLength is commonly one megabyte or larger, a few trickle connections can pin all event-loop threads and cause service unavailability. The impact demonstrated is denial of service; no confidentiality or integrity impact was observed or is claimed. The condition is present only when the application configures a non-line delimiter; that configuration is realistic because a NUL delimiter helper ships with the library and NUL and custom delimited protocols are common.
Proof of Concept
Requires a TCP peer that can send bytes to a pipeline whose framing stage is a DelimiterBasedFrameDecoder configured with a non-line delimiter. Reproduced against the released 4.2.18.Final artifact with a decoder harness on OpenJDK 17.
- Configure
new DelimiterBasedFrameDecoder(maxFrameLength, Delimiters.nulDelimiter())(or any custom, non-line delimiter). - Stream bytes that never contain the delimiter, one byte per inbound read.
- Each inbound byte triggers one
decode()call that scans the whole accumulated buffer.
Inbound bytes: n delimiter-free bytes, one per read, using a NUL delimiter
Measured on the released 4.2.18.Final artifact (single-byte reads, OpenJDK 17):
n = 25,000 -> ~87 ms
n = 50,000 -> ~181 ms
n = 100,000 -> ~669 ms
n = 200,000 -> ~2671 ms (~4x per doubling => quadratic)
Negative control LineBasedFrameDecoder (persists a scan offset): flat => linearAttack Chain
- Exposure: An unauthenticated remote peer reaches a shipped pipeline whose framing stage is a
DelimiterBasedFrameDecoderconfigured with a non-line delimiter; framing runs before application authentication. - Control: The peer fully controls the inbound byte stream and its segmentation, so it can stream bytes that never contain the delimiter.
- Path: With
lineBasedDecodernull,decode()callsindexOffor each delimiter, andByteBufUtil.indexOfscans the entire readable region from the reader index on every call. - Guard: The
readableBytes() > maxFrameLengthdiscard is present but only fires once the buffer exceeds the limit; below the limit the method returns without advancing the reader index, and there is no scan-progress offset. - Primitive: Each
decode()rescans the full accumulated buffer from the reader index. - Result: Summed over n dripped bytes the work is O(n^2), bounded by
maxFrameLengthsquared, exhausting an event-loop thread and, across a few connections, all such threads.
Bypass Evidence
No prior advisory addresses DelimiterBasedFrameDecoder; the repository advisories and the ecosystem advisories for the affected package were enumerated and none names this class or method. The two related complexity issues in this project are in different classes and modules with independent fixes: CVE-2026-73507 / GHSA-v74w-7mr3-4qg3 concerns XmlFrameDecoder, and CVE-2026-75596 / GHSA-fccg-mwvh-qqg4 concerns SslClientHelloHandler. This report is therefore a distinct issue rather than an incomplete fix or duplicate. The generic-delimiter branch was read in full and shown to have no scan-offset field, while the line-delimiter path is routed to LineBasedFrameDecoder, which resumes from a persisted offset; switching the configuration to a line delimiter removes the quadratic behaviour, confirming the missing offset in the generic branch is the cause. The scaling was reproduced on the released artifact with an offset-guarded control decoder staying linear in the same harness. The strongest counterargument considered, that the cost might be low because it is bounded by maxFrameLength, does not hold: maxFrameLength is application chosen and commonly one megabyte or larger, giving a large per-attempt quadratic that pins an event-loop thread.
Affected Versions
Ecosystem: mavenPackage: io.netty:netty-codec-baseConfirmed affected range: <= 4.2.18.FinalLatest release checked: 4.2.18.Final (Maven Central; source byte-identical to the released tag netty-4.2.18.Final)Fix status: not fixed (no released version adds a scan offset to the generic-delimiter branch)
The io.netty:netty-codec-base artifact exists only on the 4.2.x line, and every published release of it carries the unguarded generic-delimiter branch, so the entire published history through 4.2.18.Final is affected with no lower fix boundary. The same code ships on the 4.1.x line under the pre-split coordinate io.netty:netty-codec and is also affected there; that line is not represented in this entry's single package coordinate and was not independently executed, but maintainers should apply the same fix to both artifacts. No fix exists on any line.
Suggested Fix
Add a persisted scan-progress offset to the generic-delimiter branch so each decode() resumes the delimiter search from where the previous call stopped, at parity with the offset already used by LineBasedFrameDecoder. As an interim mitigation, deployments can reduce maxFrameLength to shrink the quadratic ceiling, prefer the line-delimited configuration where protocol semantics allow, or place the endpoint behind authentication or a rate limiter and terminate connections that do not complete a frame promptly, though none of these fully removes the quadratic behaviour.
Reported by zx (GitHub: @manus-pi).