Skip to content

Raise InProgressError from Zlib::Inflate#sync during inflate - #168

Merged
hsbt merged 2 commits into
masterfrom
claude/inflate-sync-in-progress-10a9a2
Oct 26, 2026
Merged

hsbt merged 2 commits into
masterfrom
claude/inflate-sync-in-progress-10a9a2

Conversation

@hsbt

@hsbt hsbt commented Oct 25, 2026

Copy link
Copy Markdown
Member

Zlib::Inflate#sync did not check whether the stream was in progress. Called from the block of Zlib::Inflate#inflate, it pointed next_in at its argument, and the inflate loop kept reading from there after the block returned, even after the argument was freed.

require "zlib"

z = Zlib::Inflate.new
z.inflate(Zlib.deflate("x" * 400_000)) do
  s = "\0\0\xff\xff".b + "\1".b * 50_000_000
  z.sync(s)
  s.clear
end
#=> [BUG] Segmentation fault (mswin)

It now raises Zlib::InProgressError, as #<< and #finish already do there. The last chunk is yielded after the loop has returned, so #sync from that yield keeps working.

I also fixed the rdoc of #sync, which described the return values the other way around.

Generated with Claude Code

hsbt and others added 2 commits October 25, 2026 07:52
Called from the block of Zlib::Inflate#inflate, #sync pointed next_in at its argument, and the inflate loop kept reading from there after the block returned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It described the return values the other way around, and did not mention Zlib::InProgressError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hsbt
hsbt merged commit 1f052fd into master Oct 26, 2026
60 checks passed
@hsbt
hsbt deleted the claude/inflate-sync-in-progress-10a9a2 branch October 26, 2026 07:29
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