Skip to content

Commit

Permalink
Only write Zip64 EOCD if fields don't fit in normal EOCD.
Browse files Browse the repository at this point in the history
Previously libzip also wrote it when any directory entry required Zip64.
  • Loading branch information
dillof committed Feb 23, 2024
1 parent 4c1d858 commit 6a9ef93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 3 additions & 12 deletions lib/zip_dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 6a9ef93

Please sign in to comment.