Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Zip archives not starting at zero offset #309

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

LemonBoy
Copy link
Contributor

@LemonBoy LemonBoy commented Jun 1, 2024

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.

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.
@uroni uroni merged commit 3c46a05 into richgel999:master Jun 9, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants