mirror of
https://github.com/golang/go
synced 2024-11-18 08:34:44 -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:
parent
549ca046ff
commit
0b84a64da1
@ -175,11 +175,14 @@ loop:
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dsnet): The extended headers may have updated the size.
|
// The extended headers may have updated the size.
|
||||||
// Thus, we must setup the regFileReader again here.
|
// Thus, setup the regFileReader again after merging PAX headers.
|
||||||
//
|
if err := tr.handleRegularFile(hdr); err != nil {
|
||||||
// See golang.org/issue/15573
|
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 {
|
if err := tr.handleSparseFile(hdr, rawHdr, extHdrs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -237,6 +237,23 @@ var untarTests = []*untarTest{
|
|||||||
file: "testdata/pax-bad-mtime-file.tar",
|
file: "testdata/pax-bad-mtime-file.tar",
|
||||||
err: ErrHeader,
|
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
|
file: "testdata/nil-uid.tar", // golang.org/issue/5290
|
||||||
headers: []*Header{
|
headers: []*Header{
|
||||||
|
BIN
src/archive/tar/testdata/pax-pos-size-file.tar
vendored
Normal file
BIN
src/archive/tar/testdata/pax-pos-size-file.tar
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user