Skip to content

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

Merged
madler merged 1 commit into
madler:developfrom
RedworkDE:minizip-fix-empty
Jul 30, 2023
Merged

minizip: Fix being unable to open empty zip file#778
madler merged 1 commit into
madler:developfrom
RedworkDE:minizip-fix-empty

Conversation

@RedworkDE

Copy link
Copy Markdown
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
Copy Markdown

@gvollant: Can you look?

@gvollant

Copy link
Copy Markdown
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