GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't lose frames when a delimiter is split across reads by allthingssecurity · Pull Request #17665 · netty/netty

Conversation

@allthingssecurity

@allthingssecurity allthingssecurity commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Motivation:

When DelimiterBasedFrameDecoder finds no delimiter in the buffer, it counts all readable bytes as frame content and, while discarding a too long frame, skips all of them. That includes a trailing partial delimiter whose remaining bytes are in the next read. With a multi-byte delimiter, this loses frames. In both examples below the delimiter is ## and maxFrameLength is 4:

  • While a too long frame is discarded, the first bytes of the delimiter that ends it are thrown away. The delimiter is never seen, so discarding continues through the next valid frame, which is lost silently. For example, AAAAAAAAAA# then #ok##next## gives TooLongFrameException, next: the ok frame is lost. With failFast = false, the two frames are also reported as a single exception.
  • A frame of up to maxFrameLength bytes is rejected when a read ends inside its delimiter, because the partial delimiter is counted. For example, ABCD# then #ok## gives only TooLongFrameException: ABCD is lost, and ok too (by the first case).

Single-byte delimiters, and line delimiters (which are handled by LineBasedFrameDecoder), are not affected.

Modification:

  • When no delimiter is found, compute the longest suffix of the buffer that is the beginning of a delimiter, and don't count or skip it. This check only runs when no delimiter was found. It compares at most delimiter length - 1 bytes per delimiter, next to the existing search of the whole buffer.
  • New tests in DelimiterBasedFrameDecoderTest:
    • a frame of maxFrameLength bytes with its delimiter split across reads;
    • a delimiter split across reads while discarding, with and without failFast;
    • maxFrameLength is still enforced when the delimiter is split.

Result:

Frames are not lost when a multi-byte delimiter is split across reads. The limit is still exact: the branch that finds the delimiter checks it as before.

  • DelimiterBasedFrameDecoderTest: 9 tests pass. Without the change to DelimiterBasedFrameDecoder, all 4 new tests fail. For example: expected: <ok> but was: <next>, TooLongFrameException: frame length exceeds 4: 5 - discarded, or a lost frame.
  • codec-base tests: 356, 0 failures. Checkstyle passes.
  • Randomized check over 300,000 inputs, with the delimiter sets ##, #!#, abc, {##, !!!} and NUL, random maxFrameLength, stripDelimiter and failFast, and random splits into reads:
    • Split input gave the same result as whole input every time. Inputs that raise more than one exception were excluded, because an exception delays the rest of a buffer until the next read.
    • Without the change, 5,941 of 200,000 differed.
  • Compared with the current decoder, whole-input results only change when the input ends with the beginning of a delimiter: such a truncated last frame is no longer reported as too long before its delimiter can arrive.

The problem was found by modelling the decoder in Lean 4 (split-input equivalence) and reproducing the counterexamples with the real class. The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a Co-Authored-By trailer.

Prepared with Claude Code on behalf of allthingssecurity.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
allthingssecurity and others added 2 commits September 29, 2026 14:16
@allthingssecurity @claude
Don't lose frames when a delimiter is split across reads
c876758
Motivation:

When no delimiter was found, DelimiterBasedFrameDecoder counted and
discarded all readable bytes, including a trailing partial delimiter
whose remaining bytes had not arrived yet:

- While a too long frame was discarded, the first bytes of the
  delimiter that ends it were thrown away. The delimiter was never
  seen, so the discarding went on through the next valid frame, which
  was lost silently.
- A frame whose length is close to maxFrameLength was rejected when a
  read ended inside its delimiter, and the next frame was lost too.

Modification:

When no delimiter is found, don't count or discard the longest suffix
of the buffer that is the beginning of a delimiter. Add tests.

Result:

Frames are no longer lost when a multi-byte delimiter is split across
reads. maxFrameLength is still enforced exactly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allthingssecurity @claude
Merge branch '4.2' into fix-delimiter-split-while-discarding
84eefb1
Resolve the conflicts with the scan offset added to
DelimiterBasedFrameDecoder on 4.2: the beginning of a delimiter at the
end of the buffer is still neither counted nor discarded, and the scan
offset is reset whenever bytes are discarded. Keep the tests of both
sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allthingssecurity

allthingssecurity commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Merged the current 4.2 into this branch (84eefb1) to resolve the conflict with 85498e0 "Fix quadratic scanning in DelimiterBasedFrameDecoder for non-line delimiters".

The two changes are independent: the scan offset from 4.2 is kept as is, and this PR still only changes what is counted and discarded when no delimiter was found. The beginning of a delimiter at the end of the buffer is neither counted as part of the frame nor discarded, and scanOffset is reset to 0 whenever bytes are discarded, so the kept delimiter prefix (always shorter than the longest delimiter) is scanned again on the next read.

