Skip to content

Commit

Permalink
Remove extra field information when using zip_replace().
Browse files Browse the repository at this point in the history
The extra field information is usually dependent on the file data.
  • Loading branch information
0-wiz-0 committed Mar 18, 2024
1 parent 15e7fbf commit 802fef0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/zip_file_replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion man/zip_file_add.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified regress/utf-8-standardization-output.zip
Binary file not shown.

0 comments on commit 802fef0

Please sign in to comment.