Commit 7733a7ca authored by Michael Gehring's avatar Michael Gehring Committed by Russ Cox

archive/tar: add missing error checks

Check for errors when reading the headers following the pax headers.

Fixes #11169.

Change-Id: Ifec4a949ec8df8b49fa7cb7a67eb826fe2282ad8
Reviewed-on: https://go-review.googlesource.com/11031Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 1b269463
...@@ -110,7 +110,13 @@ func (tr *Reader) Next() (*Header, error) { ...@@ -110,7 +110,13 @@ func (tr *Reader) Next() (*Header, error) {
// We actually read the whole file, // We actually read the whole file,
// but this skips alignment padding // but this skips alignment padding
tr.skipUnread() tr.skipUnread()
if tr.err != nil {
return nil, tr.err
}
hdr = tr.readHeader() hdr = tr.readHeader()
if hdr == nil {
return nil, tr.err
}
mergePAX(hdr, headers) mergePAX(hdr, headers)
// Check for a PAX format sparse file // Check for a PAX format sparse file
......
...@@ -781,3 +781,18 @@ func TestIssue10968(t *testing.T) { ...@@ -781,3 +781,18 @@ func TestIssue10968(t *testing.T) {
t.Fatalf("expected %q, got %q", io.ErrUnexpectedEOF, err) t.Fatalf("expected %q, got %q", io.ErrUnexpectedEOF, err)
} }
} }
// Do not panic if there are errors in header blocks after the pax header.
// Issue 11169
func TestIssue11169(t *testing.T) {
f, err := os.Open("testdata/issue11169.tar")
if err != nil {
t.Fatal(err)
}
defer f.Close()
r := NewReader(f)
_, err = r.Next()
if err == nil {
t.Fatal("Unexpected success")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment