1
0
mirror of https://github.com/golang/go synced 2024-09-30 06:24: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:
Shenghou Ma 2013-05-15 04:40:42 +08:00
parent 392cebea5d
commit 9c94580921
3 changed files with 28 additions and 7 deletions

View File

@ -243,13 +243,15 @@ func (tr *Reader) octal(b []byte) int64 {
return x return x
} }
// Removing leading spaces. // Because unused fields are filled with NULs, we need
for len(b) > 0 && b[0] == ' ' { // to skip leading NULs. Fields may also be padded with
b = b[1:] // spaces or NULs.
} // So we remove leading and trailing NULs and spaces to
// Removing trailing NULs and spaces. // be sure.
for len(b) > 0 && (b[len(b)-1] == ' ' || b[len(b)-1] == '\x00') { b = bytes.Trim(b, " \x00")
b = b[0 : len(b)-1]
if len(b) == 0 {
return 0
} }
x, err := strconv.ParseUint(cString(b), 8, 64) x, err := strconv.ParseUint(cString(b), 8, 64)
if err != nil { if err != nil {

View File

@ -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) { func TestReader(t *testing.T) {

BIN
src/pkg/archive/tar/testdata/nil-uid.tar vendored Normal file

Binary file not shown.