vbatts/tar-split

Empty entry added when no padding at end of file

Closed this issue · 3 comments

I've run into an issue where an empty entry is added when reading a tar stream and I wanted to check if this was expected behaviour or not?

I have a scenario where this read operation

n, err := outputRdr.Read(paddingChunk[:])
is retuning n=0 and err=EOF

In other places in this code you are checking that the length of the payload is greater than 0

if b := tr.RawBytes(); len(b) > 0 {
_, err := p.AddEntry(storage.Entry{
Type: storage.SegmentType,
Payload: b,
})
if err != nil {
pW.CloseWithError(err)
return
}
}

Should this length check also be applied when adding the padding chunk or is adding the empty entry desired?

vbatts commented

thanks for reporting. Do you have a reproducer for this situation?

tianon commented

Ooh, if this is what I think it is (the trailing "EOF" entry), then it might be useful to you that I just recently refactored the layer on tianon/true:oci to not include that (in case you need a very small test case).

vbatts commented

I just tried your layer from that tianon/true:oci image, but it passes right through this code and doesn't hit the issue.

diff --git a/tar/asm/assemble_test.go b/tar/asm/assemble_test.go
index 6cb7850..cfbcca6 100644
--- a/tar/asm/assemble_test.go
+++ b/tar/asm/assemble_test.go
@@ -140,6 +140,7 @@ var testCases = []struct {
        {"./testdata/iso-8859.tar.gz", "ddafa51cb03c74ec117ab366ee2240d13bba1ec3", 10240},
        {"./testdata/extranils.tar.gz", "e187b4b3e739deaccc257342f4940f34403dc588", 10648},
        {"./testdata/notenoughnils.tar.gz", "72f93f41efd95290baa5c174c234f5d4c22ce601", 512},
+       {"./testdata/1c51fc286aa95d9413226599576bafa38490b1e292375c90de095855b64caea6", "946caa03167a8cc707db6ff9785608b652e631dc", 1024},
 }

 func TestTarStream(t *testing.T) {