diff options
author | Joe Tsai <joetsai@digital-static.net> | 2016-10-29 12:25:20 -0700 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2016-10-29 23:29:13 +0000 |
commit | b4e714e59efd21f9140a3e8e2b0182c74bfde437 (patch) | |
tree | 4da106798f70a25352410e44ba60e57469b8af39 /src/compress/gzip/gunzip.go | |
parent | 4b130f92d248cfa37dceeb45622d36d9c90331ff (diff) | |
download | go-b4e714e59efd21f9140a3e8e2b0182c74bfde437.tar.gz go-b4e714e59efd21f9140a3e8e2b0182c74bfde437.zip |
compress/gzip: only encode MTIME if it is valid
The GZIP format records the ModTime as an uint32 counting seconds since
the Unix epoch. The zero value is explicitly defined in section 2.3.1
as meaning no timestamp is available.
Currently, the Writer always encodes the ModTime even if it is the zero
time.Time value, which causes the Writer to try and encode the value
-62135596800 into the uint32 MTIME field. This causes an overflow and
results in our GZIP files having MTIME fields indicating a date in 2042-07-13.
We alter the Writer to only encode ModTime if the value does not underflow
the MTIME field (i.e., it is newer than the Unix epoch). We do not attempt
to fix what happens when the timestamp overflows in the year 2106.
We alter the Reader to only decode ModTime if the value is non-zero.
There is no risk of overflowing time.Time when decoding.
Fixes #17663
Change-Id: Ie1b65770c6342cd7b14aeebe10e5a49e6c9eb730
Reviewed-on: https://go-review.googlesource.com/32325
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/compress/gzip/gunzip.go')
-rw-r--r-- | src/compress/gzip/gunzip.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compress/gzip/gunzip.go b/src/compress/gzip/gunzip.go index bc303898b3..8bd750bd8b 100644 --- a/src/compress/gzip/gunzip.go +++ b/src/compress/gzip/gunzip.go @@ -186,7 +186,11 @@ func (z *Reader) readHeader() (hdr Header, err error) { return hdr, ErrHeader } flg := z.buf[3] - hdr.ModTime = time.Unix(int64(le.Uint32(z.buf[4:8])), 0) + if t := int64(le.Uint32(z.buf[4:8])); t > 0 { + // Section 2.3.1, the zero value for MTIME means that the + // modified time is not set. + hdr.ModTime = time.Unix(t, 0) + } // z.buf[8] is XFL and is currently ignored. hdr.OS = z.buf[9] z.digest = crc32.ChecksumIEEE(z.buf[:10]) |