1
0
mirror of https://github.com/golang/go synced 2024-11-20 07:04:40 -07:00

archive/tar: accept binary format when reading numeric header fields.

Fixes #4358.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6840043
This commit is contained in:
David Symonds 2012-11-09 08:50:10 +11:00
parent 761830f481
commit 86b9e3e2b4
2 changed files with 13 additions and 0 deletions

View File

@ -72,6 +72,18 @@ func cString(b []byte) string {
}
func (tr *Reader) octal(b []byte) int64 {
// Check for binary format first.
if len(b) > 0 && b[0]&0x80 != 0 {
var x int64
for i, c := range b {
if i == 0 {
c &= 0x7f // ignore signal bit in first byte
}
x = x<<8 | int64(c)
}
return x
}
// Removing leading spaces.
for len(b) > 0 && b[0] == ' ' {
b = b[1:]

View File

@ -65,6 +65,7 @@ func TestRoundTrip(t *testing.T) {
tw := NewWriter(&b)
hdr := &Header{
Name: "file.txt",
Uid: 1 << 21, // too big for 8 octal digits
Size: int64(len(data)),
ModTime: time.Now(),
}