summaryrefslogtreecommitdiff
path: root/test/zlib
diff options
context:
space:
mode:
authorMartin Emde <martin.emde@gmail.com>2023-12-21 14:11:02 -0800
committergit <svn-admin@ruby-lang.org>2024-02-22 06:42:06 +0000
commit9f8f32bf9f3758ba67dd2afe7e07d9eccb68bbc7 (patch)
tree1e4f0f4b5c5fb70eb523d78e51534eba7be36413 /test/zlib
parent7acc8bbea5f7f61e5154be8adb391f3dd641186c (diff)
[ruby/zlib] In Zlib::GzipReader#eof? check if we're actually at eof
Only consider it eof if we read ahead and something fills the buf. If not, we may only have empty blocks and the footer. Fixes https://github.com/ruby/zlib/pull/56 https://github.com/ruby/zlib/commit/437bea8003
Diffstat (limited to 'test/zlib')
-rw-r--r--test/zlib/test_zlib.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index 779c583424..502ccceec5 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -1205,6 +1205,38 @@ if defined? Zlib
}
end
+ # Various methods of Zlib::GzipReader failed when to reading files
+ # just a few bytes larger than GZFILE_READ_SIZE.
+ def test_gzfile_read_size_boundary
+ Tempfile.create("test_zlib_gzip_read_size_boundary") {|t|
+ t.close
+ # NO_COMPRESSION helps with recreating the error condition.
+ # The error happens on compressed files too, but it's harder to reproduce.
+ # For example, ~12750 bytes are needed to trigger the error using __FILE__.
+ # We avoid this because the test file will change over time.
+ Zlib::GzipWriter.open(t.path, Zlib::NO_COMPRESSION) do |gz|
+ gz.print("\n" * 2024) # range from 2024 to 2033 triggers the error
+ gz.flush
+ end
+
+ Zlib::GzipReader.open(t.path) do |f|
+ f.readpartial(1024) until f.eof?
+ assert_raise(EOFError) { f.readpartial(1) }
+ end
+
+ Zlib::GzipReader.open(t.path) do |f|
+ f.readline until f.eof?
+ assert_raise(EOFError) { f.readline }
+ end
+
+ Zlib::GzipReader.open(t.path) do |f|
+ b = f.readbyte until f.eof?
+ f.ungetbyte(b)
+ f.readbyte
+ assert_raise(EOFError) { f.readbyte }
+ end
+ }
+ end
end
class TestZlibGzipWriter < Test::Unit::TestCase