Skip to content

Fix Zlib::Deflate#params after breaking out of #deflate - #172

Open
hsbt wants to merge 2 commits into
masterfrom
claude/strange-driscoll-cc0616
Open

hsbt wants to merge 2 commits into
masterfrom
claude/strange-driscoll-cc0616

Conversation

@hsbt

@hsbt hsbt commented Oct 26, 2026

Copy link
Copy Markdown
Member

After breaking out of the block given to Zlib::Deflate#deflate, Zlib::Deflate#params compresses the input left by the break a second time, so the output no longer inflates to the original.

z = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, 9, 1)
input = Random.new(0).bytes(20000)
out = +""
z.deflate(input) { |chunk| out << chunk; break }
z.params(Zlib::BEST_SPEED, Zlib::DEFAULT_STRATEGY)
out << z.finish
Zlib.inflate(out).bytesize # => 23616, expected 20000

The rest of the input is already kept for the next call, so I clear next_in and avail_in once it is. Zlib::Inflate#inflate("") used the stale avail_in to tell whether such input was left, so it now checks the kept input instead.

Generated with Claude Code

hsbt and others added 2 commits October 26, 2026 13:18
Zlib::Deflate#params after breaking out of the block of #deflate compressed the input left by the break a second time, and the output no longer inflated to the original. Zlib::Inflate#inflate now checks the buffered input instead of avail_in to decide whether an empty string has anything to process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chunked break test does not reach the reset of next_in on the error path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant