]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: make Reader.Read errors persistent
authorJoe Tsai <joetsai@digital-static.net>
Thu, 1 Oct 2015 10:08:18 +0000 (03:08 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 1 Oct 2015 22:33:33 +0000 (22:33 +0000)
If the stream is in an inconsistent state, it does not make sense
that Reader.Read can be called and possibly succeed.

Change-Id: I9d1c5a1300b2c2b45232188aa7999e350809dcf2
Reviewed-on: https://go-review.googlesource.com/15177
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/archive/tar/reader.go

index e9a6aa350aa2b2ffd6505647ebda94a797150395..67db71540c508ee4ababd1d4f531ff1d2a46935f 100644 (file)
@@ -763,9 +763,13 @@ func (tr *Reader) numBytes() int64 {
 // It returns 0, io.EOF when it reaches the end of that entry,
 // until Next is called to advance to the next entry.
 func (tr *Reader) Read(b []byte) (n int, err error) {
+       if tr.err != nil {
+               return 0, tr.err
+       }
        if tr.curr == nil {
                return 0, io.EOF
        }
+
        n, err = tr.curr.Read(b)
        if err != nil && err != io.EOF {
                tr.err = err