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 value[^1], 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]
[^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.
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 value[^1], 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][^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.