Skip to content

Commit

Permalink
archive/tar: add missing error checks
Browse files Browse the repository at this point in the history
Check for errors when reading the headers following the pax headers.

Fixes #11169.

Change-Id: Ifec4a949ec8df8b49fa7cb7a67eb826fe2282ad8
Reviewed-on: https://go-review.googlesource.com/11031
Reviewed-by: Russ Cox <rsc@golang.org>
  • Loading branch information
ebfe authored and rsc committed Jun 18, 2015
1 parent 1b26946 commit 7733a7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/archive/tar/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ func (tr *Reader) Next() (*Header, error) {
// We actually read the whole file,
// but this skips alignment padding
tr.skipUnread()
if tr.err != nil {
return nil, tr.err
}
hdr = tr.readHeader()
if hdr == nil {
return nil, tr.err
}
mergePAX(hdr, headers)

// Check for a PAX format sparse file
Expand Down
15 changes: 15 additions & 0 deletions src/archive/tar/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,18 @@ func TestIssue10968(t *testing.T) {
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")
}
}
Binary file added src/archive/tar/testdata/issue11169.tar
Binary file not shown.

0 comments on commit 7733a7c

Please sign in to comment.