зеркало из https://github.com/github/ruby.git
Zlib::GzipReader#pos underflows after calling #ungetbyte or #ungetc at start of file [Bug #13616]
patched by Andrew Haines <andrew@haines.org.nz> [ruby-core:81488] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d893c123f6
Коммит
7c9c2bc1dd
|
@ -3393,7 +3393,14 @@ static VALUE
|
|||
rb_gzfile_total_out(VALUE obj)
|
||||
{
|
||||
struct gzfile *gz = get_gzfile(obj);
|
||||
return rb_uint2inum(gz->z.stream.total_out - ZSTREAM_BUF_FILLED(&gz->z));
|
||||
uLong total_out = gz->z.stream.total_out;
|
||||
long buf_filled = ZSTREAM_BUF_FILLED(&gz->z);
|
||||
|
||||
if (total_out >= (uLong)buf_filled) {
|
||||
return rb_uint2inum(total_out - buf_filled);
|
||||
} else {
|
||||
return LONG2FIX(-(buf_filled - total_out));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -663,6 +663,18 @@ if defined? Zlib
|
|||
}
|
||||
end
|
||||
|
||||
def test_ungetc_at_start_of_file
|
||||
s = "".dup
|
||||
w = Zlib::GzipWriter.new(StringIO.new(s))
|
||||
w << "abc"
|
||||
w.close
|
||||
r = Zlib::GzipReader.new(StringIO.new(s))
|
||||
|
||||
r.ungetc ?!
|
||||
|
||||
assert_equal(-1, r.pos, "[ruby-core:81488][Bug #13616]")
|
||||
end
|
||||
|
||||
def test_open
|
||||
Tempfile.create("test_zlib_gzip_reader_open") {|t|
|
||||
t.close
|
||||
|
|
Загрузка…
Ссылка в новой задаче