Skip to content

fix: don't truncate decompressed packets that expand more than 2x - #750

Merged
Eugeny merged 1 commit into
Eugeny:mainfrom
luizribeiro:fix-decompress-truncation
Aug 17, 2026
Merged

fix: don't truncate decompressed packets that expand more than 2x#750
Eugeny merged 1 commit into
Eugeny:mainfrom
luizribeiro:fix-decompress-truncation

Conversation

@luizribeiro

Copy link
Copy Markdown
Contributor

Fixes #749.

Decompress::decompress checked 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 with Compression 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.

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
@Eugeny

Eugeny commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Thanks! @all-contributors add @luizribeiro for code

@allcontributors

Copy link
Copy Markdown
Contributor

@Eugeny

I've put up a pull request to add @luizribeiro! 🎉

@Eugeny
Eugeny merged commit 58886f4 into Eugeny:main Aug 17, 2026
11 checks passed
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.

zlib decompression truncates packets

2 participants