mirror of
https://github.com/vbatts/tar-split.git
synced 2024-12-19 11:56:30 +00:00
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:
parent
7410961e75
commit
6b59e6942e
1 changed files with 7 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue