vendor: update stdlib archive/tar for go1.19
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
5091f13a5d
commit
721358e0cb
9 changed files with 14 additions and 63 deletions
9
vendor/archive/tar/common.go
vendored
9
vendor/archive/tar/common.go
vendored
|
@ -221,9 +221,11 @@ func (s sparseEntry) endOffset() int64 { return s.Offset + s.Length }
|
|||
// that the file has no data in it, which is rather odd.
|
||||
//
|
||||
// As an example, if the underlying raw file contains the 10-byte data:
|
||||
//
|
||||
// var compactFile = "abcdefgh"
|
||||
//
|
||||
// And the sparse map has the following entries:
|
||||
//
|
||||
// var spd sparseDatas = []sparseEntry{
|
||||
// {Offset: 2, Length: 5}, // Data fragment for 2..6
|
||||
// {Offset: 18, Length: 3}, // Data fragment for 18..20
|
||||
|
@ -235,6 +237,7 @@ func (s sparseEntry) endOffset() int64 { return s.Offset + s.Length }
|
|||
// }
|
||||
//
|
||||
// Then the content of the resulting sparse file with a Header.Size of 25 is:
|
||||
//
|
||||
// var sparseFile = "\x00"*2 + "abcde" + "\x00"*11 + "fgh" + "\x00"*4
|
||||
type (
|
||||
sparseDatas []sparseEntry
|
||||
|
@ -293,9 +296,9 @@ func alignSparseEntries(src []sparseEntry, size int64) []sparseEntry {
|
|||
// The input must have been already validated.
|
||||
//
|
||||
// This function mutates src and returns a normalized map where:
|
||||
// * adjacent fragments are coalesced together
|
||||
// * only the last fragment may be empty
|
||||
// * the endOffset of the last fragment is the total size
|
||||
// - adjacent fragments are coalesced together
|
||||
// - only the last fragment may be empty
|
||||
// - the endOffset of the last fragment is the total size
|
||||
func invertSparseEntries(src []sparseEntry, size int64) []sparseEntry {
|
||||
dst := src[:0]
|
||||
var pre sparseEntry
|
||||
|
|
4
vendor/archive/tar/format.go
vendored
4
vendor/archive/tar/format.go
vendored
|
@ -143,10 +143,6 @@ const (
|
|||
blockSize = 512 // Size of each block in a tar stream
|
||||
nameSize = 100 // Max length of the name field in USTAR format
|
||||
prefixSize = 155 // Max length of the prefix field in USTAR format
|
||||
|
||||
// Max length of a special file (PAX header, GNU long name or link).
|
||||
// This matches the limit used by libarchive.
|
||||
maxSpecialFileSize = 1 << 20
|
||||
)
|
||||
|
||||
// blockPadding computes the number of bytes needed to pad offset up to the
|
||||
|
|
20
vendor/archive/tar/reader.go
vendored
20
vendor/archive/tar/reader.go
vendored
|
@ -103,7 +103,7 @@ func (tr *Reader) next() (*Header, error) {
|
|||
continue // This is a meta header affecting the next header
|
||||
case TypeGNULongName, TypeGNULongLink:
|
||||
format.mayOnlyBe(FormatGNU)
|
||||
realname, err := readSpecialFile(tr)
|
||||
realname, err := io.ReadAll(tr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
|
|||
// parsePAX parses PAX headers.
|
||||
// If an extended header (type 'x') is invalid, ErrHeader is returned
|
||||
func parsePAX(r io.Reader) (map[string]string, error) {
|
||||
buf, err := readSpecialFile(r)
|
||||
buf, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -336,9 +336,9 @@ func parsePAX(r io.Reader) (map[string]string, error) {
|
|||
// header in case further processing is required.
|
||||
//
|
||||
// The err will be set to io.EOF only when one of the following occurs:
|
||||
// * Exactly 0 bytes are read and EOF is hit.
|
||||
// * Exactly 1 block of zeros is read and EOF is hit.
|
||||
// * At least 2 blocks of zeros are read.
|
||||
// - Exactly 0 bytes are read and EOF is hit.
|
||||
// - Exactly 1 block of zeros is read and EOF is hit.
|
||||
// - At least 2 blocks of zeros are read.
|
||||
func (tr *Reader) readHeader() (*Header, *block, error) {
|
||||
// Two blocks of zero bytes marks the end of the archive.
|
||||
if _, err := io.ReadFull(tr.r, tr.blk[:]); err != nil {
|
||||
|
@ -828,16 +828,6 @@ func tryReadFull(r io.Reader, b []byte) (n int, err error) {
|
|||
return n, err
|
||||
}
|
||||
|
||||
// readSpecialFile is like io.ReadAll except it returns
|
||||
// ErrFieldTooLong if more than maxSpecialFileSize is read.
|
||||
func readSpecialFile(r io.Reader) ([]byte, error) {
|
||||
buf, err := io.ReadAll(io.LimitReader(r, maxSpecialFileSize+1))
|
||||
if len(buf) > maxSpecialFileSize {
|
||||
return nil, ErrFieldTooLong
|
||||
}
|
||||
return buf, err
|
||||
}
|
||||
|
||||
// discard skips n bytes in r, reporting an error if unable to do so.
|
||||
func discard(r io.Reader, n int64) error {
|
||||
// If possible, Seek to the last byte before the end of the data section.
|
||||
|
|
11
vendor/archive/tar/reader_test.go
vendored
11
vendor/archive/tar/reader_test.go
vendored
|
@ -6,7 +6,6 @@ package tar
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/bzip2"
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -244,9 +243,6 @@ func TestReader(t *testing.T) {
|
|||
}, {
|
||||
file: "testdata/pax-bad-hdr-file.tar",
|
||||
err: ErrHeader,
|
||||
}, {
|
||||
file: "testdata/pax-bad-hdr-large.tar.bz2",
|
||||
err: ErrFieldTooLong,
|
||||
}, {
|
||||
file: "testdata/pax-bad-mtime-file.tar",
|
||||
err: ErrHeader,
|
||||
|
@ -629,14 +625,9 @@ func TestReader(t *testing.T) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
var fr io.Reader = f
|
||||
if strings.HasSuffix(v.file, ".bz2") {
|
||||
fr = bzip2.NewReader(fr)
|
||||
}
|
||||
|
||||
// Capture all headers and checksums.
|
||||
var (
|
||||
tr = NewReader(fr)
|
||||
tr = NewReader(f)
|
||||
hdrs []*Header
|
||||
chksums []string
|
||||
rdbuf = make([]byte, 8)
|
||||
|
|
2
vendor/archive/tar/stat_unix.go
vendored
2
vendor/archive/tar/stat_unix.go
vendored
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build aix || linux || darwin || dragonfly || freebsd || openbsd || netbsd || solaris
|
||||
//go:build unix
|
||||
|
||||
package tar
|
||||
|
||||
|
|
1
vendor/archive/tar/strconv.go
vendored
1
vendor/archive/tar/strconv.go
vendored
|
@ -306,6 +306,7 @@ func formatPAXRecord(k, v string) (string, error) {
|
|||
|
||||
// validPAXRecord reports whether the key-value pair is valid where each
|
||||
// record is formatted as:
|
||||
//
|
||||
// "%d %s=%s\n" % (size, key, value)
|
||||
//
|
||||
// Keys and values should be UTF-8, but the number of bad writers out there
|
||||
|
|
Binary file not shown.
3
vendor/archive/tar/writer.go
vendored
3
vendor/archive/tar/writer.go
vendored
|
@ -199,9 +199,6 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHdrs map[string]string) error {
|
|||
flag = TypeXHeader
|
||||
}
|
||||
data := buf.String()
|
||||
if len(data) > maxSpecialFileSize {
|
||||
return ErrFieldTooLong
|
||||
}
|
||||
if err := tw.writeRawFile(name, data, flag, FormatPAX); err != nil || isGlobal {
|
||||
return err // Global headers return here
|
||||
}
|
||||
|
|
27
vendor/archive/tar/writer_test.go
vendored
27
vendor/archive/tar/writer_test.go
vendored
|
@ -1004,33 +1004,6 @@ func TestIssue12594(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWriteLongHeader(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
h *Header
|
||||
}{{
|
||||
name: "name too long",
|
||||
h: &Header{Name: strings.Repeat("a", maxSpecialFileSize)},
|
||||
}, {
|
||||
name: "linkname too long",
|
||||
h: &Header{Linkname: strings.Repeat("a", maxSpecialFileSize)},
|
||||
}, {
|
||||
name: "uname too long",
|
||||
h: &Header{Uname: strings.Repeat("a", maxSpecialFileSize)},
|
||||
}, {
|
||||
name: "gname too long",
|
||||
h: &Header{Gname: strings.Repeat("a", maxSpecialFileSize)},
|
||||
}, {
|
||||
name: "PAX header too long",
|
||||
h: &Header{PAXRecords: map[string]string{"GOLANG.x": strings.Repeat("a", maxSpecialFileSize)}},
|
||||
}} {
|
||||
w := NewWriter(io.Discard)
|
||||
if err := w.WriteHeader(test.h); err != ErrFieldTooLong {
|
||||
t.Errorf("%v: w.WriteHeader() = %v, want ErrFieldTooLong", test.name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// testNonEmptyWriter wraps an io.Writer and ensures that
|
||||
// Write is never called with an empty buffer.
|
||||
type testNonEmptyWriter struct{ io.Writer }
|
||||
|
|
Loading…
Reference in a new issue