Fix incorrect header size assumption #22
Open
+648
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #21
I propose fix for the issue but I'm not sure this should be merged, since it needs copying Go's std library and reconstruction of sparse infomation.
This adds complexity to codebase but I believe the part I've copied from std is stable enough to maintain.
The current implementation assumes headers are always only single block long.
But as per spec and
archive/tar
implementation, some kind of headers may span multiple blocks.All of them may span multiple blocks or modification header which only relevant to a next tar entry.
I think we have roughly 3 options:
*tar.Reader
after each time*tar.Reader.Next
is called, and collect offset of start and end of header.*tar.Reader
, only collect header end offsets but reconstruct sparse infomation. And then calculate actual body length by subtracting sparse hole sizes from body size.1.
and2.
are not option because they are too large to have or too slow for large tar archives.I took
3.
. This needs copying of Go std library.I've first added tests where it reads some tar archives from
$(go env GOROOT)/src/archive/tar/testdata
using botharchive/tar
and*go-tarfs.Fs
, then compare bytes read.There was only one, but apparantly failing case.
After fix, it passes.
What I did is basically same thing I've done in my own tarfs implementation with slight simplification.