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
6 changes: 5 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,12 @@ static VALUE
rb_zstream_set_avail_out(VALUE obj, VALUE size)
{
struct zstream *z = get_zstream(obj);
int n = NUM2INT(size);

zstream_expand_buffer_into(z, FIX2INT(size));
if (n < 0) {
rb_raise(rb_eArgError, "negative size");
}
zstream_expand_buffer_into(z, n);
return size;
}

Expand Down
8 changes: 8 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def test_avail
assert_equal("foobar", Zlib::Inflate.inflate(s))
end

def test_negative_avail_out
z = Zlib::Inflate.new
assert_raise(ArgumentError) { z.avail_out = -1 }
assert_equal("foo" * 100, z.inflate(Zlib::Deflate.deflate("foo" * 100)))
ensure
z&.close
end

def test_expand_buffer;
z = Zlib::Deflate.new
src = "baz" * 1000
Expand Down
Loading