From 977580df8cad700339f0463bca29ca4d803bd938 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 1 Nov 2024 16:10:48 +1300 Subject: [PATCH] Don't allow recursive usage. --- ext/zlib/zlib.c | 6 +++--- test/zlib/test_zlib.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 037cd96..2f05e64 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -674,9 +674,7 @@ zstream_expand_buffer(struct zstream *z) rb_obj_reveal(z->buf, rb_cString); } - rb_mutex_unlock(z->mutex); - rb_protect(rb_yield, z->buf, &state); - rb_mutex_lock(z->mutex); + rb_protect(rb_yield, z->buf, &state); if (ZSTREAM_REUSE_BUFFER_P(z)) { rb_str_modify(z->buf); @@ -729,6 +727,7 @@ zstream_expand_buffer_protect(struct zstream *z) return state; } + static int zstream_expand_buffer_non_stream(struct zstream *z) { @@ -1207,6 +1206,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush) .jump_state = 0, .stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(), }; + rb_mutex_lock(z->mutex); rb_ensure(zstream_run_try, (VALUE)&args, zstream_run_ensure, (VALUE)&args); if (args.jump_state) diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 15e5bd8..5a8463a 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -545,7 +545,7 @@ def test_recursive_deflate zd = Zlib::Deflate.new s = SecureRandom.random_bytes(1024**2) - assert_raise(Zlib::InProgressError) do + assert_raise(ThreadError) do zd.deflate(s) do zd.deflate(s) end @@ -563,7 +563,7 @@ def test_recursive_inflate s = Zlib.deflate(SecureRandom.random_bytes(1024**2)) - assert_raise(Zlib::InProgressError) do + assert_raise(ThreadError) do zi.inflate(s) do zi.inflate(s) end