summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-02-19 15:15:04 +0900
committernagachika <nagachika@ruby-lang.org>2022-02-19 15:15:04 +0900
commit951e1377c18f84b52fbd3aab048da8536a3bbdb0 (patch)
tree308197e522074989cd21cb0f905b29c3de571d7d /test
parent49ed412060f48d3b9343b8b90d73e6fcb02b3354 (diff)
merge revision(s) c51b92c18deb850d2cea3a7c9020db23b364ab72: [Backport #18358]
[ruby/zlib] [Bug #18358] Fix crash in zlib when in progress When Zlib::Inflate#inflate or Zlib::Deflate#deflate is called recursively inside the block, a crash can occur because of an use-after-free bug. https://github.com/ruby/zlib/commit/50fb8a0338 --- ext/zlib/zlib.c | 117 ++++++++++++++++++++++++++++++++----------------- test/zlib/test_zlib.rb | 10 ++++- 2 files changed, 85 insertions(+), 42 deletions(-)
Diffstat (limited to 'test')
-rw-r--r--test/zlib/test_zlib.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index a5fc9056c8..c469d24dfc 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -538,30 +538,36 @@ if defined? Zlib
end
def test_recursive_deflate
+ original_gc_stress = GC.stress
+ GC.stress = true
zd = Zlib::Deflate.new
s = SecureRandom.random_bytes(1024**2)
- assert_raise(Zlib::BufError) do
+ assert_raise(Zlib::InProgressError) do
zd.deflate(s) do
zd.deflate(s)
end
end
ensure
+ GC.stress = original_gc_stress
zd&.finish
zd&.close
end
def test_recursive_inflate
+ original_gc_stress = GC.stress
+ GC.stress = true
zi = Zlib::Inflate.new
s = Zlib.deflate(SecureRandom.random_bytes(1024**2))
- assert_raise(Zlib::DataError) do
+ assert_raise(Zlib::InProgressError) do
zi.inflate(s) do
zi.inflate(s)
end
end
ensure
+ GC.stress = original_gc_stress
zi&.close
end
end