diff options
22 files changed, 1869 insertions, 0 deletions
@@ -0,0 +1 @@ +/zlib-1.2.13.tar.xz diff --git a/backport-Add-bounds-checking-to-ERR_MSG-macro-used-by-zError.patch b/backport-Add-bounds-checking-to-ERR_MSG-macro-used-by-zError.patch new file mode 100644 index 0000000..e4d75cf --- /dev/null +++ b/backport-Add-bounds-checking-to-ERR_MSG-macro-used-by-zError.patch @@ -0,0 +1,27 @@ +From 431a9b65eacab7efabf2230ba97ff426c0e07f9d Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Thu, 7 Dec 2023 06:38:10 -0800 +Subject: [PATCH] Add bounds checking to ERR_MSG() macro, used by zError(). + +Reference: https://github.com/madler/zlib/commit/431a9b65eacab7efabf2230ba97ff426c0e07f9d +Conflict: no +--- + zutil.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/zutil.h b/zutil.h +index 902a304..0bd2dbc 100644 +--- a/zutil.h ++++ b/zutil.h +@@ -56,7 +56,7 @@ typedef unsigned long ulg; + extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ + /* (size given to avoid silly warnings with Visual C++) */ + +-#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] ++#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] + + #define ERR_RETURN(strm,err) \ + return (strm->msg = ERR_MSG(err), (err)) +-- +2.33.0 + diff --git a/backport-CVE-2023-45853.patch b/backport-CVE-2023-45853.patch new file mode 100644 index 0000000..f750e0f --- /dev/null +++ b/backport-CVE-2023-45853.patch @@ -0,0 +1,39 @@ +From 73331a6a0481067628f065ffe87bb1d8f787d10c Mon Sep 17 00:00:00 2001 +From: Hans Wennborg <hans@chromium.org> +Date: Fri, 18 Aug 2023 11:05:33 +0200 +Subject: [PATCH] Reject overflows of zip header fields in minizip. + +This checks the lengths of the file name, extra field, and comment +that would be put in the zip headers, and rejects them if they are +too long. They are each limited to 65535 bytes in length by the zip +format. This also avoids possible buffer overflows if the provided +fields are too long. +--- + contrib/minizip/zip.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c +index 3d3d4ca..0446109 100644 +--- a/contrib/minizip/zip.c ++++ b/contrib/minizip/zip.c +@@ -1043,6 +1043,17 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c + return ZIP_PARAMERROR; + #endif + ++ // The filename and comment length must fit in 16 bits. ++ if ((filename!=NULL) && (strlen(filename)>0xffff)) ++ return ZIP_PARAMERROR; ++ if ((comment!=NULL) && (strlen(comment)>0xffff)) ++ return ZIP_PARAMERROR; ++ // The extra field length must fit in 16 bits. If the member also requires ++ // a Zip64 extra block, that will also need to fit within that 16-bit ++ // length, but that will be checked for later. ++ if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff)) ++ return ZIP_PARAMERROR; ++ + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) +-- +2.41.0.windows.3 + diff --git a/backport-CVE-2026-27171.patch b/backport-CVE-2026-27171.patch new file mode 100644 index 0000000..c22968c --- /dev/null +++ b/backport-CVE-2026-27171.patch @@ -0,0 +1,60 @@ +From ba829a458576d1ff0f26fc7230c6de816d1f6a77 Mon Sep 17 00:00:00 2001 +From: Mark Adler <git@madler.net> +Date: Sun, 21 Dec 2025 18:17:56 -0800 +Subject: [PATCH] Check for negative lengths in crc32_combine functions. + +Though zlib.h says that len2 must be non-negative, this avoids the +possibility of an accidental infinite loop. + +link:https://github.com/madler/zlib/commit/ba829a458576d1ff0f26fc7230c6de816d1f6a77 +--- + crc32.c | 4 ++++ + zlib.h | 4 ++-- + 2 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/crc32.c b/crc32.c +index 23f8f8b..40f0810 100644 +--- a/crc32.c ++++ b/crc32.c +@@ -1133,6 +1133,8 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2) + uLong crc2; + z_off64_t len2; + { ++ if (len2 < 0) ++ return 0; + #ifdef DYNAMIC_CRC_TABLE + once(&made, make_crc_table); + #endif /* DYNAMIC_CRC_TABLE */ +@@ -1152,6 +1154,8 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong ZEXPORT crc32_combine_gen64(len2) + z_off64_t len2; + { ++ if (len2 < 0) ++ return 0; + #ifdef DYNAMIC_CRC_TABLE + once(&made, make_crc_table); + #endif /* DYNAMIC_CRC_TABLE */ +diff --git a/zlib.h b/zlib.h +index 953cb50..c9cecf3 100644 +--- a/zlib.h ++++ b/zlib.h +@@ -1755,14 +1755,14 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and +- len2. ++ len2. len2 must be non-negativem, otherwise zero is returned. + */ + + /* + ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); + + Return the operator corresponding to length len2, to be used with +- crc32_combine_op(). ++ crc32_combine_op(). len2 must be non-negative, otherwise zero is returned. + */ + + ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +-- +2.43.0 + diff --git a/backport-Fix-a-bug-in-ZLIB_DEBUG-compiles-in-check_match.patch b/backport-Fix-a-bug-in-ZLIB_DEBUG-compiles-in-check_match.patch new file mode 100644 index 0000000..18bc6a8 --- /dev/null +++ b/backport-Fix-a-bug-in-ZLIB_DEBUG-compiles-in-check_match.patch @@ -0,0 +1,50 @@ +From 7af6320ad78b390de42f414fabdc64dc6d67a5ea Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Fri, 19 Jan 2024 12:19:53 -0800 +Subject: [PATCH] Fix a bug in ZLIB_DEBUG compiles in check_match(). + +This avoids trying to compare a match starting one byte before the +current window. Thanks to @zmodem (Hans) for discovering this. + +Reference:https://github.com/madler/zlib/commit/7af6320ad78b390de42f414fabdc64dc6d67a5ea +Conflict: Patch context adaptation + +--- + deflate.c | 20 ++++++++++++++------ + 1 file changed, 14 insertions(+), 6 deletions(-) + +diff --git a/deflate.c b/deflate.c +index 8088083..396ab12 100644 +--- a/deflate.c ++++ b/deflate.c +@@ -1510,13 +1510,21 @@ local void check_match(s, start, match, length) + int length; + { + /* check that the match is indeed a match */ +- if (zmemcmp(s->window + match, +- s->window + start, length) != EQUAL) { +- fprintf(stderr, " start %u, match %u, length %d\n", +- start, match, length); ++ Bytef *back = s->window + (int)match, *here = s->window + start; ++ IPos len = length; ++ if (match == (IPos)-1) { ++ /* match starts one byte before the current window -- just compare the ++ subsequent length-1 bytes */ ++ back++; ++ here++; ++ len--; ++ } ++ if (zmemcmp(back, here, len) != EQUAL) { ++ fprintf(stderr, " start %u, match %d, length %d\n", ++ start, (int)match, length); + do { +- fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); +- } while (--length != 0); ++ fprintf(stderr, "(%02x %02x)", *back++, *here++); ++ } while (--len != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { +-- +2.33.0 + diff --git a/backport-Fix-bug-in-inflateSync-for-data-held-in-bit-buffer.patch b/backport-Fix-bug-in-inflateSync-for-data-held-in-bit-buffer.patch new file mode 100644 index 0000000..0bcac9f --- /dev/null +++ b/backport-Fix-bug-in-inflateSync-for-data-held-in-bit-buffer.patch @@ -0,0 +1,27 @@ +From 5af7cef45eeef86ddf6ab00b4e363c1eecaf47b6 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Thu, 24 Aug 2023 02:14:23 -0400 +Subject: [PATCH] Fix bug in inflateSync() for data held in bit buffer. + +Reference: https://github.com/madler/zlib/commit/5af7cef45eeef86ddf6ab00b4e363c1eecaf47b6 +Conflict: no +--- + inflate.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/inflate.c b/inflate.c +index b0757a9..94ecff0 100644 +--- a/inflate.c ++++ b/inflate.c +@@ -1387,7 +1387,7 @@ int ZEXPORT inflateSync(z_streamp strm) { + /* if first time, start search in bit buffer */ + if (state->mode != SYNC) { + state->mode = SYNC; +- state->hold <<= state->bits & 7; ++ state->hold >>= state->bits & 7; + state->bits -= state->bits & 7; + len = 0; + while (state->bits >= 8) { +-- +2.33.0 + diff --git a/backport-Fix-bug-when-gzungetc-is-used-immediately-after-gzopen.patch b/backport-Fix-bug-when-gzungetc-is-used-immediately-after-gzopen.patch new file mode 100644 index 0000000..a6b892e --- /dev/null +++ b/backport-Fix-bug-when-gzungetc-is-used-immediately-after-gzopen.patch @@ -0,0 +1,26 @@ +From 7dd6aa72455ef1f2aacdc28a00d1eaf632d59593 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Fri, 11 Aug 2023 10:59:03 -0700 +Subject: [PATCH] Fix bug when gzungetc() is used immediately after gzopen(). + +Reference:https://github.com/madler/zlib/commit/7dd6aa72455ef1f2aacdc28a00d1eaf632d59593 +Conflict:NA +--- + gzread.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/gzread.c b/gzread.c +index 6034a2823..4168cbc88 100644 +--- a/gzread.c ++++ b/gzread.c +@@ -443,6 +443,10 @@ int ZEXPORT gzungetc(int c, gzFile file) { + return -1; + state = (gz_statep)file; + ++ /* in case this was just opened, set up the input buffer */ ++ if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) ++ (void)gz_look(state); ++ + /* check that we're reading and that there's no (serious) error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) diff --git a/backport-Fix-bug-when-using-gzflush-with-a-very-small-buffer.patch b/backport-Fix-bug-when-using-gzflush-with-a-very-small-buffer.patch new file mode 100644 index 0000000..047c17d --- /dev/null +++ b/backport-Fix-bug-when-using-gzflush-with-a-very-small-buffer.patch @@ -0,0 +1,26 @@ +From d98251478246c8ef2f405d76e4ef1678c14d7eda Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Mon, 14 Aug 2023 17:01:54 -0700 +Subject: [PATCH] Fix bug when using gzflush() with a very small buffer. + +Reference:https://github.com/madler/zlib/commit/d98251478246c8ef2f405d76e4ef1678c14d7eda +Conflict:NA +--- + gzlib.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/gzlib.c b/gzlib.c +index 2b446c448..29fc4486f 100644 +--- a/gzlib.c ++++ b/gzlib.c +@@ -308,8 +308,8 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size) { + /* check and set requested size */ + if ((size << 1) < size) + return -1; /* need to be able to double it */ +- if (size < 2) +- size = 2; /* need two bytes to check magic header */ ++ if (size < 8) ++ size = 8; /* needed to behave well with flushing */ + state->want = size; + return 0; + } diff --git a/backport-Fix-crash-when-gzsetparams-attempted-for-transparent-write.patch b/backport-Fix-crash-when-gzsetparams-attempted-for-transparent-write.patch new file mode 100644 index 0000000..1d488ba --- /dev/null +++ b/backport-Fix-crash-when-gzsetparams-attempted-for-transparent-write.patch @@ -0,0 +1,26 @@ +From 02a6049eb3884c430268bb0fe3296d597a03174c Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Mon, 26 Dec 2022 23:36:01 -0800 +Subject: [PATCH] Fix crash when gzsetparams() attempted for transparent write. + +gzsetparams() now returns a Z_STREAM_ERROR in this case.i + +Reference:https://github.com/madler/zlib/commit/02a6049eb3884c430268bb0fe3296d597a03174c +Conflict:NA +--- + gzwrite.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/gzwrite.c b/gzwrite.c +index eb8a0e589..3030d74d6 100644 +--- a/gzwrite.c ++++ b/gzwrite.c +@@ -609,7 +609,7 @@ int ZEXPORT gzsetparams(file, level, strategy) + strm = &(state->strm); + + /* check that we're writing and that there's no error */ +- if (state->mode != GZ_WRITE || state->err != Z_OK) ++ if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct) + return Z_STREAM_ERROR; + + /* if no change is requested, then do nothing */ diff --git a/backport-Fix-decision-on-the-emission-of-Zip64-end-records-in.patch b/backport-Fix-decision-on-the-emission-of-Zip64-end-records-in.patch new file mode 100644 index 0000000..a2a8435 --- /dev/null +++ b/backport-Fix-decision-on-the-emission-of-Zip64-end-records-in.patch @@ -0,0 +1,35 @@ +From 15c45adb76e81a7e3a8a9e17b2a56eb90f668f44 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Tue, 7 Nov 2023 15:46:41 -0800 +Subject: [PATCH] Fix decision on the emission of Zip64 end records in minizip. + +The appnote says that if the number of entries in the end record +is 0xffff, then the actual number of entries will be found in the +Zip64 end record. Therefore if the number of entries is equal to +0xffff, it can't be in the end record by itself, since that is an +instruction to get the number from the Zip64 end record. This code +would just store 0xffff in the end record in that case, not making +a Zip64 end record. This commit fixes that. + +Reference: https://github.com/madler/zlib/commit/15c45adb76e81a7e3a8a9e17b2a56eb90f668f44 +Conflict: no +--- + contrib/minizip/zip.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c +index 0446109..86be90b 100644 +--- a/contrib/minizip/zip.c ++++ b/contrib/minizip/zip.c +@@ -1872,7 +1872,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) { + free_linkedlist(&(zi->central_dir)); + + pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; +- if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) ++ if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF) + { + ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); + Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); +-- +2.33.0 + diff --git a/backport-Fix-logic-error-in-minizip-argument-processing.patch b/backport-Fix-logic-error-in-minizip-argument-processing.patch new file mode 100644 index 0000000..e10da93 --- /dev/null +++ b/backport-Fix-logic-error-in-minizip-argument-processing.patch @@ -0,0 +1,24 @@ +From 3061e5013c2569974fd7d830f2776b38da4e2691 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Sat, 29 Jul 2023 23:51:22 -0700 +Subject: [PATCH] Fix logic error in minizip argument processing. + +Reference:https://github.com/madler/zlib/commit/3061e5013c2569974fd7d830f2776b38da4e2691 +Conflict:NA +--- + contrib/minizip/minizip.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c +index f458c85ef..61a9d4c7d 100644 +--- a/contrib/minizip/minizip.c ++++ b/contrib/minizip/minizip.c +@@ -381,7 +381,7 @@ int main(int argc, char *argv[]) { + ((argv[i][1]=='o') || (argv[i][1]=='O') || + (argv[i][1]=='a') || (argv[i][1]=='A') || + (argv[i][1]=='p') || (argv[i][1]=='P') || +- ((argv[i][1]>='0') || (argv[i][1]<='9'))) && ++ ((argv[i][1]>='0') && (argv[i][1]<='9'))) && + (strlen(argv[i]) == 2))) + { + FILE * fin; diff --git a/backport-Fix-reading-disk-number-start-on-zip64-files-in-minizip.patch b/backport-Fix-reading-disk-number-start-on-zip64-files-in-minizip.patch new file mode 100644 index 0000000..f68c8af --- /dev/null +++ b/backport-Fix-reading-disk-number-start-on-zip64-files-in-minizip.patch @@ -0,0 +1,40 @@ +From e0bd0ad6e4d8afd2bc3d55d84d459a0e2c0e2890 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Sat, 29 Jul 2023 23:34:26 -0700 +Subject: [PATCH] Fix reading disk number start on zip64 files in minizip. + +Reference:https://github.com/madler/zlib/commit/e0bd0ad6e4d8afd2bc3d55d84d459a0e2c0e2890 +Conflict:NA +--- + contrib/minizip/unzip.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c +index 1da51a9..9329732 100644 +--- a/contrib/minizip/unzip.c ++++ b/contrib/minizip/unzip.c +@@ -1038,8 +1038,6 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file, + /* ZIP64 extra fields */ + if (headerId == 0x0001) + { +- uLong uL; +- + if(file_info.uncompressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) +@@ -1059,10 +1057,10 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file, + err=UNZ_ERRNO; + } + +- if(file_info.disk_num_start == MAXU32) ++ if(file_info.disk_num_start == 0xffff) + { + /* Disk Start Number */ +- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) ++ if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + } + +-- +2.27.0 + diff --git a/backport-Neutralize-zip-file-traversal-attacks-in-miniunz.patch b/backport-Neutralize-zip-file-traversal-attacks-in-miniunz.patch new file mode 100644 index 0000000..18589f5 --- /dev/null +++ b/backport-Neutralize-zip-file-traversal-attacks-in-miniunz.patch @@ -0,0 +1,61 @@ +From 14a5f8f266c16c87ab6c086fc52b770b27701e01 Mon Sep 17 00:00:00 2001 +From: Matt Wilson <msw@amazon.com> +Date: Wed, 17 Jan 2024 14:46:18 -0800 +Subject: [PATCH] Neutralize zip file traversal attacks in miniunz. + +Archive formats such as .zip files are generally susceptible to +so-called "traversal attacks". This allows an attacker to craft +an archive that writes to unexpected locations of the file system +(e.g., /etc/shadow) if an unspecting root user were to unpack a +malicious archive. + +This patch neutralizes absolute paths such as /tmp/moo and deeply +relative paths such as dummy/../../../../../../../../../../tmp/moo + +The Debian project requested CVE-2014-9485 be allocated for the +first identified weakness. The fix was incomplete, resulting in a +revised patch applied here. Since there wasn't an updated version +released by Debian with the incomplete fix, I suggest we use this +CVE to identify both issues. + +Link: https://security.snyk.io/research/zip-slip-vulnerability +Link: https://bugs.debian.org/774321 +Link: https://bugs.debian.org/776831 +Link: https://nvd.nist.gov/vuln/detail/CVE-2014-9485 +Reported-by: Jakub Wilk <jwilk@debian.org> +Fixed-by: Michael Gilbert <mgilbert@debian.org> + +Reference: https://github.com/madler/zlib/commit/14a5f8f266c16c87ab6c086fc52b770b27701e01 +Conflict: no +--- + contrib/minizip/miniunz.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c +index 0c2fb0d..d627c42 100644 +--- a/contrib/minizip/miniunz.c ++++ b/contrib/minizip/miniunz.c +@@ -356,6 +356,20 @@ static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_pa + else + write_filename = filename_withoutpath; + ++ if (write_filename[0]!='\0') ++ { ++ const char* relative_check = write_filename; ++ while (relative_check[1]!='\0') ++ { ++ if (relative_check[0]=='.' && relative_check[1]=='.') ++ write_filename = relative_check; ++ relative_check++; ++ } ++ } ++ ++ while (write_filename[0]=='/' || write_filename[0]=='.') ++ write_filename++; ++ + err = unzOpenCurrentFilePassword(uf,password); + if (err!=UNZ_OK) + { +-- +2.33.0 + diff --git a/backport-Remove-use-of-OF-from-contrib-untgz-and-render-it-compilable.patch b/backport-Remove-use-of-OF-from-contrib-untgz-and-render-it-compilable.patch new file mode 100644 index 0000000..eabc5eb --- /dev/null +++ b/backport-Remove-use-of-OF-from-contrib-untgz-and-render-it-compilable.patch @@ -0,0 +1,109 @@ +From 66588683b36042154ad35140bf9fcbb60c5d573c Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Sat, 15 Apr 2023 11:27:12 -0700 +Subject: [PATCH] Remove use of OF() from contrib/untgz and render it + compilable. + +Reference:https://github.com/madler/zlib/commit/66588683b36042154ad35140bf9fcbb60c5d573c +Conflict:NA +--- + contrib/untgz/untgz.c | 47 +++++++++++-------------------------------- + 1 file changed, 12 insertions(+), 35 deletions(-) + +diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c +index 2c391e598..3e530971c 100644 +--- a/contrib/untgz/untgz.c ++++ b/contrib/untgz/untgz.c +@@ -14,15 +14,10 @@ + + #include "zlib.h" + +-#ifdef unix +-# include <unistd.h> +-#else ++#ifdef _WIN32 + # include <direct.h> + # include <io.h> +-#endif +- +-#ifdef WIN32 +-#include <windows.h> ++# include <windows.h> + # ifndef F_OK + # define F_OK 0 + # endif +@@ -33,6 +28,8 @@ + # define strdup(str) _strdup(str) + # endif + #else ++# include <sys/stat.h> ++# include <unistd.h> + # include <utime.h> + #endif + +@@ -102,28 +99,14 @@ struct attr_item + + enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; + +-char *TGZfname OF((const char *)); +-void TGZnotfound OF((const char *)); +- +-int getoct OF((char *, int)); +-char *strtime OF((time_t *)); +-int setfiletime OF((char *, time_t)); +-void push_attr OF((struct attr_item **, char *, int, time_t)); +-void restore_attr OF((struct attr_item **)); +- +-int ExprMatch OF((char *, char *)); +- +-int makedir OF((char *)); +-int matchname OF((int, int, char **, char *)); +- +-void error OF((const char *)); +-int tar OF((gzFile, int, int, int, char **)); +- +-void help OF((int)); +-int main OF((int, char **)); +- + char *prog; + ++void error(const char *msg) ++{ ++ fprintf(stderr, "%s: %s\n", prog, msg); ++ exit(1); ++} ++ + const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL }; + + /* return the file name of the TGZ archive */ +@@ -205,7 +188,7 @@ char *strtime (time_t *t) + + int setfiletime (char *fname,time_t ftime) + { +-#ifdef WIN32 ++#ifdef _WIN32 + static int isWinNT = -1; + SYSTEMTIME st; + FILETIME locft, modft; +@@ -590,12 +573,6 @@ void help(int exitval) + exit(exitval); + } + +-void error(const char *msg) +-{ +- fprintf(stderr, "%s: %s\n", prog, msg); +- exit(1); +-} +- + + /* ============================================================ */ + +@@ -608,7 +585,7 @@ int main(int argc,char **argv) + int action = TGZ_EXTRACT; + int arg = 1; + char *TGZfile; +- gzFile *f; ++ gzFile f; + + prog = strrchr(argv[0],'\\'); + if (prog == NULL) diff --git a/backport-Suppress-MSAN-detections-in-deflate-slide_hash.patch b/backport-Suppress-MSAN-detections-in-deflate-slide_hash.patch new file mode 100644 index 0000000..449a9e3 --- /dev/null +++ b/backport-Suppress-MSAN-detections-in-deflate-slide_hash.patch @@ -0,0 +1,36 @@ +From 981ee7570ad98a3cf1ae74d737e2ee619ed79171 Mon Sep 17 00:00:00 2001 +From: Andrzej Hunt <andrzej@ahunt.org> +Date: Fri, 4 Jun 2021 18:25:19 +0200 +Subject: [PATCH] Suppress MSAN detections in deflate's slide_hash(). + +slide_hash() knowingly reads potentially uninitialized memory, see +comment lower down about prev[n] potentially being garbage. In +this case, the result is never used. + +Reference:https://github.com/madler/zlib/commit/981ee7570ad98a3cf1ae74d737e2ee619ed79171 +Conflict:NA +--- + deflate.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/deflate.c b/deflate.c +index 5410497..8088083 100644 +--- a/deflate.c ++++ b/deflate.c +@@ -209,6 +209,13 @@ local const config configuration_table[10] = { + * bit values at the expense of memory usage). We slide even when level == 0 to + * keep the hash table consistent if we switch back to level > 0 later. + */ ++ ++#if defined(__has_feature) ++# if __has_feature(memory_sanitizer) ++ __attribute__((no_sanitize("memory"))) ++# endif ++#endif ++ + local void slide_hash(s) + deflate_state *s; + { +-- +2.27.0 + diff --git a/backport-avoid-uninitialized-and-unused-warnings-in-contrib-minizip.patch b/backport-avoid-uninitialized-and-unused-warnings-in-contrib-minizip.patch new file mode 100644 index 0000000..c40bb55 --- /dev/null +++ b/backport-avoid-uninitialized-and-unused-warnings-in-contrib-minizip.patch @@ -0,0 +1,63 @@ +From 25bbd7f5a6a172b83b59fab7a80c55d1533dd100 Mon Sep 17 00:00:00 2001 +From: Mark Adler <madler@alumni.caltech.edu> +Date: Thu, 17 Aug 2023 21:40:28 -0700 +Subject: [PATCH] Avoid uninitialized and unused warnings in contrib/minizip. + +Reference:https://github.com/madler/zlib/commit/25bbd7f5a6a172b83b59fab7a80c55d1533dd100 +Conflict:NA +--- + contrib/minizip/miniunz.c | 10 ++++++++-- + contrib/minizip/minizip.c | 2 +- + 2 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c +index 3d65401..507820d 100644 +--- a/contrib/minizip/miniunz.c ++++ b/contrib/minizip/miniunz.c +@@ -113,7 +113,11 @@ void change_file_date(filename,dosdate,tmu_date) + + ut.actime=ut.modtime=mktime(&newdate); + utime(filename,&ut); +-#endif ++#else ++ (void)filename; ++ (void)dosdate; ++ (void)tmu_date; ++#endif + #endif + } + +@@ -131,6 +135,8 @@ int mymkdir(dirname) + ret = mkdir (dirname,0775); + #elif __APPLE__ + ret = mkdir (dirname,0775); ++#else ++ (void)dirname; + #endif + return ret; + } +@@ -248,7 +254,7 @@ int do_list(uf) + char filename_inzip[256]; + unz_file_info64 file_info; + uLong ratio=0; +- const char *string_method; ++ const char *string_method = ""; + char charCrypt=' '; + err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); + if (err!=UNZ_OK) +diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c +index c5d9cc6..5dde38f 100644 +--- a/contrib/minizip/minizip.c ++++ b/contrib/minizip/minizip.c +@@ -395,7 +395,7 @@ int main(argc,argv) + ((argv[i][1]>='0') && (argv[i][1]<='9'))) && + (strlen(argv[i]) == 2))) + { +- FILE * fin; ++ FILE * fin = NULL; + size_t size_read; + const char* filenameinzip = argv[i]; + const char *savefilenameinzip; +-- +2.27.0 + diff --git a/backport-minizip-Fix-being-unable-to-open-empty-zip-file.patch b/backport-minizip-Fix-being-unable-to-open-empty-zip-file.patch new file mode 100644 index 0000000..f574468 --- /dev/null +++ b/backport-minizip-Fix-being-unable-to-open-empty-zip-file.patch @@ -0,0 +1,160 @@ +From f209ca7be7981dc8fca79428706057e4ebc929ee Mon Sep 17 00:00:00 2001 +From: RedworkDE <10944644+RedworkDE@users.noreply.github.com> +Date: Wed, 15 Feb 2023 12:25:33 +0100 +Subject: [PATCH] minizip: Fix being unable to open empty zip file + +Reference:https://github.com/madler/zlib/commit/f209ca7be7981dc8fca79428706057e4ebc929ee +Conflict:NA +--- + contrib/minizip/unzip.c | 48 ++++++++++++++++++++++------------------- + 1 file changed, 26 insertions(+), 22 deletions(-) + +diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c +index ad2eb3bc9..3adc692f3 100644 +--- a/contrib/minizip/unzip.c ++++ b/contrib/minizip/unzip.c +@@ -379,6 +379,10 @@ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, + #define BUFREADCOMMENT (0x400) + #endif + ++#ifndef CENTRALDIRINVALID ++#define CENTRALDIRINVALID ((ZPOS64_T)(-1)) ++#endif ++ + /* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +@@ -388,10 +392,10 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ +- ZPOS64_T uPosFound=0; ++ ZPOS64_T uPosFound=CENTRALDIRINVALID; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) +- return 0; ++ return CENTRALDIRINVALID; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); +@@ -401,7 +405,7 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) +- return 0; ++ return CENTRALDIRINVALID; + + uBackRead = 4; + while (uBackRead<uMaxBack) +@@ -431,7 +435,7 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f + break; + } + +- if (uPosFound!=0) ++ if (uPosFound!=CENTRALDIRINVALID) + break; + } + TRYFREE(buf); +@@ -449,12 +453,12 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ +- ZPOS64_T uPosFound=0; ++ ZPOS64_T uPosFound=CENTRALDIRINVALID; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) +- return 0; ++ return CENTRALDIRINVALID; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); +@@ -464,7 +468,7 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) +- return 0; ++ return CENTRALDIRINVALID; + + uBackRead = 4; + while (uBackRead<uMaxBack) +@@ -494,47 +498,47 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib + break; + } + +- if (uPosFound!=0) ++ if (uPosFound!=CENTRALDIRINVALID) + break; + } + TRYFREE(buf); +- if (uPosFound == 0) +- return 0; ++ if (uPosFound == CENTRALDIRINVALID) ++ return CENTRALDIRINVALID; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) +- return 0; ++ return CENTRALDIRINVALID; + + /* the signature, already checked */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) +- return 0; ++ return CENTRALDIRINVALID; + + /* number of the disk with the start of the zip64 end of central directory */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) +- return 0; ++ return CENTRALDIRINVALID; + if (uL != 0) +- return 0; ++ return CENTRALDIRINVALID; + + /* relative offset of the zip64 end of central directory record */ + if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) +- return 0; ++ return CENTRALDIRINVALID; + + /* total number of disks */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) +- return 0; ++ return CENTRALDIRINVALID; + if (uL != 1) +- return 0; ++ return CENTRALDIRINVALID; + + /* Goto end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) +- return 0; ++ return CENTRALDIRINVALID; + + /* the signature */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) +- return 0; ++ return CENTRALDIRINVALID; + + if (uL != 0x06064b50) +- return 0; ++ return CENTRALDIRINVALID; + + return relativeOffset; + } +@@ -587,7 +591,7 @@ local unzFile unzOpenInternal(const void *path, + return NULL; + + central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); +- if (central_pos) ++ if (central_pos!=CENTRALDIRINVALID) + { + uLong uS; + ZPOS64_T uL64; +@@ -649,7 +653,7 @@ local unzFile unzOpenInternal(const void *path, + else + { + central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); +- if (central_pos==0) ++ if (central_pos==CENTRALDIRINVALID) + err=UNZ_ERRNO; + + us.isZip64 = 0; diff --git a/backport-zlib-1.2.5-minizip-fixuncrypt.patch b/backport-zlib-1.2.5-minizip-fixuncrypt.patch new file mode 100644 index 0000000..d113879 --- /dev/null +++ b/backport-zlib-1.2.5-minizip-fixuncrypt.patch @@ -0,0 +1,14 @@ +diff -up zlib-1.2.5/contrib/minizip/unzip.c.fixuncrypt zlib-1.2.5/contrib/minizip/unzip.c +--- zlib-1.2.5/contrib/minizip/unzip.c.fixuncrypt 2011-11-11 12:13:56.335867758 -0500 ++++ zlib-1.2.5/contrib/minizip/unzip.c 2011-11-11 12:14:01.747799372 -0500 +@@ -68,10 +68,6 @@ + #include <stdlib.h> + #include <string.h> + +-#ifndef NOUNCRYPT +- #define NOUNCRYPT +-#endif +- + #include "zlib.h" + #include "unzip.h" + @@ -0,0 +1 @@ +7d9fc1d78ae2fa3e84fe98b77d006c63 zlib-1.2.13.tar.xz diff --git a/zlib-1.2.11-SIMD.patch b/zlib-1.2.11-SIMD.patch new file mode 100644 index 0000000..df0bf7a --- /dev/null +++ b/zlib-1.2.11-SIMD.patch @@ -0,0 +1,770 @@ +From 91c1e78feec94739cc5da8562b3e2395bfdf6193 Mon Sep 17 00:00:00 2001 +From: hedongbo <hedongbo@huawei.com> +Date: Sun, 14 Sep 2020 15:36:12 +0800 +Subject: [PATCH] zlib-1.2.11-SIMD.patch + +In the sampling of the Hive test program, it is found that inflate occupies a high proportion. +The zlib is optimized through instruction set optimization, hash replacement, and compilation option optimization. +The inflate and deflate processes of the Zlib library provided by the JDK are optimized to shorten the invoking time. +--- + CMakeLists.txt | 6 + + adler32.c | 169 +++++++++++++++++++++- + deflate.c | 22 ++- + inffast.c | 62 ++++++++- + inffast.h | 370 +++++++++++++++++++++++++++++++++++++++++++++++++ + inflate.c | 7 + + 6 files changed, 627 insertions(+), 9 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b412dc7..40dc533 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -126,6 +126,12 @@ if(NOT MINGW) + ) + endif() + ++if(CMAKE_COMPILER_IS_GNUCC) ++ if(ARM_NEON) ++ add_definitions(-DHASH_ARMV8_CRC32 -march=armv8-a+crc -DUNALIGNED_OK -DADLER32_SIMD_NEON -DINFLATE_CHUNK_SIMD_NEON -O3) ++ endif() ++endif() ++ + # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) + string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" +diff --git a/adler32.c b/adler32.c +index d0be438..6ced75d 100644 +--- a/adler32.c ++++ b/adler32.c +@@ -59,7 +59,169 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); + # define MOD63(a) a %= BASE + #endif + +-/* ========================================================================= */ ++#if defined(ADLER32_SIMD_NEON) ++#include <arm_neon.h> ++/* ++ * Multiply-add bytes by [ 32, 31, 30, ... ] for s2. ++ */ ++uint32x4_t ZLIB_INTERNAL mul_add_bytes( ++ uint32x4_t v_s2, ++ uint16x8_t v_column_sum_1, ++ uint16x8_t v_column_sum_2, ++ uint16x8_t v_column_sum_3, ++ uint16x8_t v_column_sum_4) ++{ ++ v_s2 = vshlq_n_u32(v_s2, 5); ++ ++ v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_1), ++ (uint16x4_t) { 32, 31, 30, 29 }); ++ v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1), ++ (uint16x4_t) { 28, 27, 26, 25 }); ++ v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_2), ++ (uint16x4_t) { 24, 23, 22, 21 }); ++ v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_2), ++ (uint16x4_t) { 20, 19, 18, 17 }); ++ v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_3), ++ (uint16x4_t) { 16, 15, 14, 13 }); ++ v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_3), ++ (uint16x4_t) { 12, 11, 10, 9 }); ++ v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_4), ++ (uint16x4_t) { 8, 7, 6, 5 }); ++ v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_4), ++ (uint16x4_t) { 4, 3, 2, 1 }); ++ return v_s2; ++} ++ ++/* ++ * Handle leftover data. ++ */ ++uLong ZLIB_INTERNAL leftover_handler(uint32_t s1, uint32_t s2, const Bytef *buf, z_size_t len) ++{ ++ if (len) { ++ if (len >= 16) { ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ s2 += (s1 += *buf++); ++ ++ len -= 16; ++ } ++ ++ while (len--) { ++ s2 += (s1 += *buf++); ++ } ++ ++ if (s1 >= BASE) ++ s1 -= BASE; ++ s2 %= BASE; ++ } ++ ++ /* ++ * Return the recombined sums. ++ */ ++ return s1 | (s2 << 16); ++} ++ ++uLong ZLIB_INTERNAL adler32_simd_(uLong adler, const Bytef *buf, z_size_t len) ++{ ++ /* ++ * Split Adler-32 into component sums. ++ */ ++ uint32_t s1 = adler & 0xffff; ++ uint32_t s2 = adler >> 16; ++ /* ++ * Serially compute s1 & s2, until the data is 16-byte aligned. ++ */ ++ if ((uintptr_t)buf & 0xf) { ++ while ((uintptr_t)buf & 0xf) { ++ s2 += (s1 += *buf++); ++ --len; ++ } ++ if (s1 >= BASE) ++ s1 -= BASE; ++ s2 %= BASE; ++ } ++ /* ++ * Process the data in blocks. ++ */ ++ const unsigned BLOCK_SIZE = 1 << 5; ++ z_size_t blocks = len / BLOCK_SIZE; ++ len -= blocks * BLOCK_SIZE; ++ while (blocks) { ++ unsigned n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */ ++ if (n > blocks) ++ n = (unsigned) blocks; ++ blocks -= n; ++ /* ++ * Process n blocks of data. At most NMAX data bytes can be ++ * processed before s2 must be reduced modulo BASE. ++ */ ++ uint32x4_t v_s2 = (uint32x4_t) { 0, 0, 0, s1 * n }; ++ uint32x4_t v_s1 = (uint32x4_t) { 0, 0, 0, 0 }; ++ ++ uint16x8_t v_column_sum_1 = vdupq_n_u16(0); ++ uint16x8_t v_column_sum_2 = vdupq_n_u16(0); ++ uint16x8_t v_column_sum_3 = vdupq_n_u16(0); ++ uint16x8_t v_column_sum_4 = vdupq_n_u16(0); ++ do { ++ /* ++ * Load 32 input bytes. ++ */ ++ const uint8x16_t bytes1 = vld1q_u8((uint8_t*)(buf)); ++ const uint8x16_t bytes2 = vld1q_u8((uint8_t*)(buf + 16)); ++ /* ++ * Add previous block byte sum to v_s2. ++ */ ++ v_s2 = vaddq_u32(v_s2, v_s1); ++ /* ++ * Horizontally add the bytes for s1. ++ */ ++ v_s1 = vpadalq_u16(v_s1, vpadalq_u8(vpaddlq_u8(bytes1), bytes2)); ++ /* ++ * Vertically add the bytes for s2. ++ */ ++ v_column_sum_1 = vaddw_u8(v_column_sum_1, vget_low_u8 (bytes1)); ++ v_column_sum_2 = vaddw_u8(v_column_sum_2, vget_high_u8(bytes1)); ++ v_column_sum_3 = vaddw_u8(v_column_sum_3, vget_low_u8 (bytes2)); ++ v_column_sum_4 = vaddw_u8(v_column_sum_4, vget_high_u8(bytes2)); ++ buf += BLOCK_SIZE; ++ } while (--n); ++ v_s2 = mul_add_bytes(v_s2, v_column_sum_1, v_column_sum_2, v_column_sum_3, v_column_sum_4); ++ /* ++ * Sum epi32 ints v_s1(s2) and accumulate in s1(s2). ++ */ ++ uint32x2_t sum1 = vpadd_u32(vget_low_u32(v_s1), vget_high_u32(v_s1)); ++ uint32x2_t sum2 = vpadd_u32(vget_low_u32(v_s2), vget_high_u32(v_s2)); ++ uint32x2_t s1s2 = vpadd_u32(sum1, sum2); ++ ++ s1 += vget_lane_u32(s1s2, 0); ++ s2 += vget_lane_u32(s1s2, 1); ++ /* ++ * Reduce. ++ */ ++ s1 %= BASE; ++ s2 %= BASE; ++ } ++ return leftover_handler(s1, s2, buf, len); ++ ++} ++#endif ++ + uLong ZEXPORT adler32_z(adler, buf, len) + uLong adler; + const Bytef *buf; +@@ -68,6 +230,11 @@ uLong ZEXPORT adler32_z(adler, buf, len) + unsigned long sum2; + unsigned n; + ++#if defined(ADLER32_SIMD_NEON) ++ if (buf && len >= 64) ++ return adler32_simd_(adler, buf, len); ++#endif ++ + /* split Adler-32 into component sums */ + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; +diff --git a/deflate.c b/deflate.c +index f290783..31d1cfe 100644 +--- a/deflate.c ++++ b/deflate.c +@@ -154,7 +154,16 @@ local const config configuration_table[10] = { + * characters, so that a running hash key can be computed from the previous + * key instead of complete recalculation each time. + */ +-#define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask) ++#if defined(HASH_ARMV8_CRC32) ++#include <arm_acle.h> ++#define UPDATE_HASH_CRC_INTERNAL(s, h, c) \ ++ (h = __crc32w(0, (c) & 0xFFFFFF) & ((deflate_state *)s)->hash_mask) ++ ++#define UPDATE_HASH(s, h, c) \ ++ UPDATE_HASH_CRC_INTERNAL(s, h, *(unsigned *)((uintptr_t)(&c) - (MIN_MATCH-1))) ++#else ++#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) ++#endif + + + /* =========================================================================== +@@ -1226,14 +1235,15 @@ local unsigned read_buf(strm, buf, size) + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); +- if (strm->state->wrap == 1) { +- strm->adler = adler32(strm->adler, buf, len); +- } + #ifdef GZIP +- else if (strm->state->wrap == 2) { ++ if (strm->state->wrap == 2) { /* use crc32 algo */ + strm->adler = crc32(strm->adler, buf, len); +- } ++ } else + #endif ++ if (strm->state->wrap == 1) { ++ strm->adler = adler32(strm->adler, buf, len); ++ } ++ + strm->next_in += len; + strm->total_in += len; + +diff --git a/inffast.c b/inffast.c +index 1fec7f3..84c5aba 100644 +--- a/inffast.c ++++ b/inffast.c +@@ -57,6 +57,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ + unsigned char FAR *out; /* local strm->next_out */ + unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ + unsigned char FAR *end; /* while out < end, enough space available */ ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ unsigned char FAR *limit; /* safety limit for chunky copies */ ++#endif + #ifdef INFLATE_STRICT + unsigned dmax; /* maximum distance from zlib header */ + #endif +@@ -89,7 +92,12 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ + #endif + wsize = state->wsize; + whave = state->whave; ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ limit = out + strm->avail_out; ++ wnext = (state->wnext == 0 && whave >= wsize) ? wsize : state->wnext; ++#else + wnext = state->wnext; ++#endif + window = state->window; + hold = state->hold; + bits = state->bits; +@@ -197,6 +205,45 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ + #endif + } + from = window; ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ if (wnext >= op) { /* contiguous in window */ ++ from += wnext - op; ++ } ++ else { /* wrap around window */ ++ op -= wnext; ++ from += wsize - op; ++ if (op < len) { /* some from end of window */ ++ len -= op; ++ out = chunkcopy_safe(out, from, op, limit); ++ from = window; /* more from start of window */ ++ op = wnext; ++ /* This (rare) case can create a situation where ++ the first chunkcopy below must be checked. ++ */ ++ } ++ } ++ if (op < len) { /* still need some from output */ ++ out = chunkcopy_safe(out, from, op, limit); ++ len -= op; ++ /* When dist is small the amount of data that can be ++ copied from the window is also small, and progress ++ towards the dangerous end of the output buffer is ++ also small. This means that for trivial memsets and ++ for chunkunroll_relaxed() a safety check is ++ unnecessary. However, these conditions may not be ++ entered at all, and in that case it's possible that ++ the main copy is near the end. ++ */ ++ out = chunkunroll_relaxed(out, &dist, &len); ++ out = chunkcopy_safe(out, out - dist, len, limit); ++ } ++ else { ++ /* from points to window, so there is no risk of ++ overlapping pointers requiring memset-like behaviour ++ */ ++ out = chunkcopy_safe(out, from, len, limit); ++ } ++#else + if (wnext == 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ +@@ -247,8 +294,18 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ + if (len > 1) + *out++ = *from++; + } ++#endif + } +- else { ++ else { ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ /* Whole reference is in range of current output. No ++ range checks are necessary because we start with room ++ for at least 258 bytes of output, so unroll and roundoff ++ operations can write beyond `out+len` so long as they ++ stay within 258 bytes of `out`. ++ */ ++ out = chunkcopy_lapped_relaxed(out, dist, len); ++#else + from = out - dist; /* copy direct from output */ + do { /* minimum length is three */ + *out++ = *from++; +@@ -260,7 +317,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ + *out++ = *from++; + if (len > 1) + *out++ = *from++; +- } ++ } ++#endif + } + } + else if ((op & 64) == 0) { /* 2nd level distance code */ +diff --git a/inffast.h b/inffast.h +index e5c1aa4..259882c 100644 +--- a/inffast.h ++++ b/inffast.h +@@ -8,4 +8,374 @@ + subject to change. Applications should only use zlib.h. + */ + ++/* ++ * The chunk-copy code below deals with writing the decoded DEFLATE data to ++ * the output with SIMD methods to increase decode speed. Reading the input ++ * to the DEFLATE decoder with a wide, SIMD method can also increase decode ++ * speed. This option is supported on little endian machines, and reads the ++ * input data in 64-bit (8 byte) chunks. ++ */ ++ + void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); ++ ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ ++#include <stdint.h> ++#include "zutil.h" ++#include <arm_neon.h> ++ ++typedef uint8x16_t z_vec128i_t; ++ ++#define Z_STATIC_ASSERT(name, assert) typedef char name[(assert) ? 1 : -1] ++ ++#if __STDC_VERSION__ >= 199901L ++#define Z_RESTRICT restrict ++#else ++#define Z_RESTRICT ++#endif ++ ++#if defined(__clang__) || defined(__GNUC__) || defined(__llvm__) ++#define Z_BUILTIN_MEMCPY __builtin_memcpy ++#else ++#define Z_BUILTIN_MEMCPY zmemcpy ++#endif ++ ++/* ++ * chunk copy type: the z_vec128i_t type size should be exactly 128-bits ++ * and equal to CHUNKCOPY_CHUNK_SIZE. ++ */ ++#define CHUNKCOPY_CHUNK_SIZE sizeof(z_vec128i_t) ++ ++Z_STATIC_ASSERT(vector_128_bits_wide, ++ CHUNKCOPY_CHUNK_SIZE == sizeof(int8_t) * 16); ++ ++/* ++ * Ask the compiler to perform a wide, unaligned load with a machinevst1q_u8 ++ * instruction appropriate for the z_vec128i_t type. ++ */ ++static inline z_vec128i_t loadchunk( ++ const unsigned char FAR* s) ++{ ++ z_vec128i_t v; ++ Z_BUILTIN_MEMCPY(&v, s, sizeof(v)); ++ return v; ++} ++ ++/* ++ * Ask the compiler to perform a wide, unaligned store with a machine ++ * instruction appropriate for the z_vec128i_t type. ++ */ ++static inline void storechunk( ++ unsigned char FAR* d, ++ const z_vec128i_t v) ++{ ++ Z_BUILTIN_MEMCPY(d, &v, sizeof(v)); ++} ++ ++/* ++ * Perform a memcpy-like operation, assuming that length is non-zero and that ++ * it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if ++ * the length is shorter than this. ++ * ++ * It also guarantees that it will properly unroll the data if the distance ++ * between `out` and `from` is at least CHUNKCOPY_CHUNK_SIZE, which we rely on ++ * in chunkcopy_relaxed(). ++ * ++ * Aside from better memory bus utilisation, this means that short copies ++ * (CHUNKCOPY_CHUNK_SIZE bytes or fewer) will fall straight through the loop ++ * without iteration, which will hopefully make the branch prediction more ++ * reliable. ++ */ ++static inline unsigned char FAR* chunkcopy_core( ++ unsigned char FAR* out, ++ const unsigned char FAR* from, ++ unsigned len) ++{ ++ const int bump = (--len % CHUNKCOPY_CHUNK_SIZE) + 1; ++ storechunk(out, loadchunk(from)); ++ out += bump; ++ from += bump; ++ len /= CHUNKCOPY_CHUNK_SIZE; ++ while (len-- > 0) { ++ storechunk(out, loadchunk(from)); ++ out += CHUNKCOPY_CHUNK_SIZE; ++ from += CHUNKCOPY_CHUNK_SIZE; ++ } ++ return out; ++} ++ ++/* ++ * Like chunkcopy_core(), but avoid writing beyond of legal output. ++ * ++ * Accepts an additional pointer to the end of safe output. A generic safe ++ * copy would use (out + len), but it's normally the case that the end of the ++ * output buffer is beyond the end of the current copy, and this can still be ++ * exploited. ++ */ ++static inline unsigned char FAR* chunkcopy_core_safe( ++ unsigned char FAR* out, ++ const unsigned char FAR* from, ++ unsigned len, ++ unsigned char FAR* limit) ++{ ++ Assert(out + len <= limit, "chunk copy exceeds safety limit"); ++ if ((limit - out) < (ptrdiff_t) CHUNKCOPY_CHUNK_SIZE) { ++ const unsigned char FAR* Z_RESTRICT rfrom = from; ++ if (len & 8) { ++ Z_BUILTIN_MEMCPY(out, rfrom, 8); ++ out += 8; ++ rfrom += 8; ++ } ++ if (len & 4) { ++ Z_BUILTIN_MEMCPY(out, rfrom, 4); ++ out += 4; ++ rfrom += 4; ++ } ++ if (len & 2) { ++ Z_BUILTIN_MEMCPY(out, rfrom, 2); ++ out += 2; ++ rfrom += 2; ++ } ++ if (len & 1) { ++ *out++ = *rfrom++; ++ } ++ return out; ++ } ++ return chunkcopy_core(out, from, len); ++} ++ ++/* ++ * Perform short copies until distance can be rewritten as being at least ++ * CHUNKCOPY_CHUNK_SIZE. ++ * ++ * Assumes it's OK to overwrite at least the first 2*CHUNKCOPY_CHUNK_SIZE ++ * bytes of output even if the copy is shorter than this. This assumption ++ * holds within zlib inflate_fast(), which starts every iteration with at ++ * least 258 bytes of output space available (258 being the maximum length ++ * output from a single token; see inffast.c). ++ */ ++static inline unsigned char FAR* chunkunroll_relaxed( ++ unsigned char FAR* out, ++ unsigned FAR* dist, ++ unsigned FAR* len) ++{ ++ const unsigned char FAR* from = out - *dist; ++ while (*dist < *len && *dist < CHUNKCOPY_CHUNK_SIZE) { ++ storechunk(out, loadchunk(from)); ++ out += *dist; ++ *len -= *dist; ++ *dist += *dist; ++ } ++ return out; ++} ++ ++/* ++ * v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in ++ * every 64-bit component of the 128-bit result (64-bit int splat). ++ */ ++static inline z_vec128i_t v_load64_dup(const void* src) ++{ ++ return vcombine_u8(vld1_u8(src), vld1_u8(src)); ++} ++ ++/* ++ * v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in ++ * every 32-bit component of the 128-bit result (32-bit int splat). ++ */ ++static inline z_vec128i_t v_load32_dup(const void* src) ++{ ++ int32_t i32; ++ Z_BUILTIN_MEMCPY(&i32, src, sizeof(i32)); ++ return vreinterpretq_u8_s32(vdupq_n_s32(i32)); ++} ++ ++/* ++ * v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in ++ * every 16-bit component of the 128-bit result (16-bit int splat). ++ */ ++static inline z_vec128i_t v_load16_dup(const void* src) ++{ ++ int16_t i16; ++ Z_BUILTIN_MEMCPY(&i16, src, sizeof(i16)); ++ return vreinterpretq_u8_s16(vdupq_n_s16(i16)); ++} ++ ++/* ++ * v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit ++ * component of the 128-bit result (8-bit int splat). ++ */ ++static inline z_vec128i_t v_load8_dup(const void* src) ++{ ++ return vld1q_dup_u8((const uint8_t*) src); ++} ++ ++/* ++ * v_store_128(): store the 128-bit vec in a memory destination (that might ++ * not be 16-byte aligned) void* out. ++ */ ++static inline void v_store_128(unsigned char* out, const z_vec128i_t vec) ++{ ++ vst1q_u8(out, vec); ++} ++ ++/* ++ * Perform an overlapping copy which behaves as a memset() operation, but ++ * supporting periods other than one, and assume that length is non-zero and ++ * that it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE*3 bytes of output ++ * even if the length is shorter than this. ++ */ ++static inline unsigned char FAR* chunkset_store_result( ++ unsigned len, ++ unsigned char FAR* out, ++ z_vec128i_t v) ++{ ++ do { ++ v_store_128(out, v); ++ out += sizeof(v); ++ len -= sizeof(v); ++ } while (len > 0); ++ return out; ++} ++ ++static inline unsigned char FAR* chunkset_core(unsigned char FAR* out, unsigned period, unsigned len) ++{ ++ z_vec128i_t v; ++ const int bump = ((len - 1) % sizeof(v)) + 1; ++ switch (period) { ++ case 1: ++ v = v_load8_dup(out - 1); ++ v_store_128(out, v); ++ out += bump; ++ len -= bump; ++ while (len > 0) { ++ v_store_128(out, v); ++ out += sizeof(v); ++ len -= sizeof(v); ++ } ++ return out; ++ case 2: ++ v = v_load16_dup(out - 2); ++ v_store_128(out, v); ++ out += bump; ++ len -= bump; ++ if (len > 0) { ++ v = v_load16_dup(out - 2); ++ out = chunkset_store_result(len, out, v); ++ } ++ return out; ++ case 4: ++ v = v_load32_dup(out - 4); ++ v_store_128(out, v); ++ out += bump; ++ len -= bump; ++ if (len > 0) { ++ v = v_load32_dup(out - 4); ++ out = chunkset_store_result(len, out, v); ++ } ++ return out; ++ case 8: ++ v = v_load64_dup(out - 8); ++ v_store_128(out, v); ++ out += bump; ++ len -= bump; ++ if (len > 0) { ++ v = v_load64_dup(out - 8); ++ out = chunkset_store_result(len, out, v); ++ } ++ return out; ++ } ++ out = chunkunroll_relaxed(out, &period, &len); ++ return chunkcopy_core(out, out - period, len); ++} ++ ++/* ++ * Perform a memcpy-like operation, but assume that length is non-zero and that ++ * it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if ++ * the length is shorter than this. ++ * ++ * Unlike chunkcopy_core() above, no guarantee is made regarding the behaviour ++ * of overlapping buffers, regardless of the distance between the pointers. ++ * This is reflected in the `restrict`-qualified pointers, allowing the ++ * compiler to re-order loads and stores. ++ */ ++static inline unsigned char FAR* chunkcopy_relaxed( ++ unsigned char FAR* Z_RESTRICT out, ++ const unsigned char FAR* Z_RESTRICT from, ++ unsigned len) ++{ ++ return chunkcopy_core(out, from, len); ++} ++ ++/* ++ * Like chunkcopy_relaxed(), but avoid writing beyond of legal output. ++ * ++ * Unlike chunkcopy_core_safe() above, no guarantee is made regarding the ++ * behaviour of overlapping buffers, regardless of the distance between the ++ * pointers. This is reflected in the `restrict`-qualified pointers, allowing ++ * the compiler to re-order loads and stores. ++ * ++ * Accepts an additional pointer to the end of safe output. A generic safe ++ * copy would use (out + len), but it's normally the case that the end of the ++ * output buffer is beyond the end of the current copy, and this can still be ++ * exploited. ++ */ ++static inline unsigned char FAR* chunkcopy_safe( ++ unsigned char FAR* out, ++ const unsigned char FAR* Z_RESTRICT from, ++ unsigned len, ++ unsigned char FAR* limit) ++{ ++ Assert(out + len <= limit, "chunk copy exceeds safety limit"); ++ return chunkcopy_core_safe(out, from, len, limit); ++} ++ ++/* ++ * Perform chunky copy within the same buffer, where the source and destination ++ * may potentially overlap. ++ * ++ * Assumes that len > 0 on entry, and that it's safe to write at least ++ * CHUNKCOPY_CHUNK_SIZE*3 bytes to the output. ++ */ ++static inline unsigned char FAR* chunkcopy_lapped_relaxed( ++ unsigned char FAR* out, ++ unsigned dist, ++ unsigned len) ++{ ++ if (dist < len && dist < CHUNKCOPY_CHUNK_SIZE) { ++ return chunkset_core(out, dist, len); ++ } ++ return chunkcopy_core(out, out - dist, len); ++} ++ ++/* ++ * Behave like chunkcopy_lapped_relaxed(), but avoid writing beyond of legal ++ * output. ++ * ++ * Accepts an additional pointer to the end of safe output. A generic safe ++ * copy would use (out + len), but it's normally the case that the end of the ++ * output buffer is beyond the end of the current copy, and this can still be ++ * exploited. ++ */ ++static inline unsigned char FAR* chunkcopy_lapped_safe( ++ unsigned char FAR* out, ++ unsigned dist, ++ unsigned len, ++ unsigned char FAR* limit) ++{ ++ Assert(out + len <= limit, "chunk copy exceeds safety limit"); ++ if ((limit - out) < (ptrdiff_t) (3 * CHUNKCOPY_CHUNK_SIZE)) { ++ while (len-- > 0) { ++ *out = *(out - dist); ++ out++; ++ } ++ return out; ++ } ++ return chunkcopy_lapped_relaxed(out, dist, len); ++} ++ ++ ++#undef Z_STATIC_ASSERT ++#undef Z_RESTRICT ++#undef Z_BUILTIN_MEMCPY ++ ++#endif //defined(INFLATE_CHUNK_SIMD_NEON) +diff --git a/inflate.c b/inflate.c +index 8acbef4..4e695b1 100644 +--- a/inflate.c ++++ b/inflate.c +@@ -408,9 +408,16 @@ unsigned copy; + + /* if it hasn't been done already, allocate space for the window */ + if (state->window == Z_NULL) { ++#if defined(INFLATE_CHUNK_SIMD_NEON) ++ unsigned wsize = 1U << state->wbits; ++ state->window = (unsigned char FAR *) ++ ZALLOC(strm, CHUNKCOPY_CHUNK_SIZE + wsize, ++ sizeof(unsigned char)); ++#else + state->window = (unsigned char FAR *) + ZALLOC(strm, 1U << state->wbits, + sizeof(unsigned char)); ++#endif + if (state->window == Z_NULL) return 1; + } + +-- +2.33.0 + diff --git a/zlib-Optimize-CRC32.patch b/zlib-Optimize-CRC32.patch new file mode 100644 index 0000000..16d66b4 --- /dev/null +++ b/zlib-Optimize-CRC32.patch @@ -0,0 +1,94 @@ +From 8935175266e343ac1d52106e2e790810b54f26c1 Mon Sep 17 00:00:00 2001 +From: liqiang64 <liqiang64@huawei.com> +Date: Tue, 3 Dec 2019 03:22:00 +0000 +Subject: [PATCH] zlib: Optimize CRC32 + +This patch uses the NEON instruction set to optimize the CRC32 +algorithm. + +On the ARM architecture, we can optimize the efficiency of +crc32 through the interface provided by the neon instruction +set. +Modify by Li Qiang. +--- + crc32.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +diff --git a/crc32.c b/crc32.c +index f8357b0..5c53068 100644 +--- a/crc32.c ++++ b/crc32.c +@@ -28,6 +28,9 @@ + #endif /* MAKECRCH */ + + #include "zutil.h" /* for Z_U4, Z_U8, z_crc_t, and FAR definitions */ ++#ifdef __aarch64__ ++#include "arm_acle.h" ++#endif + + /* + A CRC of a message is computed on N braids of words in the message, where +@@ -600,6 +603,49 @@ const z_crc_t FAR * ZEXPORT get_crc_table() + return (const z_crc_t FAR *)crc_table; + } + ++#ifdef __aarch64__ ++ulg crc32_neon(crc, buf, len) ++ unsigned long crc; ++ const unsigned char FAR *buf; ++ z_size_t len; ++{ ++ register uint32_t crc_result = 0xFFFFFFFFU; ++ register const uint8_t *buf1; ++ register const uint16_t *buf2; ++ register const uint32_t *buf4; ++ register const uint64_t *buf8; ++ int64_t length = (int64_t)len; ++ buf8 = (const uint64_t *)(const void *)buf; ++ ++ if (buf == NULL) { ++ crc_result = 0xffffffffL; ++ } else { ++ crc_result = crc^0xffffffffUL; ++ ++ while((length -= sizeof(uint64_t)) >= 0) { ++ crc_result = __crc32d((crc_result), *buf8++); ++ } ++ ++ buf4 = (const uint32_t *)(const void *)buf8; ++ if (length & sizeof(uint32_t)) { ++ crc_result = __crc32w((crc_result), *buf4++); ++ } ++ ++ buf2 = (const uint16_t *)(const void *)buf4; ++ if(length & sizeof(uint16_t)) { ++ crc_result = __crc32h((crc_result), *buf2++); ++ } ++ ++ buf1 = (const uint8_t *)(const void *)buf2; ++ if (length & sizeof(uint8_t)) { ++ crc_result = __crc32b((crc_result), *buf1); ++ } ++ } ++ ++ return (crc_result ^ 0xffffffffL); ++} ++#endif ++ + /* ========================================================================= + * Use ARM machine instructions if available. This will compute the CRC about + * ten times faster than the braided calculation. This code does not check for +@@ -750,6 +794,10 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) + const unsigned char FAR *buf; + z_size_t len; + { ++ #ifdef __aarch64__ ++ return crc32_neon(crc, buf, len); ++ #endif ++ + /* Return initial CRC, if requested. */ + if (buf == Z_NULL) return 0; + +-- +2.27.0 + diff --git a/zlib.spec b/zlib.spec new file mode 100644 index 0000000..dfc333a --- /dev/null +++ b/zlib.spec @@ -0,0 +1,180 @@ +Name: zlib +Version: 1.2.13 +Release: 5 +Summary: A lossless data-compression library +License: zlib and Boost +URL: http://www.zlib.net +Source0: http://www.zlib.net/zlib-%{version}.tar.xz + +# Patch0 get from fedora +Patch6000: backport-zlib-1.2.5-minizip-fixuncrypt.patch +Patch6001: backport-CVE-2023-45853.patch +Patch6002: backport-Fix-crash-when-gzsetparams-attempted-for-transparent-write.patch +Patch6003: backport-Remove-use-of-OF-from-contrib-untgz-and-render-it-compilable.patch +Patch6004: backport-minizip-Fix-being-unable-to-open-empty-zip-file.patch +Patch6005: backport-Fix-reading-disk-number-start-on-zip64-files-in-minizip.patch +Patch6006: backport-Fix-logic-error-in-minizip-argument-processing.patch +Patch6007: backport-Fix-bug-when-gzungetc-is-used-immediately-after-gzopen.patch +Patch6008: backport-Suppress-MSAN-detections-in-deflate-slide_hash.patch +Patch6009: backport-Fix-bug-when-using-gzflush-with-a-very-small-buffer.patch +Patch6010: backport-avoid-uninitialized-and-unused-warnings-in-contrib-minizip.patch +Patch6011: backport-Add-bounds-checking-to-ERR_MSG-macro-used-by-zError.patch +Patch6012: backport-Fix-bug-in-inflateSync-for-data-held-in-bit-buffer.patch +Patch6013: backport-Fix-decision-on-the-emission-of-Zip64-end-records-in.patch +Patch6014: backport-Neutralize-zip-file-traversal-attacks-in-miniunz.patch +Patch6015: backport-Fix-a-bug-in-ZLIB_DEBUG-compiles-in-check_match.patch +Patch6016: backport-CVE-2026-27171.patch + +Patch9000: zlib-Optimize-CRC32.patch +Patch9001: zlib-1.2.11-SIMD.patch + +BuildRequires: automake, autoconf, libtool + +%description +Zlib is a free, general-purpose, not covered by any patents, lossless data-compression +library for use on virtually any computer hardware and operating system. The zlib data +format is itself portable across platforms. + +%package devel +Summary: Header files and libraries for Zlib development +Requires: %{name} = %{version}-%{release} + +Provides: zlib-static +Obsoletes: zlib-static + +%description devel +This package contains the static library, the header files, the tests user case and other +development content. + +%package help +Summary: Help documentation related to zlib +BuildArch: noarch + +%description help +This package includes help documentation and manuals related to zlib. + +%package -n minizip +Summary: Encapsulates the operations related to zip files +Requires: %{name} = %{version}-%{release} + +%description -n minizip +Minizip is the upper library of zlib, which encapsulates the operations related to zip files. + +%package -n minizip-devel +Summary: The development-related content related to minizip +Requires: minizip = %{version}-%{release} +Requires: %{name}-devel = %{version}-%{release} + +%description -n minizip-devel +This package contains the development-related content related to minizip. + +%prep +%setup -n %{name}-%{version} +%autosetup -b 0 -n %{name}-%{version} -p1 + +%build +export CFLAGS="$RPM_OPT_FLAGS" +%ifarch aarch64 +CFLAGS+=" -march=armv8-a+crc" +%endif + +./configure --libdir=%{_libdir} --includedir=%{_includedir} --prefix=%{_prefix} +%make_build LDFLAGS="$LDFLAGS -Wl,-z,relro -Wl,-z,now" + +cd contrib/minizip +autoreconf --install +%configure --enable-static=no +%make_build + +%install +%make_install + +%make_install -C contrib/minizip +rm -f $RPM_BUILD_ROOT%_includedir/minizip/crypt.h + +find $RPM_BUILD_ROOT -name '*.la' | xargs rm -f + +%check +make test + +%files +%defattr(-,root,root) +%doc README ChangeLog FAQ +%{_libdir}/libz.so.* + +%files devel +%doc doc/algorithm.txt test/example.c +%{_includedir}/zlib.h +%{_includedir}/zconf.h + +%{_libdir}/libz.so +%{_libdir}/pkgconfig/zlib.pc +%{_libdir}/libz.a + +%files help +%{_mandir}/man3/zlib.3* + +%files -n minizip +%doc contrib/minizip/MiniZip64_info.txt contrib/minizip/MiniZip64_Changes.txt +%{_libdir}/libminizip.so.* + + +%files -n minizip-devel +%dir %{_includedir}/minizip +%{_includedir}/minizip/*.h + +%{_libdir}/libminizip.so +%{_libdir}/pkgconfig/minizip.pc + +%changelog +* Wed Feb 25 2026 liweigang <liweiganga@gmail.com> - 1.2.13-5 +- fix CVE-2026-27171 + +* Tue Aug 13 2024 yanglongkang <yanglongkang@h-partners.com> - 1.2.13-4 +- backport patches from upstream + +* Tue Jun 18 2024 zhoupengcheng <zhoupengcheng11@huawei.com> - 1.2.13-3 +- delete redundant patch + +* Tue May 14 2024 zhoupengcheng <zhoupengcheng11@huawei.com> - 1.2.13-2 +- downgrade to zlib-1.2.13 + +* Wed Feb 21 2024 liweigang <izmirvii@gmail.com> - 1.3.1-1 +- update to version zlib-1.3.1 + +* Tue Oct 17 2023 liningjie <liningjie@xfusion.com> - 1.2.13-2 +- DESC:Fix CVE-2023-45853 + +* Thu Dec 29 2022 zhoupengcheng <zhoupengcheng11@huawei.com> - 1.2.13-1 +- update to zlib-1.2.13 +- remove openEuler uncompiled patch : 0005-Accelerate-Adler32-using-arm64-SVE-instructions.patch + +* Mon Dec 26 2022 zhoupengcheng <zhoupengcheng11@huawei.com> - 1.2.11-24 +- DESC:remove unapplied patches + +* Tue Aug 23 2022 shixuantong <shixuantong@h-partners.com> - 1.2.11-23 +- Fix missing patches due to different arch + +* Fri Aug 12 2022 dongyuzhen <dongyuzhen@h-partners.com> - 1.2.11-22 +- fix CVE-2022-37434 + +* Mon Apr 18 2022 tianwei <tianwei12@h-partners.com> - 1.2.11-21 +- modify patch info for CVE-2018-25032 + +* Wed Apr 13 2022 tianwei <tianwei12@h-partners.com> - 1.2.11-20 +- fix CVE-2018-25032 + +* Thu Sep 2 2021 liqiang <liqiang64@huawei.com> - 1.2.11-19 +- Optimize Adler32 by SVE instructions. + +* Mon Sep 14 2020 noah <hedongbo@huawei.com> - 1.2.11-18 +- add zlib-1.2.11-SIMD.patch + +* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.2.11-17 +- Fix undefined buffer detected by oss-fuzz + +* Tue Dec 3 2019 liqiang <liqiang64@huawei.com> - 1.2.11-16 +- Optimize CRC32 by NEON + +* Thu Sep 5 2019 dongjian <dongjian13@huawei.com> - 1.2.11-15 +- Rebuild the zlib and fix description |
