From 802fef0df079be36177b6e88767b57378b6bda9c Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Mon, 18 Mar 2024 22:01:58 +0100 Subject: [PATCH] Remove extra field information when using zip_replace(). The extra field information is usually dependent on the file data. --- NEWS.md | 3 ++- TODO.md | 1 - lib/zip_file_replace.c | 6 ++++++ man/zip_file_add.mdoc | 13 ++++++++++++- regress/utf-8-standardization-output.zip | Bin 226 -> 190 bytes 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 201df5a8f..101981cbe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,8 @@ * Only write Zip64 EOCD if fields don't fit in normal EOCD. Previously libzip also wrote it when any directory entry required Zip64. * Allow bytes from 0x00-0x1F as UTF-8. * Add new error code `ZIP_ER_TRUNCATED_ZIP` for files that start with a valid local header signature. -* `zipcmp`: add `-T` option for comparing timestamps +* `zipcmp`: add `-T` option for comparing timestamps. +* `zip_file_replace` now removes the target's extra field information. # 1.10.1 [2023-08-23] diff --git a/TODO.md b/TODO.md index 76b487884..caed74359 100644 --- a/TODO.md +++ b/TODO.md @@ -49,7 +49,6 @@ const zip_uint8_t *zip_get_archive_prefix(struct zip *za, zip_uint64_t *lengthp) * allow invalid data flag, used when computing extra field size before writing data * new command `ZIP_SOURCE_EXTRA_FIELDS` * no support for multiple copies of same extra field -* delete all extra fields during `zip_replace()` * function to copy file from one archive to another * set `O_CLOEXEC` flag after fopen and mkstemp * support streaming output (creating new archive to e.g. stdout) diff --git a/lib/zip_file_replace.c b/lib/zip_file_replace.c index 4262d453e..85178602b 100644 --- a/lib/zip_file_replace.c +++ b/lib/zip_file_replace.c @@ -83,6 +83,12 @@ _zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *s return -1; } + /* delete all extra fields - these are usually data that are + * strongly coupled with the original data */ + if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) { + return -1; + } + /* does not change any name related data, so we can do it here; * needed for a double add of the same file name */ _zip_unchange_data(za->entry + idx); diff --git a/man/zip_file_add.mdoc b/man/zip_file_add.mdoc index 287ebe351..8a6ceb766 100644 --- a/man/zip_file_add.mdoc +++ b/man/zip_file_add.mdoc @@ -29,7 +29,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 22, 2020 +.Dd March 18, 2024 .Dt ZIP_FILE_ADD 3 .Os .Sh NAME @@ -100,6 +100,17 @@ after it was used successfully in a or .Nm zip_file_replace call. +.Pp +Please also note that when using +.Nm zip_replace , +the target file's extra field information will be deleted since this +usually is dependent on the file contents. +If you want to keep them, query them beforehand with +.Xr zip_file_extra_field_get 3 +and restore them after +.Nm zip_replace +with +.Xr zip_file_extra_field_set 3 . .Sh RETURN VALUES Upon successful completion, .Fn zip_file_add diff --git a/regress/utf-8-standardization-output.zip b/regress/utf-8-standardization-output.zip index 266027ff64b93c5261b6acd0bdaf29492bee2ed2..3f7f08ce8501e298819309300b1fd27a178bb2e4 100644 GIT binary patch delta 34 jcmaFFxQ}r{B_qScDm}3PZ&o%2AYcSSUmzU~;xGUJh~NcG delta 70 zcmdnT_=s^rC8Ns3Dm^PM1_cHXU}TVB$j&_9et6A!Mi`yo+$Rs>2Y9oxLDVoZ6apF1 HAPxfn>k|@O