tools/zip: sync with upstream

Signed-off-by: Linhui Liu <liulinhui36@gmail.com>
This commit is contained in:
Linhui Liu 2022-10-23 12:31:14 +08:00
parent e83a16d318
commit 5c04a547c8
4 changed files with 116 additions and 146 deletions

View File

@ -33,4 +33,3 @@ define Host/Install
endef endef
$(eval $(call HostBuild)) $(eval $(call HostBuild))
#$(eval $(call BuildPackage,zip))

View File

@ -1,145 +0,0 @@
From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001
From: Mathias Kresin <dev@kresin.me>
Date: Sat, 12 Jan 2019 19:33:33 +0100
Subject: [PATCH] add option for reproducible archives
Add the option -mt/--mtime to pass a timestamp which is used as filedate
for the containing files.
So far, it isn't used for anything written to the extra fields,
therefore requires the -X (eXclude eXtra file attributes) parameter to
be effective.
Signed-off-by: Mathias Kresin <dev@kresin.me>
---
globals.c | 1 +
util.c | 22 ++++++++++++++++++++++
zip.c | 6 ++++++
zip.h | 1 +
zipup.c | 4 +++-
5 files changed, 33 insertions(+), 1 deletion(-)
--- a/globals.c
+++ b/globals.c
@@ -205,6 +205,7 @@ uzoff_t bytes_this_split = 0; /* byt
int read_split_archive = 0; /* 1=scanzipf_reg detected spanning signature */
int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */
uzoff_t split_size = 0; /* how big each split should be */
+time_t timestamp = -1; /* fixed timestamp for archive content filedate */
int split_bell = 0; /* when pause for next split ring bell */
uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */
uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */
--- a/util.c
+++ b/util.c
@@ -1217,6 +1217,7 @@ int DisplayNumString(file, i)
return 0;
}
+
/* Read numbers with trailing size multiplier (like 10M) and return number.
10/30/04 EG */
@@ -1279,6 +1280,29 @@ uzoff_t ReadNumString( numstring )
}
+uzoff_t ReadNumStringUL( numstring )
+ char *numstring;
+{
+ zoff_t num = 0;
+
+ /* check if valid number (currently no negatives) */
+ if (numstring == NULL) {
+ zipwarn("Unable to read empty number in ReadNumString", "");
+ return (uzoff_t)-1;
+ }
+ if (numstring[0] < '0' || numstring[0] > '9') {
+ zipwarn("Unable to read number (must start with digit): ", numstring);
+ return (uzoff_t)-1;
+ }
+ if (strlen(numstring) > 10) {
+ zipwarn("Number too long to read (10 characters max): ", numstring);
+ return (uzoff_t)-1;
+ }
+
+ return (uzoff_t)atoll(numstring);
+}
+
+
/* Write the number as a string with a multiplier (like 10M) to outstring.
Always writes no more than 3 digits followed maybe by a multiplier and
returns the characters written or -1 if error.
--- a/zip.c
+++ b/zip.c
@@ -1942,6 +1942,7 @@ int set_filetype(out_path)
#ifdef UNICODE_TEST
#define o_sC 0x146
#endif
+#define o_mt 0x255
/* the below is mainly from the old main command line
@@ -2036,6 +2037,7 @@ struct option_struct far options[] = {
{"m", "move", o_NO_VALUE, o_NOT_NEGATABLE, 'm', "add files to archive then delete files"},
{"mm", "", o_NO_VALUE, o_NOT_NEGATABLE, o_mm, "not used"},
{"MM", "must-match", o_NO_VALUE, o_NOT_NEGATABLE, o_MM, "error if in file not matched/not readable"},
+ {"mt", "mtime", o_REQUIRED_VALUE, o_NOT_NEGATABLE, o_mt, "use fixed timestamp for archive content filedate"},
{"n", "suffixes", o_REQUIRED_VALUE, o_NOT_NEGATABLE, 'n', "suffixes to not compress: .gz:.zip"},
{"nw", "no-wild", o_NO_VALUE, o_NOT_NEGATABLE, o_nw, "no wildcards during add or update"},
#if defined(AMIGA) || defined(MACOS)
@@ -2440,6 +2442,7 @@ char **argv; /* command line
split_method = 0; /* 0=no splits, 1=update LHs, 2=data descriptors */
split_size = 0; /* how big each split should be */
split_bell = 0; /* when pause for next split ring bell */
+ timestamp = -1; /* fixed timestamp for archive content filedate */
bytes_prev_splits = 0; /* total bytes written to all splits before this */
bytes_this_entry = 0; /* bytes written for this entry across all splits */
noisy_splits = 0; /* be verbose about creating splits */
@@ -2897,6 +2900,9 @@ char **argv; /* command line
dispose = 1; break;
case o_MM: /* Exit with error if input file can't be read */
bad_open_is_error = 1; break;
+ case o_mt: /* fixed timestamp for archive content filedate */
+ timestamp = ReadNumStringUL(value);
+ break;
case 'n': /* Don't compress files with a special suffix */
special = value;
/* special = NULL; */ /* will be set at next argument */
--- a/zip.h
+++ b/zip.h
@@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte
extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */
extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */
extern uzoff_t split_size; /* how big each split should be */
+extern time_t timestamp; /* fixed timestamp for archive content filedate */
extern int split_bell; /* when pause for next split ring bell */
extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */
extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */
@@ -789,6 +790,7 @@ char *zip_fzofft OF((zoff_t, char
int DisplayNumString OF ((FILE *file, uzoff_t i));
int WriteNumString OF((uzoff_t num, char *outstring));
uzoff_t ReadNumString OF((char *numstring));
+uzoff_t ReadNumStringUL OF((char *numstring));
/* returns true if abbrev is abbreviation for string */
int abbrevmatch OF((char *, char *, int, int));
--- a/zipup.c
+++ b/zipup.c
@@ -415,7 +415,6 @@ struct zlist far *z; /* zip entry to
char *tempextra = NULL;
char *tempcextra = NULL;
-
#ifdef WINDLL
# ifdef ZIP64_SUPPORT
extern _int64 filesize64;
@@ -441,6 +440,9 @@ struct zlist far *z; /* zip entry to
if (tim == 0 || q == (zoff_t) -3)
return ZE_OPEN;
+ if (timestamp > 0)
+ tim = unix2dostime(&timestamp);
+
/* q is set to -1 if the input file is a device, -2 for a volume label */
if (q == (zoff_t) -2) {
isdir = 1;

View File

@ -0,0 +1,41 @@
From 501ae4e93fd6fa2f7d20d00d1b011f9006802eae Mon Sep 17 00:00:00 2001
From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
Date: Fri, 3 May 2019 16:32:24 +0200
Subject: [PATCH] Override mtime with zip -X
with SOURCE_DATE_EPOCH
to allow for reproducible builds of .zip files
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
Uses clamping to keep older mtimes than SOURCE_DATE_EPOCH intact.
---
zipup.c | 8 ++++++++
1 file changed, 8 insertions(+)
--- a/zipup.c
+++ b/zipup.c
@@ -414,6 +414,7 @@ struct zlist far *z; /* zip entry to
ush tempcext = 0;
char *tempextra = NULL;
char *tempcextra = NULL;
+ const char *source_date_epoch;
#ifdef WINDLL
@@ -674,6 +675,13 @@ struct zlist far *z; /* zip entry to
} /* strcmp(z->name, "-") == 0 */
+ if (extra_fields == 0 && (source_date_epoch = getenv("SOURCE_DATE_EPOCH")) != NULL) {
+ time_t epoch = strtoull(source_date_epoch, NULL, 10);
+ if (epoch > 0) {
+ ulg epochtim = unix2dostime(&epoch);
+ if (z->tim > epochtim) z->tim = epochtim;
+ }
+ }
if (extra_fields == 2) {
unsigned len;
char *p;

View File

@ -0,0 +1,75 @@
From db9165814823401d57383a8f9e82642129cf4223 Mon Sep 17 00:00:00 2001
From: Sungbo Eo <mans0n@gorani.run>
Date: Sat, 12 Feb 2022 16:42:14 +0900
Subject: [PATCH] make encrypted archives reproducible
Zip always try to generate new encryption header depending on execution
time and process id, which is far from being reproducible. This commit
changes the zip srand() seed to a predictable value to generate
reproducible random bytes for the encryption header. This will compromise
the goal of secure archive encryption, but it would not be a big problem
for our purpose.
Signed-off-by: Sungbo Eo <mans0n@gorani.run>
---
crypt.c | 8 ++++++--
globals.c | 1 +
zip.h | 1 +
zipup.c | 2 +-
4 files changed, 9 insertions(+), 3 deletions(-)
--- a/crypt.c
+++ b/crypt.c
@@ -29,7 +29,6 @@
version without encryption capabilities).
*/
-#define ZCRYPT_INTERNAL
#include "zip.h"
#include "crypt.h"
#include "ttyio.h"
@@ -219,7 +218,12 @@ void crypthead(passwd, crc)
* often poorly implemented.
*/
if (++calls == 1) {
- srand((unsigned)time(NULL) ^ ZCR_SEED2);
+ unsigned zcr_seed1 = (unsigned)time(NULL);
+#ifndef ZCRYPT_INTERNAL
+ if (epoch > 0)
+ zcr_seed1 = (unsigned)epoch;
+#endif
+ srand(zcr_seed1 ^ ZCR_SEED2);
}
init_keys(passwd);
for (n = 0; n < RAND_HEAD_LEN-2; n++) {
--- a/globals.c
+++ b/globals.c
@@ -206,6 +206,7 @@ int read_split_archive = 0; /* 1=s
int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */
uzoff_t split_size = 0; /* how big each split should be */
int split_bell = 0; /* when pause for next split ring bell */
+time_t epoch = 0; /* timestamp from SOURCE_DATE_EPOCH */
uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */
uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */
int noisy_splits = 0; /* note when splits are being created */
--- a/zip.h
+++ b/zip.h
@@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte
extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */
extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */
extern uzoff_t split_size; /* how big each split should be */
+extern time_t epoch; /* timestamp from SOURCE_DATE_EPOCH */
extern int split_bell; /* when pause for next split ring bell */
extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */
extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */
--- a/zipup.c
+++ b/zipup.c
@@ -676,7 +676,7 @@ struct zlist far *z; /* zip entry to
} /* strcmp(z->name, "-") == 0 */
if (extra_fields == 0 && (source_date_epoch = getenv("SOURCE_DATE_EPOCH")) != NULL) {
- time_t epoch = strtoull(source_date_epoch, NULL, 10);
+ epoch = strtoull(source_date_epoch, NULL, 10);
if (epoch > 0) {
ulg epochtim = unix2dostime(&epoch);
if (z->tim > epochtim) z->tim = epochtim;