1
0
mirror of https://github.com/golang/go synced 2024-11-18 06:14:46 -07:00

archive/tar: reapply Header.Size to regFileReader after merging

The use of PAX headers can modify the overall file size, thus the
formerly created regFileReader may be stale.

The relevant PAX specification for this behavior is:
<<<
Any fields in the preceding optional extended header shall override
the associated fields in this header block for this file.
>>>
Where "optional extended header" refers to the preceding PAX header.
Where "this header block" refers to the subsequent USTAR header.

Fixes #15573
Fixes #15564

Change-Id: I83b1c3f05a9ca2d3be38647425ad21a9fe450ee2
Reviewed-on: https://go-review.googlesource.com/28418
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Joe Tsai 2016-09-02 14:37:35 -07:00 committed by Joe Tsai
parent 549ca046ff
commit 0b84a64da1
3 changed files with 24 additions and 4 deletions

View File

@ -175,11 +175,14 @@ loop:
return nil, err
}
// TODO(dsnet): The extended headers may have updated the size.
// Thus, we must setup the regFileReader again here.
//
// See golang.org/issue/15573
// The extended headers may have updated the size.
// Thus, setup the regFileReader again after merging PAX headers.
if err := tr.handleRegularFile(hdr); err != nil {
return nil, err
}
// Sparse formats rely on being able to read from the logical data
// section; there must be a preceding call to handleRegularFile.
if err := tr.handleSparseFile(hdr, rawHdr, extHdrs); err != nil {
return nil, err
}

View File

@ -237,6 +237,23 @@ var untarTests = []*untarTest{
file: "testdata/pax-bad-mtime-file.tar",
err: ErrHeader,
},
{
file: "testdata/pax-pos-size-file.tar",
headers: []*Header{{
Name: "foo",
Mode: 0640,
Uid: 319973,
Gid: 5000,
Size: 999,
ModTime: time.Unix(1442282516, 0),
Typeflag: '0',
Uname: "joetsai",
Gname: "eng",
}},
chksums: []string{
"0afb597b283fe61b5d4879669a350556",
},
},
{
file: "testdata/nil-uid.tar", // golang.org/issue/5290
headers: []*Header{

Binary file not shown.