The problem is still present on 4.2 after the scan offset change: with the decoder of 4.2 (014ef8d), the four tests of this PR fail (testMaxLengthFrameWithDelimiterSplitAcrossReads, testDelimiterSplitAcrossReadsWhileDiscarding, testDelimiterSplitAcrossReadsWhileDiscardingNoFailFast, testMaxFrameLengthEnforcedWithDelimiterSplitAcrossReads). With the merge, the codec-base tests pass (360 tests, including the new scan offset tests from 4.2), also with -Dio.netty.leakDetection.level=paranoid and without any LEAK: report.

The earlier linux-x86_64-java21 build failure was the JDK download in the Docker image build (sdk install java 21.0.10-zulu: "Download has failed, aborting!"), before any code was compiled.

Prepared with Claude Code on behalf of allthingssecurity

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
Merge branch '4.2' into fix-delimiter-split-while-discarding
50b9c6e
@testlens-app

testlens-app Bot commented Oct 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 50b9c6e
▶️ Tests: 40930 executed
🟡 Checks: 30/33 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer normanmaurer added this to the 4.2.20.Final milestone Oct 19, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Oct 19, 2026
@normanmaurer
normanmaurer merged commit 07aed99 into netty:4.2 Oct 19, 2026
31 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Oct 19, 2026
Auto-port 4.1: Don't lose frames when a delimiter is split across reads #17909
Merged
@netty-project-bot

netty-project-bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17909

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Oct 19, 2026
@netty-project-bot

