1
0
Fork 0
forked from mirrors/tar-split

Merge pull request #36 from dmcgowan/fix-extra-nil-accounting

archive/tar: fix writing too many raw bytes
This commit is contained in:
Vincent Batts 2016-09-26 18:31:47 -04:00 committed by GitHub
commit 416fa5dcfe
4 changed files with 9 additions and 6 deletions

View file

@ -608,12 +608,12 @@ func (tr *Reader) readHeader() *Header {
header := tr.hdrBuff[:]
copy(header, zeroBlock)
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
if n, err := io.ReadFull(tr.r, header); err != nil {
tr.err = err
// because it could read some of the block, but reach EOF first
if tr.err == io.EOF && tr.RawAccounting {
if _, err := tr.rawBytes.Write(header); err != nil {
if _, err := tr.rawBytes.Write(header[:n]); err != nil {
tr.err = err
return nil
}
}
return nil // io.EOF is okay here
@ -626,11 +626,12 @@ func (tr *Reader) readHeader() *Header {
// Two blocks of zero bytes marks the end of the archive.
if bytes.Equal(header, zeroBlock[0:blockSize]) {
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
if n, err := io.ReadFull(tr.r, header); err != nil {
tr.err = err
// because it could read some of the block, but reach EOF first
if tr.err == io.EOF && tr.RawAccounting {
if _, tr.err = tr.rawBytes.Write(header); tr.err != nil {
return nil
if _, err := tr.rawBytes.Write(header[:n]); err != nil {
tr.err = err
}
}
return nil // io.EOF is okay here

View file

@ -139,6 +139,8 @@ var testCases = []struct {
{"./testdata/longlink.tar.gz", "d9f6babe107b7247953dff6b5b5ae31a3a880add", 20480},
{"./testdata/fatlonglink.tar.gz", "8537f03f89aeef537382f8b0bb065d93e03b0be8", 26234880},
{"./testdata/iso-8859.tar.gz", "ddafa51cb03c74ec117ab366ee2240d13bba1ec3", 10240},
{"./testdata/extranils.tar.gz", "e187b4b3e739deaccc257342f4940f34403dc588", 10648},
{"./testdata/notenoughnils.tar.gz", "72f93f41efd95290baa5c174c234f5d4c22ce601", 512},
}
func TestTarStream(t *testing.T) {

BIN
tar/asm/testdata/extranils.tar.gz vendored Normal file

Binary file not shown.

BIN
tar/asm/testdata/notenoughnils.tar.gz vendored Normal file

Binary file not shown.