Skip to content

Commit 04c976d

Browse files
tbeunmoinvaz
authored andcommitted
#597 Allow recover flag to read zips with >65535 entries missing zip64 EOCD
When number_entry in the standard EOCD is UINT16_MAX, the reader looks for a zip64 EOCD record. If not found, it returned MZ_FORMAT_ERROR even when the recover flag was set.
1 parent b59f684 commit 04c976d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

mz_zip.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ static int32_t mz_zip_read_cd(void *handle) {
10571057
}
10581058
} else if ((zip->number_entry == UINT16_MAX) || (number_entry_cd != zip->number_entry) ||
10591059
(zip->cd_size == UINT16_MAX) || (zip->cd_offset == UINT32_MAX)) {
1060-
err = MZ_FORMAT_ERROR;
1060+
if (!zip->recover)
1061+
err = MZ_FORMAT_ERROR;
10611062
}
10621063
}
10631064
}
@@ -1267,12 +1268,14 @@ static int32_t mz_zip_recover_cd(void *handle) {
12671268

12681269
/* Determine if we are on a split disk or not */
12691270
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, 0);
1270-
if (mz_stream_tell(zip->stream) < 0) {
1271+
if (mz_stream_tell(zip->stream) < 0)
12711272
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, -1);
1272-
mz_stream_seek(zip->stream, 0, MZ_SEEK_SET);
1273-
} else
1273+
else
12741274
disk_number_with_cd = 1;
12751275

1276+
/* Always seek to start of stream for recovery scanning */
1277+
mz_stream_seek(zip->stream, 0, MZ_SEEK_SET);
1278+
12761279
local_file_info_stream = mz_stream_mem_create();
12771280
if (!local_file_info_stream)
12781281
return MZ_MEM_ERROR;

0 commit comments

Comments
 (0)