Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,6 @@ zstream_run_try(VALUE value_arg)
int err;
VALUE old_input = Qnil;

/* Cannot start zstream while it is in progress. */
if (z->flags & ZSTREAM_IN_PROGRESS) {
rb_raise(cInProgressError, "zlib stream is in progress");
}
z->flags |= ZSTREAM_IN_PROGRESS;

if (ZSTREAM_REUSE_BUFFER_P(z)) {
Expand Down Expand Up @@ -1254,6 +1250,11 @@ zstream_run(struct zstream *z, Bytef *src, rb_len_t len, int flush)
.stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(),
};

/* Cannot start zstream while it is in progress. */
if (z->flags & ZSTREAM_IN_PROGRESS) {
rb_raise(cInProgressError, "zlib stream is in progress");
}

rb_ensure(zstream_run_try, (VALUE)&args, zstream_run_ensure, (VALUE)&args);
if (args.jump_state)
rb_jump_tag(args.jump_state);
Expand Down
11 changes: 11 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ def test_recursive_deflate
zd&.close
end

def test_in_progress_error_does_not_end_in_progress
zd = Zlib::Deflate.new
s = Random.new(0).bytes(100_000)
zd.deflate(s, Zlib::FINISH) do
assert_raise(Zlib::InProgressError) { zd.flush }
assert_raise(Zlib::InProgressError) { zd << s }
break
end
zd.finish
end

def test_recursive_inflate
original_gc_stress = GC.stress
GC.stress = true
Expand Down
Loading