mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
[ruby/zlib] Raise InProgressError from Zlib::Inflate#sync during inflate
Called from the block of Zlib::Inflate#inflate, #sync pointed next_in at its argument, and the inflate loop kept reading from there after the block returned. https://github.com/ruby/zlib/commit/f7822c93e7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0b5272459c
commit
20a9f1a53d
2 files changed
+17
No files matched your search
@@ -1282,6 +1282,10 @@ zstream_sync(struct zstream *z, Bytef *src, rb_len_t len)
|
||||
/* VALUE rest; */
|
||||
int err;
|
||||
|
||||
if (z->flags & ZSTREAM_IN_PROGRESS) {
|
||||
rb_raise(cInProgressError, "zlib stream is in progress");
|
||||
}
|
||||
|
||||
if (!NIL_P(z->input)) {
|
||||
err = zstream_inflate_sync(z, (Bytef*)RSTRING_PTR(z->input),
|
||||
RSTRING_LEN(z->input));
|
||||
|
||||
@@ -647,6 +647,19 @@ if defined? Zlib
|
||||
assert_equal(true, z.sync("\0" * 100 + s))
|
||||
end
|
||||
|
||||
def test_sync_in_progress
|
||||
src = "x" * 100_000
|
||||
z = Zlib::Inflate.new
|
||||
inflated = "".dup
|
||||
z.inflate(Zlib.deflate(src)) do |chunk|
|
||||
if inflated.empty?
|
||||
assert_raise(Zlib::InProgressError) { z.sync("\0\0\xff\xff".b) }
|
||||
end
|
||||
inflated << chunk
|
||||
end
|
||||
assert_equal src, inflated
|
||||
end
|
||||
|
||||
def test_set_dictionary
|
||||
z = Zlib::Inflate.new
|
||||
assert_raise(Zlib::StreamError) { z.set_dictionary("foo") }
|
||||
|
||||
Reference in new issue
Block a user