File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -3500,6 +3500,9 @@ static VALUE
3500
3500
rb_gzfile_eof_p (VALUE obj )
3501
3501
{
3502
3502
struct gzfile * gz = get_gzfile (obj );
3503
+ while (!ZSTREAM_IS_FINISHED (& gz -> z ) && ZSTREAM_BUF_FILLED (& gz -> z ) == 0 ) {
3504
+ gzfile_read_more (gz , Qnil );
3505
+ }
3503
3506
return GZFILE_IS_FINISHED (gz ) ? Qtrue : Qfalse ;
3504
3507
}
3505
3508
Original file line number Diff line number Diff line change @@ -1205,6 +1205,38 @@ def test_double_close
1205
1205
}
1206
1206
end
1207
1207
1208
+ # Various methods of Zlib::GzipReader failed when to reading files
1209
+ # just a few bytes larger than GZFILE_READ_SIZE.
1210
+ def test_gzfile_read_size_boundary
1211
+ Tempfile . create ( "test_zlib_gzip_read_size_boundary" ) { |t |
1212
+ t . close
1213
+ # NO_COMPRESSION helps with recreating the error condition.
1214
+ # The error happens on compressed files too, but it's harder to reproduce.
1215
+ # For example, ~12750 bytes are needed to trigger the error using __FILE__.
1216
+ # We avoid this because the test file will change over time.
1217
+ Zlib ::GzipWriter . open ( t . path , Zlib ::NO_COMPRESSION ) do |gz |
1218
+ gz . print ( "\n " * 2024 ) # range from 2024 to 2033 triggers the error
1219
+ gz . flush
1220
+ end
1221
+
1222
+ Zlib ::GzipReader . open ( t . path ) do |f |
1223
+ f . readpartial ( 1024 ) until f . eof?
1224
+ assert_raise ( EOFError ) { f . readpartial ( 1 ) }
1225
+ end
1226
+
1227
+ Zlib ::GzipReader . open ( t . path ) do |f |
1228
+ f . readline until f . eof?
1229
+ assert_raise ( EOFError ) { f . readline }
1230
+ end
1231
+
1232
+ Zlib ::GzipReader . open ( t . path ) do |f |
1233
+ b = f . readbyte until f . eof?
1234
+ f . ungetbyte ( b )
1235
+ f . readbyte
1236
+ assert_raise ( EOFError ) { f . readbyte }
1237
+ end
1238
+ }
1239
+ end
1208
1240
end
1209
1241
1210
1242
class TestZlibGzipWriter < Test ::Unit ::TestCase
You can’t perform that action at this time.
0 commit comments