mirror of
https://github.com/golang/go
synced 2024-09-30 04:34:33 -06:00
archive/tar: skip NUL-filled unused octal fields
Fixes #5290. R=golang-dev, dave, bradfitz, r CC=golang-dev https://golang.org/cl/8763044
This commit is contained in:
parent
392cebea5d
commit
9c94580921
@ -243,13 +243,15 @@ func (tr *Reader) octal(b []byte) int64 {
|
||||
return x
|
||||
}
|
||||
|
||||
// Removing leading spaces.
|
||||
for len(b) > 0 && b[0] == ' ' {
|
||||
b = b[1:]
|
||||
}
|
||||
// Removing trailing NULs and spaces.
|
||||
for len(b) > 0 && (b[len(b)-1] == ' ' || b[len(b)-1] == '\x00') {
|
||||
b = b[0 : len(b)-1]
|
||||
// Because unused fields are filled with NULs, we need
|
||||
// to skip leading NULs. Fields may also be padded with
|
||||
// spaces or NULs.
|
||||
// So we remove leading and trailing NULs and spaces to
|
||||
// be sure.
|
||||
b = bytes.Trim(b, " \x00")
|
||||
|
||||
if len(b) == 0 {
|
||||
return 0
|
||||
}
|
||||
x, err := strconv.ParseUint(cString(b), 8, 64)
|
||||
if err != nil {
|
||||
|
@ -142,6 +142,25 @@ var untarTests = []*untarTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
file: "testdata/nil-uid.tar", // golang.org/issue/5290
|
||||
headers: []*Header{
|
||||
{
|
||||
Name: "P1050238.JPG.log",
|
||||
Mode: 0664,
|
||||
Uid: 0,
|
||||
Gid: 0,
|
||||
Size: 14,
|
||||
ModTime: time.Unix(1365454838, 0),
|
||||
Typeflag: TypeReg,
|
||||
Linkname: "",
|
||||
Uname: "eyefi",
|
||||
Gname: "eyefi",
|
||||
Devmajor: 0,
|
||||
Devminor: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestReader(t *testing.T) {
|
||||
|
BIN
src/pkg/archive/tar/testdata/nil-uid.tar
vendored
Normal file
BIN
src/pkg/archive/tar/testdata/nil-uid.tar
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user