Support Zip archives not starting at zero offset #309
Merged
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.
Zip archives are usually read from the back to the front, making it possible to append them to other files (e.g. executables) in order to provide some kind of embedded filesystem.
We can actually extract the start of the archive by looking at the central directory offset, by comparing the specified and the actual file offset.
The Zip64 format adds another challenge as the EOCD locator specifies the offset to the EOCD starting from the beginning of the archive. Such relative offset cannot be directly used for archives not starting at position zero, hence the addition of another step that tries to locate the 64bit EOCD right before the EOCD locator. The added overhead is pretty small (and could be made smaller by reading both the presumed EOCD and EOCD locator at once) and works pretty well for 90% of the archives I've tested it with, if that heuristic fails the old behaviour is preserved.