Commit 30f8f28
Auto-port 4.1: Fix MQTT decoder size check after variable header replay (#16838)
Auto-port of #16787 to 4.1
Cherry-picked commit: 72df658
---
## Problem
The MQTT decoder can reject valid packets after the CVE-2026-44248 fix
when several MQTT packets are present in the same cumulation buffer. If
the current packet's variable header needs a replay, the decoder
compares the total readable bytes in the buffer against
`maxBytesInMessage`, so later packets can make the current in-limit
packet look too large.
## Root Cause
`READ_VARIABLE_HEADER` recorded `buffer.readableBytes()` before decoding
the variable header. That value is the cumulation's total readable
bytes, not the current MQTT packet's declared remaining length. When
`decodeVariableHeader` throws `Signal.REPLAY`, the too-large decision
must be based on `bytesRemainingBeforeVariableHeader` for the current
packet.
## Fix
- Use `bytesRemainingBeforeVariableHeader` when deciding whether to
swallow `Signal.REPLAY` and raise `TooLongFrameException`.
- Continue replaying when the current packet is within
`maxBytesInMessage`, even if the cumulation contains additional bytes
for following packets.
## Tests Added
| Change Point | Test |
|-------------|------|
| Variable-header replay uses the current packet size instead of total
cumulation bytes for the too-long check |
`testPublishMessageIncompleteVariableHeaderDoesNotUseCumulationSizeForTooLongCheck()`
verifies an incomplete in-limit PUBLISH variable header with extra
cumulated PINGREQ packets does not emit an invalid message |
| Oversized current packets still fail during variable-header replay |
`testPublishMessageIncompleteVariableHeaderStillFailsWhenCurrentPacketTooLarge()`
verifies an incomplete PUBLISH whose own remaining length exceeds
`maxBytesInMessage` still emits a `TooLongFrameException` |
## Impact
This restores decoding for valid in-limit MQTT packets batched in the
same buffer while preserving the CVE fix: packets whose declared
remaining length exceeds `maxBytesInMessage` still fail with
`TooLongFrameException` even if variable-header decoding requests
replay.
Fixes #16776
Co-authored-by: Guimu <30684111+daguimu@users.noreply.github.com>1 parent 4c1cb1d commit 30f8f28
2 files changed
Lines changed: 77 additions & 5 deletions
File tree
- codec-mqtt/src
- main/java/io/netty/handler/codec/mqtt
- test/java/io/netty/handler/codec/mqtt
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 104 | + | |
109 | 105 | | |
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
| |||
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
314 | 387 | | |
315 | 388 | | |
316 | 389 | | |
| |||
0 commit comments