Repository navigation
Raise InProgressError from other methods while the stream is running - #207
Merged
Merged
Conversation
Only #inflate, #deflate and the methods that run the stream checked
ZSTREAM_IN_PROGRESS. The others could change the zlib state or the
output buffer while another thread was running zlib without the GVL,
or from the block of #inflate/#deflate.
zd = Zlib::Deflate.new
Thread.new { sleep 0.1; zd.close }
zd.deflate(Random.bytes(50_000_000), Zlib::FINISH)
#=> [BUG] Segmentation fault at 0x0000000000000000
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GzipFile methods did not check ZSTREAM_IN_PROGRESS either, so another
thread could close the stream or replace its buffer while zlib was
running without the GVL.
gz = Zlib::GzipWriter.new(StringIO.new)
q = Thread::Queue.new
Thread.new { q.pop; gz.close }
gz.write("x")
q << true
gz.write(Random.bytes(10_000_000))
#=> can't modify frozen NilClass: nil (FrozenError)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mame
force-pushed
the
zlib-in-progress-checks
branch
from
December 2, 2026 02:52
5e9de79 to
4daca17
Compare
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.
Only
#inflate,#deflateand the methods that run the stream checkedZSTREAM_IN_PROGRESS. The others, such as#close,#reset,#flush_next_out,#avail_out=,Deflate#paramsand theGzipFilemethods, could change the zlib state or the output buffer while another thread was running zlib without the GVL, or from the block of#inflate/#deflate.This adds the same check to them, as #168 did for
Inflate#sync.