Skip to content

Auto-port 4.1: ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete - #17553

Merged
normanmaurer merged 3 commits into
4.1from
auto-port-pr-17550-to-4.1
Sep 20, 2026
Merged

normanmaurer merged 3 commits into
4.1from
auto-port-pr-17550-to-4.1

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

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.

…prefix is incomplete (#17550)

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.

(cherry picked from commit 335aed7)
@normanmaurer normanmaurer added this to the 4.1.139.Final milestone Sep 20, 2026
@testlens-app

testlens-app Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: b7796de
▶️ Tests: 398695 executed
⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app/docs.

@normanmaurer
normanmaurer merged commit 7375bc7 into 4.1 Sep 20, 2026
19 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17550-to-4.1 branch September 20, 2026 16:54
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants