Commit 0b84a64d authored by Joe Tsai's avatar Joe Tsai Committed by Joe Tsai

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/28418Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 549ca046
......@@ -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
}
......
......@@ -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{
......
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