1
0
Fork 0
forked from mirrors/tar-split

tar/asm: check length before adding an entry

This commit is contained in:
Vincent Batts 2015-08-11 15:51:19 -04:00
parent 51b0481d4a
commit df8572a1eb

View file

@ -55,13 +55,15 @@ func NewInputTarStream(r io.Reader, p storage.Packer, fp storage.FilePutter) (io
} }
// even when an EOF is reached, there is often 1024 null bytes on // even when an EOF is reached, there is often 1024 null bytes on
// the end of an archive. Collect them too. // the end of an archive. Collect them too.
_, err := p.AddEntry(storage.Entry{ if b := tr.RawBytes(); len(b) > 0 {
Type: storage.SegmentType, _, err := p.AddEntry(storage.Entry{
Payload: tr.RawBytes(), Type: storage.SegmentType,
}) Payload: b,
if err != nil { })
pW.CloseWithError(err) if err != nil {
return pW.CloseWithError(err)
return
}
} }
break // not return. We need the end of the reader. break // not return. We need the end of the reader.
} }
@ -69,12 +71,15 @@ func NewInputTarStream(r io.Reader, p storage.Packer, fp storage.FilePutter) (io
break // not return. We need the end of the reader. break // not return. We need the end of the reader.
} }
if _, err := p.AddEntry(storage.Entry{ if b := tr.RawBytes(); len(b) > 0 {
Type: storage.SegmentType, _, err := p.AddEntry(storage.Entry{
Payload: tr.RawBytes(), Type: storage.SegmentType,
}); err != nil { Payload: b,
pW.CloseWithError(err) })
return if err != nil {
pW.CloseWithError(err)
return
}
} }
var csum []byte var csum []byte