Skip to content

Commit 08be08c

Browse files
Add tests based on reproduction code.
1 parent 67f7c81 commit 08be08c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/zlib/test_zlib.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,35 @@ def test_gzfile_read_size_boundary
12661266
end
12671267
}
12681268
end
1269+
1270+
# Test for signal interrupt bug: Z_BUF_ERROR with avail_out > 0
1271+
# This reproduces the issue where thread wakeup during GzipReader operations
1272+
# can cause Z_BUF_ERROR to be raised incorrectly
1273+
def test_thread_wakeup_interrupt
1274+
content = SecureRandom.base64(5000)
1275+
gzipped = Zlib.gzip(content)
1276+
1277+
1000.times do
1278+
thr = Thread.new do
1279+
loop do
1280+
Zlib::GzipReader.new(StringIO.new(gzipped)).read
1281+
end
1282+
end
1283+
1284+
# Wakeup the thread multiple times to trigger interrupts
1285+
10.times do
1286+
thr.wakeup
1287+
Thread.pass
1288+
end
1289+
1290+
# Give thread a moment to process
1291+
sleep 0.001
1292+
1293+
# Clean up
1294+
thr.kill
1295+
thr.join
1296+
end
1297+
end
12691298
end
12701299

12711300
class TestZlibGzipWriter < Test::Unit::TestCase
@@ -1534,5 +1563,34 @@ def test_gunzip_no_memory_leak
15341563
10_000.times {Zlib.gunzip(d)}
15351564
};
15361565
end
1566+
1567+
# Test for signal interrupt bug: Z_BUF_ERROR with avail_out > 0
1568+
# This reproduces the issue where thread wakeup during GzipReader operations
1569+
# can cause Z_BUF_ERROR to be raised incorrectly
1570+
def test_thread_wakeup_interrupt
1571+
content = SecureRandom.base64(5000)
1572+
gzipped = Zlib.gzip(content)
1573+
1574+
1000.times do
1575+
thr = Thread.new do
1576+
loop do
1577+
Zlib::GzipReader.new(StringIO.new(gzipped)).read
1578+
end
1579+
end
1580+
1581+
# Wakeup the thread multiple times to trigger interrupts
1582+
10.times do
1583+
thr.wakeup
1584+
Thread.pass
1585+
end
1586+
1587+
# Give thread a moment to process
1588+
sleep 0.001
1589+
1590+
# Clean up
1591+
thr.kill
1592+
thr.join
1593+
end
1594+
end
15371595
end
15381596
end

0 commit comments

Comments
 (0)