1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2025-07-03 14:58:30 +00:00

archive/tar: make output deterministic

Replaces PID in PaxHeaders with 0.  Sorts PAX header keys before writing
them to the archive.

Fixes #12358

Change-Id: If239f89c85f1c9d9895a253fb06a47ad44960124
Reviewed-on: https://go-review.googlesource.com/13975
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
Matt Layher 2015-08-27 14:52:06 -04:00 committed by Vincent Batts
parent bffda594f7
commit 2424f4e367
5 changed files with 70 additions and 8 deletions

View file

@ -179,6 +179,13 @@ func (tr *Reader) Next() (*Header, error) {
return nil, err
}
if sp != nil {
// Sparse files do not make sense when applied to the special header
// types that never have a data section.
if isHeaderOnlyType(hdr.Typeflag) {
tr.err = ErrHeader
return nil, tr.err
}
// Current file is a PAX format GNU sparse file.
// Set the current file reader to a sparse file reader.
tr.curr, tr.err = newSparseFileReader(tr.curr, sp, hdr.Size)
@ -622,10 +629,6 @@ func (tr *Reader) readHeader() *Header {
hdr.Uid = int(tr.octal(s.next(8)))
hdr.Gid = int(tr.octal(s.next(8)))
hdr.Size = tr.octal(s.next(12))
if hdr.Size < 0 {
tr.err = ErrHeader
return nil
}
hdr.ModTime = time.Unix(tr.octal(s.next(12)), 0)
s.next(8) // chksum
hdr.Typeflag = s.next(1)[0]
@ -676,12 +679,17 @@ func (tr *Reader) readHeader() *Header {
return nil
}
// Maximum value of hdr.Size is 64 GB (12 octal digits),
// so there's no risk of int64 overflowing.
nb := int64(hdr.Size)
tr.pad = -nb & (blockSize - 1) // blockSize is a power of two
nb := hdr.Size
if isHeaderOnlyType(hdr.Typeflag) {
nb = 0
}
if nb < 0 {
tr.err = ErrHeader
return nil
}
// Set the current file reader.
tr.pad = -nb & (blockSize - 1) // blockSize is a power of two
tr.curr = &regFileReader{r: tr.r, nb: nb}
// Check for old GNU sparse format entry.