Repository navigation
Fix LZ77 window loss across BFINAL-terminated messages (RFC 7692 7.2.2) - #965
Open
arturobernalg wants to merge 1 commit into
Open
arturobernalg wants to merge 1 commit into
arturobernalg wants to merge 1 commit into
Conversation
Member
Author
|
Please @Hsnmohd check |
PR apache#942's mid-stream reset for a BFINAL-terminated block has two gaps. First, reset() without setDictionary() drops the LZ77 window a later block, or a later message under context takeover, is entitled to back-reference (RFC 7692 7.2.2, MUST). Second, a BFINAL message missing the trailing 0x00 octet section 7.2.3.4 requires - a non-conformant sender, but one worth tolerating - leaves only this method's own synthetic sync-flush tail unconsumed; feeding just that into the reset inflater leaves it mid-header, corrupting whatever is decoded next. Residual gap left by apache#942, not a regression: before it, a BFINAL block in either decoder broke the message outright. Fix: a 32 KiB ring buffer (WebSocketSlidingWindow) re-primes the dictionary on each reset; the reset inflater is only fed again when more than the synthetic tail remains. Costs one extra byte-copy per decoded byte; Inflater exposes no other way to track its window. Applied to both decoders (server PerMessageDeflateExtension, client PerMessageDeflate), with unit and E2E coverage for both.
arturobernalg
force-pushed
the
permessage-deflate-bfinal-lz77-window
branch
from
November 25, 2026 10:52
8080bdc to
e712a2e
Compare
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.
Follow-up to #942, which fixed the server read thread spinning forever on a BFINAL-terminated DEFLATE block in permessage-deflate. That fix left two residual gaps in the same code path, not a regression against it (before #942, a BFINAL block broke the message outright on both counts):
reset()withoutsetDictionary()drops the LZ77 window a later block, or a later message under context takeover, is entitled to back-reference. RFC 7692 7.2.2 (MUST): "decompress each new message using the LZ77 sliding window used to process the last compressed message". Reproduced with the RFC's own literal wire vectors (7.2.3.4's BFINAL "Hello" followed by 7.2.3.2's context-takeover "Hello") against a realWebSocketServerand a hand-rolled RFC 6455 client:DataFormatException: invalid distance too far back, connection closed 1002.0x00octet section 7.2.3.4 requires (a non-conformant sender, but one worth tolerating - the typical rawDeflater.finish()) leaves only this method's own synthetic sync-flush tail unconsumed; feeding just that into the reset inflater leaves it mid-header, corrupting whatever is decoded next, independent of any LZ77 window sharing.Fix: a 32 KiB ring buffer (
WebSocketSlidingWindow) re-primes the dictionary on each mid-stream reset; the reset inflater is only fed again when more than the synthetic tail remains. Applied to both decoders (serverPerMessageDeflateExtension, clientPerMessageDeflate).Tested beyond the unit/E2E suite added here: both decoders went through the project's own runnable WebSocket examples (
WebSocketEchoServer/Client, H1.1;WebSocketH2EchoServer/Client, H2 cleartext via RFC 8441 Extended CONNECT) with no regression, plus a probe exercising permessage-deflate with context takeover over H2 specifically (3 consecutive large messages on one connection) - confirmed the H2 path reuses the same extension classes fixed here, not a separate implementation.