websocket: fix PMD end-of-message tail partial consumption (permessage-deflate)#1
Open
shinny-yangyang wants to merge 1 commit intodevelopfrom
Open
websocket: fix PMD end-of-message tail partial consumption (permessage-deflate)#1shinny-yangyang wants to merge 1 commit intodevelopfrom
shinny-yangyang wants to merge 1 commit intodevelopfrom
Conversation
…use: when finishing a permessage-deflate (PMD) message, Beast always appended the 4-byte RFC7692 tail (00 00 FF FF) but did not track how many of those bytes zlib had consumed. With very small avail_out (e.g. 1 byte), zlib could consume only part of the tail and the next iteration would re-append from the beginning, corrupting the stored block length and producing "invalid stored block length".\n\nFix: track per-message tail consumption (0..4) and only feed the remaining portion of the tail. After all 4 bytes are consumed, continue calling inflate with avail_in=0 to naturally finish. Reset the counter on new messages and at context takeover boundaries. Also treat zlib::error::need_buffers as non-fatal in the inflate wrapper.\n\nChanges:\n- impl_base.hpp (deflateSupported=true): add pmd_type::rd_tail_in, reset in rd_deflated() and do_context_takeover_read(); add rd_tail_in()/rd_tail_in_add() helpers; clear need_buffers in inflate().\n- impl_base.hpp (deflateSupported=false): add no-op stubs for rd_tail_in helpers.\n- read.hpp: in both async and sync read paths, append only the unconsumed tail bytes, accumulate consumed bytes from zs.total_in, and finish the message when fin && zs.total_out == 0.\n- example: add repro CMake target (repro/), with server_pmd_writer and client_smallbuf to reproduce and validate the fix.\n\nValidation: repro shows stable reception with 1-byte reads and no inflate errors; 200 messages received cleanly and stream closes gracefully.
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.
Root cause
Fix
Changes
Validation
Compatibility