From f0fc67b3a8643a174215d1e514d25414feb83dcf Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Thu, 1 Oct 2015 03:08:18 -0700 Subject: [PATCH] archive/tar: make Reader.Read errors persistent 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 Run-TryBot: Brad Fitzpatrick --- archive/tar/reader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archive/tar/reader.go b/archive/tar/reader.go index 1f57508..7d05d7d 100644 --- a/archive/tar/reader.go +++ b/archive/tar/reader.go @@ -871,9 +871,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