aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-14 09:17:55 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-14 09:17:55 +0000
commit60519093e20aca11b205245f817fbc2a4cc2c3a5 (patch)
tree04cf52e468e9c6fdfb44821c86437552584d78db /ext
parent48e2f75b3f38ef0631c302f25448c582c20e793e (diff)
downloadruby-60519093e20aca11b205245f817fbc2a4cc2c3a5.tar.gz
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
Diffstat (limited to 'ext')
-rw-r--r--ext/zlib/zlib.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index bc1b47c221..ce1139dc5d 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -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));
+ }
}
/*