diff --git a/NEWS.md b/NEWS.md index e117422d..3c83bf64 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# X.X [Unreleased] + +* Only write Zip64 EOCD if fields don't fit in normal EOCD. Previously libzip also wrote it when any directory entry required Zip64. + # 1.10.1 [2023-08-23] * Add `ZIP_LENGTH_TO_END` and `ZIP_LENGTH_UNCHECKED`. Unless `ZIP_LENGTH_UNCHECKED` is used as `length`, it is an error for a file to shrink between the time when the source is created and when its data is read. diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c index 45a2a6a2..419ed64b 100644 --- a/lib/zip_dirent.c +++ b/lib/zip_dirent.c @@ -126,8 +126,6 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor zip_buffer_t *buffer; zip_int64_t off; zip_uint64_t i; - bool is_zip64; - int ret; zip_uint32_t cdir_crc; if ((off = zip_source_tell_write(za->src)) < 0) { @@ -136,8 +134,6 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor } offset = (zip_uint64_t)off; - is_zip64 = false; - if (ZIP_WANT_TORRENTZIP(za)) { cdir_crc = (zip_uint32_t)crc32(0, NULL, 0); za->write_crc = &cdir_crc; @@ -146,10 +142,9 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor for (i = 0; i < survivors; i++) { zip_entry_t *entry = za->entry + filelist[i].idx; - if ((ret = _zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL)) < 0) + if (_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL) < 0) { return -1; - if (ret) - is_zip64 = true; + } } za->write_crc = NULL; @@ -160,16 +155,12 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor } size = (zip_uint64_t)off - offset; - if (offset > ZIP_UINT32_MAX || survivors > ZIP_UINT16_MAX) { - is_zip64 = true; - } - if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) { zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return -1; } - if (is_zip64) { + if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) { _zip_buffer_put(buffer, EOCD64_MAGIC, 4); _zip_buffer_put_64(buffer, EOCD64LEN - 12); _zip_buffer_put_16(buffer, 45);