aboutsummaryrefslogtreecommitdiff
path: root/src/compress/gzip/gunzip.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2016-03-29 23:37:59 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-03-30 11:37:20 +0000
commit152a08c531a3219489136df71a8d75ff9ba3bf06 (patch)
treefa3bbee93ae7027bcd6d3fd04d3bf552d8443e59 /src/compress/gzip/gunzip.go
parent6b97dbf848d1019a9e8195e8914530a2cc518327 (diff)
downloadgo-152a08c531a3219489136df71a8d75ff9ba3bf06.tar.gz
go-152a08c531a3219489136df71a8d75ff9ba3bf06.zip
compress/gzip: fix error handling in Read
The Read logic should not assume that only (0, io.EOF) is returned instead of (n, io.EOF) where n is positive. The fix done here is very similar to the fix to compress/zlib in CL/20292. Change-Id: Icb76258cdcf8cfa386a60bab330fefde46fc071d Reviewed-on: https://go-review.googlesource.com/21308 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.go34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/compress/gzip/gunzip.go b/src/compress/gzip/gunzip.go
index 4a4f19443d..8ab2b5e5ec 100644
--- a/src/compress/gzip/gunzip.go
+++ b/src/compress/gzip/gunzip.go
@@ -262,16 +262,13 @@ func (z *Reader) Read(p []byte) (n int, err error) {
if z.err != nil {
return 0, z.err
}
- if len(p) == 0 {
- return 0, nil
- }
- n, err = z.decompressor.Read(p)
+ n, z.err = z.decompressor.Read(p)
z.digest.Write(p[0:n])
z.size += uint32(n)
- if n != 0 || err != io.EOF {
- z.err = err
- return
+ if z.err != io.EOF {
+ // In the normal case we return here.
+ return n, z.err
}
// Finished file; check checksum + size.
@@ -280,28 +277,31 @@ func (z *Reader) Read(p []byte) (n int, err error) {
err = io.ErrUnexpectedEOF
}
z.err = err
- return 0, err
+ return n, err
}
crc32, isize := get4(z.buf[0:4]), get4(z.buf[4:8])
sum := z.digest.Sum32()
if sum != crc32 || isize != z.size {
z.err = ErrChecksum
- return 0, z.err
+ return n, z.err
}
+ z.digest.Reset()
+ z.size = 0
- // File is ok; is there another?
+ // File is ok; check if there is another.
if !z.multistream {
- return 0, io.EOF
+ return n, io.EOF
}
+ z.err = nil // Remove io.EOF
- if err = z.readHeader(false); err != nil {
- z.err = err
- return
+ if z.err = z.readHeader(false); z.err != nil {
+ return n, z.err
}
- // Yes. Reset and read from it.
- z.digest.Reset()
- z.size = 0
+ // Read from next file, if necessary.
+ if n > 0 {
+ return n, nil
+ }
return z.Read(p)
}