fix: don't truncate decompressed packets that expand more than 2x - #750
Merged
Conversation
Decompress::decompress checked its loop-exit conditions using progress counters read before the current inflate call, so a drain call that filled the output buffer exactly broke out of the loop with data still pending inside zlib. The packet came back short and the leftover bytes desynced the stream for every later packet. Read the counters after the call instead, and add a regression test that round-trips partial-flush packets on a continuous stream - the shape real SSH traffic has, which the existing finished-stream tests don't cover. Fixes Eugeny#749
Owner
|
Thanks! @all-contributors add @luizribeiro for code |
Contributor
|
I've put up a pull request to add @luizribeiro! 🎉 |
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.
Fixes #749.
Decompress::decompresschecked its loop-exit conditions using progress counters read before the current inflate call. A drain call that filled the output buffer exactly would break out of the loop with data still pending inside zlib: the packet came back short, and the leftover bytes corrupted the stream for every later packet. Any packet compressing better than 2:1 hit this, which killed every compressed session (e.g. OpenSSH clients withCompression yes).This reads the counters after the call instead, and adds a regression test that round-trips partial-flush packets on a continuous stream — the shape real SSH traffic has, which the existing finished-stream tests don't cover. The test fails without the fix (
sent 37 bytes, got 36 back) and passes with it; the full suite passes.