netty-project-bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17911

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Oct 19, 2026
Auto-port 5.0: Don't lose frames when a delimiter is split across reads #17911
Merged
@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 19, 2026
normanmaurer added a commit that referenced this pull request Oct 19, 2026
@netty-project-bot @allthingssecurity @normanmaurer
Auto-port 5.0: Don't lose frames when a delimiter is split across rea…
6d6eba2
…ds (#17911)

Auto-port of #17665 to 5.0
Cherry-picked commit: 07aed99

---
Motivation:

When `DelimiterBasedFrameDecoder` finds no delimiter in the buffer, it
counts all readable bytes as frame content and, while discarding a too
long frame, skips all of them. That includes a trailing partial
delimiter whose remaining bytes are in the next read. With a multi-byte
delimiter, this loses frames. In both examples below the delimiter is
`##` and `maxFrameLength` is 4:

- While a too long frame is discarded, the first bytes of the delimiter
that ends it are thrown away. The delimiter is never seen, so discarding
continues through the next valid frame, which is lost silently. For
example, `AAAAAAAAAA#` then `#ok##next##` gives `TooLongFrameException,
next`: the `ok` frame is lost. With `failFast = false`, the two frames
are also reported as a single exception.
- A frame of up to `maxFrameLength` bytes is rejected when a read ends
inside its delimiter, because the partial delimiter is counted. For
example, `ABCD#` then `#ok##` gives only `TooLongFrameException`: `ABCD`
is lost, and `ok` too (by the first case).

Single-byte delimiters, and line delimiters (which are handled by
`LineBasedFrameDecoder`), are not affected.

Modification:

- When no delimiter is found, compute the longest suffix of the buffer
that is the beginning of a delimiter, and don't count or skip it. This
check only runs when no delimiter was found. It compares at most
`delimiter length - 1` bytes per delimiter, next to the existing search
of the whole buffer.
- New tests in `DelimiterBasedFrameDecoderTest`:
- a frame of `maxFrameLength` bytes with its delimiter split across
reads;
- a delimiter split across reads while discarding, with and without
`failFast`;
  - `maxFrameLength` is still enforced when the delimiter is split.

Result:

Frames are not lost when a multi-byte delimiter is split across reads.
The limit is still exact: the branch that finds the delimiter checks it
as before.

---------

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Oct 19, 2026
@netty-project-bot @allthingssecurity @normanmaurer
Auto-port 4.1: Don't lose frames when a delimiter is split across rea…
fb6207e
…ds (#17909)

Auto-port of #17665 to 4.1
Cherry-picked commit: 07aed99

---
Motivation:

When `DelimiterBasedFrameDecoder` finds no delimiter in the buffer, it
counts all readable bytes as frame content and, while discarding a too
long frame, skips all of them. That includes a trailing partial
delimiter whose remaining bytes are in the next read. With a multi-byte
delimiter, this loses frames. In both examples below the delimiter is
`##` and `maxFrameLength` is 4:

- While a too long frame is discarded, the first bytes of the delimiter
that ends it are thrown away. The delimiter is never seen, so discarding
continues through the next valid frame, which is lost silently. For
example, `AAAAAAAAAA#` then `#ok##next##` gives `TooLongFrameException,
next`: the `ok` frame is lost. With `failFast = false`, the two frames
are also reported as a single exception.
- A frame of up to `maxFrameLength` bytes is rejected when a read ends
inside its delimiter, because the partial delimiter is counted. For
example, `ABCD#` then `#ok##` gives only `TooLongFrameException`: `ABCD`
is lost, and `ok` too (by the first case).

Single-byte delimiters, and line delimiters (which are handled by
`LineBasedFrameDecoder`), are not affected.

Modification:

- When no delimiter is found, compute the longest suffix of the buffer
that is the beginning of a delimiter, and don't count or skip it. This
check only runs when no delimiter was found. It compares at most
`delimiter length - 1` bytes per delimiter, next to the existing search
of the whole buffer.
- New tests in `DelimiterBasedFrameDecoderTest`:
- a frame of `maxFrameLength` bytes with its delimiter split across
reads;
- a delimiter split across reads while discarding, with and without
`failFast`;
  - `maxFrameLength` is still enforced when the delimiter is split.

Result:

Frames are not lost when a multi-byte delimiter is split across reads.
The limit is still exact: the branch that finds the delimiter checks it
as before.

---------

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Oct 19, 2026
Port 5.0: Don't lose frames when a delimiter is split across reads (#17911) #17917
Merged
normanmaurer added a commit that referenced this pull request Oct 19, 2026
@normanmaurer @netty-project-bot @allthingssecurity
Port 5.0: Don't lose frames when a delimiter is split across reads (#…
a65bcf8
…17911) (#17917)

Auto-port of #17665 to 5.0
Cherry-picked commit: 07aed99

---
Motivation:

When `DelimiterBasedFrameDecoder` finds no delimiter in the buffer, it
counts all readable bytes as frame content and, while discarding a too
long frame, skips all of them. That includes a trailing partial
delimiter whose remaining bytes are in the next read. With a multi-byte
delimiter, this loses frames. In both examples below the delimiter is
`##` and `maxFrameLength` is 4:

- While a too long frame is discarded, the first bytes of the delimiter
that ends it are thrown away. The delimiter is never seen, so discarding
continues through the next valid frame, which is lost silently. For
example, `AAAAAAAAAA#` then `#ok##next##` gives `TooLongFrameException,
next`: the `ok` frame is lost. With `failFast = false`, the two frames
are also reported as a single exception.
- A frame of up to `maxFrameLength` bytes is rejected when a read ends
inside its delimiter, because the partial delimiter is counted. For
example, `ABCD#` then `#ok##` gives only `TooLongFrameException`: `ABCD`
is lost, and `ok` too (by the first case).

Single-byte delimiters, and line delimiters (which are handled by
`LineBasedFrameDecoder`), are not affected.

Modification:

- When no delimiter is found, compute the longest suffix of the buffer
that is the beginning of a delimiter, and don't count or skip it. This
check only runs when no delimiter was found. It compares at most
`delimiter length - 1` bytes per delimiter, next to the existing search
of the whole buffer.
- New tests in `DelimiterBasedFrameDecoderTest`:
- a frame of `maxFrameLength` bytes with its delimiter split across
reads;
- a delimiter split across reads while discarding, with and without
`failFast`;
  - `maxFrameLength` is still enforced when the delimiter is split.

Result:

Frames are not lost when a multi-byte delimiter is split across reads.
The limit is still exact: the branch that finds the delimiter checks it
as before.

---------

Co-authored-by: allthingssecurity
<[email protected]>
Co-authored-by: Norman Maurer <[email protected]>

---------

Co-authored-by: Netty Project Bot <[email protected]>
Co-authored-by: allthingssecurity <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @allthingssecurity
@normanmaurer @lltopk
Auto-port 4.1: Don't lose frames when a delimiter is split across rea…
686f015
…ds (netty#17909)

Auto-port of netty#17665 to 4.1
Cherry-picked commit: 07aed99

---
Motivation:

When `DelimiterBasedFrameDecoder` finds no delimiter in the buffer, it
counts all readable bytes as frame content and, while discarding a too
long frame, skips all of them. That includes a trailing partial
delimiter whose remaining bytes are in the next read. With a multi-byte
delimiter, this loses frames. In both examples below the delimiter is
`##` and `maxFrameLength` is 4:

- While a too long frame is discarded, the first bytes of the delimiter
that ends it are thrown away. The delimiter is never seen, so discarding
continues through the next valid frame, which is lost silently. For
example, `AAAAAAAAAA#` then `#ok##next##` gives `TooLongFrameException,
next`: the `ok` frame is lost. With `failFast = false`, the two frames
are also reported as a single exception.
- A frame of up to `maxFrameLength` bytes is rejected when a read ends
inside its delimiter, because the partial delimiter is counted. For
example, `ABCD#` then `#ok##` gives only `TooLongFrameException`: `ABCD`
is lost, and `ok` too (by the first case).

Single-byte delimiters, and line delimiters (which are handled by
`LineBasedFrameDecoder`), are not affected.

Modification:

- When no delimiter is found, compute the longest suffix of the buffer
that is the beginning of a delimiter, and don't count or skip it. This
check only runs when no delimiter was found. It compares at most
`delimiter length - 1` bytes per delimiter, next to the existing search
of the whole buffer.
- New tests in `DelimiterBasedFrameDecoderTest`:
- a frame of `maxFrameLength` bytes with its delimiter split across
reads;
- a delimiter split across reads while discarding, with and without
`failFast`;
  - `maxFrameLength` is still enforced when the delimiter is split.

Result:

Frames are not lost when a multi-byte delimiter is split across reads.
The limit is still exact: the branch that finds the delimiter checks it
as before.

---------

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.20.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@allthingssecurity @netty-project-bot @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.