From 3cee6a22c07abe0c60331b860c9fac3388bb72a1 Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 30 Aug 2014 23:53:28 +0000 Subject: zlib: GzipReader#rewind preserves ZSTREAM_FLAG_GZFILE * ext/zlib/zlib.c (gzfile_reset): preserve ZSTREAM_FLAG_GZFILE [Bug #10101] * test/zlib/test_zlib.rb (test_rewind): test each_byte We must preserve the ZSTREAM_FLAG_GZFILE flag to prevent zstream_detach_buffer from: a) returning Qnil and breaking out of the `each_byte' loop b) yielding a large string to each_byte Note: the test case in bug report takes a long time. I found this bug because I noticed the massive time descrepancy between `each_byte' and `readbyte' loop before this patch. With this patch, `each_byte' and `readbyte' both take very long. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/zlib/zlib.c | 1 + test/zlib/test_zlib.rb | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index c5d168fc37..98ca81e62f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Aug 31 08:46:44 2014 Eric Wong + + * ext/zlib/zlib.c (gzfile_reset): preserve ZSTREAM_FLAG_GZFILE + [Bug #10101] + + * test/zlib/test_zlib.rb (test_rewind): test each_byte + Sat Aug 30 19:22:47 2014 Eric Wong * symbol.c (rb_sym2id): do not return garbage object diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index c253b94d95..223879c2dc 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -2293,6 +2293,7 @@ static void gzfile_reset(struct gzfile *gz) { zstream_reset(&gz->z); + gz->z.flags |= ZSTREAM_FLAG_GZFILE; gz->crc = crc32(0, Z_NULL, 0); gz->lineno = 0; gz->ungetc = 0; diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index f381b2ec0d..a7fa943c7a 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -695,6 +695,11 @@ if defined? Zlib assert_equal("foo", f.read) f.rewind assert_equal("foo", f.read) + + f.rewind + bytes = [] + f.each_byte { |b| bytes << b } + assert_equal "foo".bytes.to_a, bytes, '[Bug #10101]' end open(t.path, "rb") do |f| gz = Zlib::GzipReader.new(f) -- cgit v1.2.3