GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — Don't lose frames when a delimiter is split across reads by allthingssecurity · Pull Request #17665 · netty/netty Conversation
Contributor
Motivation: When
Single-byte delimiters, and line delimiters (which are handled by Modification:
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.
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 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 reactionsMotivation: 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]> 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]>
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
✅ All tests passed ✅🏷️ Commit: 50b9c6e Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Auto-port PR for 4.1: #17909 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Auto-port PR for 5.0: #17911 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
…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]>
…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]>
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.