Skip to content

Impossible to create .zip files with version_needed < 45 #258

@vszakats

Description

@vszakats

It seems to be impossible to create a .zip file that contains a version_needed field smaller than 45 (meaning version 4.5). This in turn means that minizip 2.x cannot be used to create valid Office Open XML (e.g. .xlsx) or OpenDocument (e.g. .ods) files, because — due to the minimum required unzip version of 4.5 indicated by the headers —, MS Office and LibreOffice refuse to open such files and/or need to "fix" them before opening. These apps require version_needed to be 30 or lower (at the same time they don't mind the ZIP64 extensions, if the sizes/offsets stay below 32-bit.)

The cause of the issue is that the version_needed value calculated for the central entry is forced to be no less than the pre-calculated value (which is always 45 or higher). There are cases when a .zip file created with version 4.5 features (= ZIP64 extensions) can be safely unzipped using a 2.0 compliant unzip, e.g. when the actual file sizes/offsets didn't break the 32-bit limits.

This patch fixes it:

diff --git a/mz_zip.c b/mz_zip.c
index 7c19400..5cd9f06 100644
--- a/mz_zip.c
+++ b/mz_zip.c
@@ -614,8 +614,6 @@ static int16_t mz_zip_entry_get_version_needed(int16_t zip64, mz_zip_file *file_
 
     if (file_info == NULL)
         return MZ_PARAM_ERROR;
-    if (file_info->version_needed > 0)
-        version_needed = file_info->version_needed;
     if (zip64)
         version_needed = 45;
 #ifdef HAVE_AES

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedIssue or bug has been fixedzipZIP file format

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions