1
0
Fork 0
forked from mirrors/tar-split

archive/tar: fix writing too many raw bytes

When an EOF is read, only the part of the header buffer which
was read should be accounted for.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2016-09-26 14:01:48 -07:00
parent 7410961e75
commit 6b59e6942e

View file

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