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

minizip: Fix being unable to open empty zip file #778

Merged
merged 1 commit into from
Jul 30, 2023

Conversation

RedworkDE
Copy link
Contributor

Fixes #199

The problem is that minizip uses the offset 0 to mark the failure to find the central directory of the zip file, but as seen in the linked issue, an empty zip file can have the central directory at offset 0.

To fix the problem, this patch uses a newly introduced constant CENTRALDIRINVALID instead. It has the value -1, which when converted to an unsigned type, results in the largest representable value1, i.e. 0xffffffffffffffff in this case. This value can never be a valid offset into a file, because it also the the maximal possible length of a file and thus not a valid offset.

Compatibility: This change should be fully backwards compatible, even if ZPOS64_T is defined to be a different size / signed.2

Footnotes

  1. In a surprising move for C, this conversion is actually well defined and not just something that happens to work, see ANSI C 6.2.1.2.

  2. This is the main motivation to using -1 instead of using 0xffffffffffffffff directly as the invalid value.

@Neustradamus
Copy link

@gvollant: Can you look?

@gvollant
Copy link
Contributor

@Neustradamus @madler the fix look fine for me, can be merged

@madler madler changed the base branch from master to develop July 30, 2023 06:12
@madler madler merged commit f209ca7 into madler:develop Jul 30, 2023
@RedworkDE RedworkDE deleted the minizip-fix-empty branch July 30, 2023 07:45
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.

unzOpen2_64 (unzip.h) function is not able to open the most trivial zip file
4 participants