summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-09 08:08:01 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-09 08:08:01 +0000
commitf4a8004e315bb33017ba9d432fa78b3b605e70b0 (patch)
tree5844a737a871ca347cc6cefbe4c8efd88b1d0af5
parent640e708deeb97ba55785299cae0259f4f080a96d (diff)
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
-rw-r--r--ext/zlib/zlib.c9
-rw-r--r--test/zlib/test_zlib.rb12
-rw-r--r--version.h2
3 files changed, 21 insertions, 2 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 25b3e7afab..c7604211bb 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -3407,7 +3407,14 @@ static VALUE
rb_gzfile_total_out(VALUE 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));
+ }
}
/*
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index 0092daf0d9..c8c917cb9c 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -650,6 +650,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
diff --git a/version.h b/version.h
index f47967bb5d..da35261ff3 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.5"
#define RUBY_RELEASE_DATE "2017-08-09"
-#define RUBY_PATCHLEVEL 344
+#define RUBY_PATCHLEVEL 345
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 8