minizip: Fix being unable to open empty zip file #778
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.
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 offset0
.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.2Footnotes
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. ↩
This is the main motivation to using -1 instead of using 0xffffffffffffffff directly as the invalid value. ↩