1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 59333,59337: [Backport #13616]

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]
	zlib.c: fix unnormalized Fixnum

	* ext/zlib/zlib.c (rb_gzfile_total_out): cast to long not to
	  result in an unsigned long to normalized to Fixnum on LLP64
	  platforms.  [ruby-core:81488]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2017-08-09 08:08:01 +00:00
parent 640e708dee
commit f4a8004e31
3 changed files with 21 additions and 2 deletions

View file

@ -3407,7 +3407,14 @@ static VALUE
rb_gzfile_total_out(VALUE obj) rb_gzfile_total_out(VALUE obj)
{ {
struct gzfile *gz = get_gzfile(obj); struct gzfile *gz = get_gzfile(obj);
return rb_uint2inum(gz->z.stream.total_out - gz->z.buf_filled); uLong total_out = gz->z.stream.total_out;
long buf_filled = gz->z.buf_filled;
if (total_out >= (uLong)buf_filled) {
return rb_uint2inum(total_out - buf_filled);
} else {
return LONG2FIX(-(buf_filled - (long)total_out));
}
} }
/* /*

View file

@ -650,6 +650,18 @@ if defined? Zlib
} }
end 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 def test_open
Tempfile.create("test_zlib_gzip_reader_open") {|t| Tempfile.create("test_zlib_gzip_reader_open") {|t|
t.close t.close

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.5" #define RUBY_VERSION "2.3.5"
#define RUBY_RELEASE_DATE "2017-08-09" #define RUBY_RELEASE_DATE "2017-08-09"
#define RUBY_PATCHLEVEL 344 #define RUBY_PATCHLEVEL 345
#define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 8 #define RUBY_RELEASE_MONTH 8