Repository navigation
ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete - #17550
Merged
Merged
Conversation
…prefix is incomplete Motivation: Since netty#14050 two incomplete length prefix cases are no longer treated as "need more data" by `ProtobufVarint32FrameDecoder`: - If only 3 bytes are readable and all of them have the continuation bit set, `readRawVarint24` returned the partial value and left the readerIndex advanced. `decode()` then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception. - If exactly 4 bytes are readable and all of them have the continuation bit set, `readRawVarint40` threw a `CorruptedFrameException` although the fifth byte may simply not have been received yet. Before netty#14050 both cases reset the readerIndex and returned 0. Modifications: - `readRawVarint24` resets the readerIndex and returns 0 when the third byte still has the continuation bit set. - `readRawVarint40` returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed. - Add tests that split 1 to 5 byte length prefixes at every position, including lengths that are exact multiples of 2 MiB. Result: `ProtobufVarint32FrameDecoder` produces the same frames regardless of how the length prefix is fragmented across reads. Fixes netty#17549.
🚨 TestLens detected 2 failed tests 🚨Here is what you can do:
Test SummaryBuild PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: cc73fce Test FailuresKQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)Rerun ControlsNote Checks are currently running using the configuration below. Select tests to mute in this pull request: 🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo) Reuse successful test results: 🔲 ♻️ Only rerun the tests that failed or were muted before Click the checkbox to trigger a rerun: 🔲 Rerun jobs Learn more about TestLens at testlens.app/docs. |
Contributor
|
Auto-port PR for 4.1: #17553 |
Contributor
|
Auto-port PR for 5.0: #17554 |
normanmaurer
added a commit
that referenced
this pull request
Sep 20, 2026
…hen the length prefix is incomplete (#17553) Auto-port of #17550 to 4.1 Cherry-picked commit: 335aed7 --- Motivation: Since #14050 two incomplete length prefix cases are no longer treated as "need more data" by `ProtobufVarint32FrameDecoder`: - If only 3 bytes are readable and all of them have the continuation bit set, `readRawVarint24` returned the partial value and left the readerIndex advanced. `decode()` then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception. - If exactly 4 bytes are readable and all of them have the continuation bit set, `readRawVarint40` threw a `CorruptedFrameException` although the fifth byte may simply not have been received yet. Before #14050 both cases reset the readerIndex and returned 0. Modifications: - `readRawVarint24` resets the readerIndex and returns 0 when the third byte still has the continuation bit set. - `readRawVarint40` returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed. - Add tests that split 1 to 5 byte length prefixes at every position, including lengths that are exact multiples of 2 MiB. Result: `ProtobufVarint32FrameDecoder` produces the same frames regardless of how the length prefix is fragmented across reads. Fixes #17549. --------- Co-authored-by: 오규찬 (B팀 서버) <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
normanmaurer
added a commit
that referenced
this pull request
Sep 20, 2026
…hen the length prefix is incomplete (#17554) Auto-port of #17550 to 5.0 Cherry-picked commit: 335aed7 --- Motivation: Since #14050 two incomplete length prefix cases are no longer treated as "need more data" by `ProtobufVarint32FrameDecoder`: - If only 3 bytes are readable and all of them have the continuation bit set, `readRawVarint24` returned the partial value and left the readerIndex advanced. `decode()` then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception. - If exactly 4 bytes are readable and all of them have the continuation bit set, `readRawVarint40` threw a `CorruptedFrameException` although the fifth byte may simply not have been received yet. Before #14050 both cases reset the readerIndex and returned 0. Modifications: - `readRawVarint24` resets the readerIndex and returns 0 when the third byte still has the continuation bit set. - `readRawVarint40` returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed. - Add tests that split 1 to 5 byte length prefixes at every position, including lengths that are exact multiples of 2 MiB. Result: `ProtobufVarint32FrameDecoder` produces the same frames regardless of how the length prefix is fragmented across reads. Fixes #17549. --------- Co-authored-by: 오규찬 (B팀 서버) <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
Oct 24, 2026
…hen the length prefix is incomplete (netty#17553) Auto-port of netty#17550 to 4.1 Cherry-picked commit: 335aed7 --- Motivation: Since netty#14050 two incomplete length prefix cases are no longer treated as "need more data" by `ProtobufVarint32FrameDecoder`: - If only 3 bytes are readable and all of them have the continuation bit set, `readRawVarint24` returned the partial value and left the readerIndex advanced. `decode()` then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception. - If exactly 4 bytes are readable and all of them have the continuation bit set, `readRawVarint40` threw a `CorruptedFrameException` although the fifth byte may simply not have been received yet. Before netty#14050 both cases reset the readerIndex and returned 0. Modifications: - `readRawVarint24` resets the readerIndex and returns 0 when the third byte still has the continuation bit set. - `readRawVarint40` returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed. - Add tests that split 1 to 5 byte length prefixes at every position, including lengths that are exact multiples of 2 MiB. Result: `ProtobufVarint32FrameDecoder` produces the same frames regardless of how the length prefix is fragmented across reads. Fixes netty#17549. --------- Co-authored-by: 오규찬 (B팀 서버) <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation:
Since #14050 two incomplete length prefix cases are no longer treated as "need more data" by
ProtobufVarint32FrameDecoder:readRawVarint24returned the partial value and left the readerIndex advanced.decode()then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception.readRawVarint40threw aCorruptedFrameExceptionalthough the fifth byte may simply not have been received yet.Before #14050 both cases reset the readerIndex and returned 0.
Modifications:
readRawVarint24resets the readerIndex and returns 0 when the third byte still has the continuation bit set.readRawVarint40returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed.Result:
ProtobufVarint32FrameDecoderproduces the same framesregardless of how the length prefix is fragmented across reads.
Fixes #17549.