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:
parent
761830f481
commit
86b9e3e2b4
@ -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:]
|
||||
|
@ -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(),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user