From 41fcda94f67bfd68a1f9cb05f5fcf47cfec6f2bc Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Sat, 4 Jan 2020 16:55:21 -0800 Subject: [PATCH] Enable data descriptor by default since it doesn't do any seek backs to update the local header. Fixed seeking to local header when writing split archive. It kept seeking back to disk with the cd instead of the disk with the local header when the disk referenced was the first disk. --- mz_zip.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mz_zip.c b/mz_zip.c index 0fb9353..30ef177 100644 --- a/mz_zip.c +++ b/mz_zip.c @@ -1466,7 +1466,7 @@ void *mz_zip_create(void **handle) if (zip != NULL) { memset(zip, 0, sizeof(mz_zip)); - zip->data_descriptor = 0; + zip->data_descriptor = 1; } if (handle != NULL) *handle = zip; @@ -1922,15 +1922,20 @@ int32_t mz_zip_entry_is_open(void *handle) static int32_t mz_zip_seek_to_local_header(void *handle) { mz_zip *zip = (mz_zip *)handle; + int64_t disk_size = 0; + int32_t disk_number = zip->file_info.disk_number; + if (disk_number == zip->disk_number_with_cd) + { + mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_SIZE, &disk_size); + if ((disk_size == 0) || ((zip->open_mode & MZ_OPEN_MODE_WRITE) == 0)) + disk_number = -1; + } - if (((zip->open_mode & MZ_OPEN_MODE_WRITE) == 0) && (zip->file_info.disk_number == zip->disk_number_with_cd)) - mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, -1); - else - mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, zip->file_info.disk_number); + mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, disk_number); mz_zip_print("Zip - Entry - Seek local (disk %" PRId32 " offset %" PRId64 ")\n", - zip->file_info.disk_number, zip->file_info.disk_offset); + disk_number, zip->file_info.disk_offset); /* Guard against seek overflows */ if ((zip->disk_offset_shift > 0) &&