Browse Source

update release 39

Signed-off-by: Toshaan Bharvani <toshaan@powerel.org>
master
Toshaan Bharvani 11 months ago
parent
commit
b3cd5e9533
  1. 2494
      SOURCES/zlib-1.2.11-Add-Power8-optimized-crc32.patch
  2. 73
      SOURCES/zlib-1.2.11-Fix-broken-libxml2-for-python311.patch
  3. 54
      SOURCES/zlib-1.2.11-Fix-clang-s-behavior-on-versions-7.patch
  4. 90
      SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch
  5. 11
      SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-strm-adler-fix.patch
  6. 299
      SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-inflate-small-window.patch
  7. 69
      SOURCES/zlib-1.2.11-Limit-hash-table-inserts.patch
  8. 282
      SOURCES/zlib-1.2.11-Preparation-for-Power-optimizations.patch
  9. 49
      SOURCES/zlib-1.2.11-covscan-issues.patch
  10. 35
      SOURCES/zlib-1.2.11-cve-2022-37434.patch
  11. 32
      SOURCES/zlib-1.2.11-cve-2022-37434_2.patch
  12. 171
      SOURCES/zlib-1.2.11-s390x-vectorize-crc32.patch
  13. 83
      SPECS/zlib.spec

2494
SOURCES/zlib-1.2.11-Add-Power8-optimized-crc32.patch

File diff suppressed because it is too large Load Diff

73
SOURCES/zlib-1.2.11-Fix-broken-libxml2-for-python311.patch

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
From 5eaae2af0defeca148c2a281873bb31a15246876 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:34:24 +0100
Subject: [PATCH] 2155328

---
contrib/s390/dfltcc.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c
index 72099e7..f8dc21c 100644
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -456,7 +456,10 @@ again:
*strm->next_out = (Bytef)state->bi_buf;
/* Honor history and check value */
param->nt = 0;
- param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
+ if (state->wrap == 1)
+ param->cv = strm->adler;
+ else if (state->wrap == 2)
+ param->cv = ZSWAP32(strm->adler);
/* When opening a block, choose a Huffman-Table Type */
if (!param->bcf) {
@@ -488,7 +491,10 @@ again:
state->bi_buf = 0; /* Avoid accessing next_out */
else
state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1);
- strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv;
+ if (state->wrap == 1)
+ strm->adler = param->cv;
+ else if (state->wrap == 2)
+ strm->adler = ZSWAP32(param->cv);
/* Unmask the input data */
strm->avail_in += masked_avail_in;
@@ -600,11 +606,12 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
}
/* Translate stream to parameter block */
- param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32;
+ param->cvt = ((state->wrap & 4) && state->flags) ? CVT_CRC32 : CVT_ADLER32;
param->sbb = state->bits;
if (param->hl)
param->nt = 0; /* Honor history for the first block */
- param->cv = state->flags ? ZSWAP32(state->check) : state->check;
+ if (state->wrap & 4)
+ param->cv = state->flags ? ZSWAP32(state->check) : state->check;
/* Inflate */
do {
@@ -615,7 +622,9 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
state->last = cc == DFLTCC_CC_OK;
state->bits = param->sbb;
- strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
+ if (state->wrap & 4)
+ strm->adler = state->check = state->flags ?
+ ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
state->mode = BAD;
@@ -1077,4 +1086,4 @@ int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(strm, dictionary, dict_length)
if (dict_length)
*dict_length = param->hl;
return Z_OK;
-}
\ No newline at end of file
+}
--
2.39.1

54
SOURCES/zlib-1.2.11-Fix-clang-s-behavior-on-versions-7.patch

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
From 480b65cae6c20a41aa698a6c9d3b260f6f744004 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:41:32 +0100
Subject: [PATCH] 0003-PATCH-Fix-clang-s-behavior-on-versions-7.patch

---
contrib/power/clang_workaround.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/contrib/power/clang_workaround.h b/contrib/power/clang_workaround.h
index b5e7dae..915f7e5 100644
--- a/contrib/power/clang_workaround.h
+++ b/contrib/power/clang_workaround.h
@@ -39,7 +39,12 @@ __vector unsigned long long __builtin_pack_vector (unsigned long __a,
return __v;
}
-#ifndef vec_xxpermdi
+/*
+ * Clang 7 changed the behavior of vec_xxpermdi in order to provide the same
+ * behavior of GCC. That means code adapted to Clang >= 7 does not work on
+ * Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6.
+ */
+#if !defined vec_xxpermdi || __clang_major__ <= 6
static inline
unsigned long __builtin_unpack_vector (__vector unsigned long long __v,
@@ -62,9 +67,9 @@ static inline
unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
- return vec_xxpermdi(__v, __v, 0x0)[1];
- #else
return vec_xxpermdi(__v, __v, 0x0)[0];
+ #else
+ return vec_xxpermdi(__v, __v, 0x3)[0];
#endif
}
@@ -72,9 +77,9 @@ static inline
unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
- return vec_xxpermdi(__v, __v, 0x3)[1];
- #else
return vec_xxpermdi(__v, __v, 0x3)[0];
+ #else
+ return vec_xxpermdi(__v, __v, 0x0)[0];
#endif
}
#endif /* vec_xxpermdi */
--
2.39.1

90
SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
--- a/compress.c
+++ b/compress.c
@@ -5,9 +5,15 @@
/* @(#) $Id$ */
-#define ZLIB_INTERNAL
+#include "zutil.h"
#include "zlib.h"
+#ifdef DFLTCC
+# include "contrib/s390/dfltcc.h"
+#else
+#define DEFLATE_BOUND_COMPLEN(source_len) 0
+#endif
+
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
@@ -81,6 +87,12 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen;
{
+ uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen);
+
+ if (complen > 0)
+ /* Architecture-specific code provided an upper bound. */
+ return complen + ZLIB_WRAPLEN;
+
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13;
}
--- a/contrib/s390/dfltcc.h
+++ b/contrib/s390/dfltcc.h
@@ -12,6 +12,28 @@ void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
uInt size));
void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
+#define DFLTCC_BLOCK_HEADER_BITS 3
+#define DFLTCC_HLITS_COUNT_BITS 5
+#define DFLTCC_HDISTS_COUNT_BITS 5
+#define DFLTCC_HCLENS_COUNT_BITS 4
+#define DFLTCC_MAX_HCLENS 19
+#define DFLTCC_HCLEN_BITS 3
+#define DFLTCC_MAX_HLITS 286
+#define DFLTCC_MAX_HDISTS 30
+#define DFLTCC_MAX_HLIT_HDIST_BITS 7
+#define DFLTCC_MAX_SYMBOL_BITS 16
+#define DFLTCC_MAX_EOBS_BITS 15
+#define DFLTCC_MAX_PADDING_BITS 7
+#define DEFLATE_BOUND_COMPLEN(source_len) \
+ ((DFLTCC_BLOCK_HEADER_BITS + \
+ DFLTCC_HLITS_COUNT_BITS + \
+ DFLTCC_HDISTS_COUNT_BITS + \
+ DFLTCC_HCLENS_COUNT_BITS + \
+ DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
+ (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
+ (source_len) * DFLTCC_MAX_SYMBOL_BITS + \
+ DFLTCC_MAX_EOBS_BITS + \
+ DFLTCC_MAX_PADDING_BITS) >> 3)
int ZLIB_INTERNAL dfltcc_can_inflate OF((z_streamp strm));
typedef enum {
DFLTCC_INFLATE_CONTINUE,
diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h
index 03f7f53..46acfc5 100644
--- a/contrib/s390/dfltcc_deflate.h
+++ b/contrib/s390/dfltcc_deflate.h
@@ -46,8 +46,7 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm,
#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
do { \
if (dfltcc_can_deflate((strm))) \
- (complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
- (source_len) * 16 + 15 + 7) >> 3; \
+ (complen) = DEFLATE_BOUND_COMPLEN(source_len); \
} while (0)
#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
#define DEFLATE_HOOK dfltcc_deflate
diff --git a/zutil.h b/zutil.h
index 14277bc..cf90e49 100644
--- a/zutil.h
+++ b/zutil.h
@@ -87,6 +87,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+#define ZLIB_WRAPLEN 6 /* zlib format overhead */
+
/* target dependencies */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))

11
SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-strm-adler-fix.patch

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -623,7 +623,7 @@
state->bits = param->sbb;
state->whave = param->hl;
state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
- state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
+ strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
state->mode = BAD;

299
SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-inflate-small-window.patch

@ -0,0 +1,299 @@ @@ -0,0 +1,299 @@
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -539,10 +539,6 @@ int ZLIB_INTERNAL dfltcc_can_inflate(strm)
struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
- /* Unsupported compression settings */
- if (state->wbits != HB_BITS)
- return 0;
-
/* Unsupported hardware */
return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) &&
is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0);
@@ -606,8 +602,6 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
/* Translate stream to parameter block */
param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32;
param->sbb = state->bits;
- param->hl = state->whave; /* Software and hardware history formats match */
- param->ho = (state->wnext - state->whave) & ((1 << HB_BITS) - 1);
if (param->hl)
param->nt = 0; /* Honor history for the first block */
param->cv = state->flags ? ZSWAP32(state->check) : state->check;
@@ -621,8 +615,6 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
state->last = cc == DFLTCC_CC_OK;
state->bits = param->sbb;
- state->whave = param->hl;
- state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
@@ -644,11 +636,52 @@ int ZLIB_INTERNAL dfltcc_was_inflate_used(strm)
return !param->nt;
}
+/*
+ Rotates a circular buffer.
+ The implementation is based on https://cplusplus.com/reference/algorithm/rotate/
+ */
+local void rotate OF((Bytef *start, Bytef *pivot, Bytef *end));
+local void rotate(start, pivot, end)
+ Bytef *start;
+ Bytef *pivot;
+ Bytef *end;
+{
+ Bytef *p = pivot;
+ Bytef tmp;
+
+ while (p != start) {
+ tmp = *start;
+ *start = *p;
+ *p = tmp;
+
+ start++;
+ p++;
+
+ if (p == end)
+ p = pivot;
+ else if (start == pivot)
+ pivot = p;
+ }
+}
+
+#define MIN(x, y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ _x < _y ? _x : _y; \
+})
+
+#define MAX(x, y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ _x > _y ? _x : _y; \
+})
+
int ZLIB_INTERNAL dfltcc_inflate_disable(strm)
z_streamp strm;
{
struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
if (!dfltcc_can_inflate(strm))
return 0;
@@ -660,6 +693,9 @@ int ZLIB_INTERNAL dfltcc_inflate_disable(strm)
return 1;
/* DFLTCC was not used yet - decompress in software */
memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
+ /* Convert the window from the hardware to the software format */
+ rotate(state->window, state->window + param->ho, state->window + HB_SIZE);
+ state->whave = state->wnext = MIN(param->hl, state->wsize);
return 0;
}
@@ -830,9 +866,9 @@ voidpf ZLIB_INTERNAL dfltcc_alloc_window(strm, items, size)
voidpf p, w;
/* To simplify freeing, we store the pointer to the allocated buffer right
- * before the window.
+ * before the window. Note that DFLTCC always uses HB_SIZE bytes.
*/
- p = ZALLOC(strm, sizeof(voidpf) + items * size + PAGE_ALIGN,
+ p = ZALLOC(strm, sizeof(voidpf) + MAX(items * size, HB_SIZE) + PAGE_ALIGN,
sizeof(unsigned char));
if (p == NULL)
return NULL;
@@ -841,6 +877,14 @@ voidpf ZLIB_INTERNAL dfltcc_alloc_window(strm, items, size)
return w;
}
+void ZLIB_INTERNAL dfltcc_copy_window(dest, src, n)
+ void *dest;
+ const void *src;
+ size_t n;
+{
+ memcpy(dest, src, MAX(n, HB_SIZE));
+}
+
void ZLIB_INTERNAL dfltcc_free_window(strm, w)
z_streamp strm;
voidpf w;
@@ -951,6 +995,24 @@ local void append_history(param, history, buf, count)
}
}
+local void get_history OF((struct dfltcc_param_v0 FAR *param,
+ const Bytef *history,
+ Bytef *buf));
+local void get_history(param, history, buf)
+ struct dfltcc_param_v0 FAR *param;
+ const Bytef *history;
+ Bytef *buf;
+{
+ if (param->ho + param->hl <= HB_SIZE)
+ /* Circular history buffer does not wrap - copy one chunk */
+ memcpy(buf, history + param->ho, param->hl);
+ else {
+ /* Circular history buffer wraps - copy two chunks */
+ memcpy(buf, history + param->ho, HB_SIZE - param->ho);
+ memcpy(buf + HB_SIZE - param->ho, history, param->ho + param->hl - HB_SIZE);
+ }
+}
+
int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(strm, dictionary, dict_length)
z_streamp strm;
const Bytef *dictionary;
@@ -975,20 +1037,43 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(strm, dictionary, dict_length)
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 FAR *param = &dfltcc_state->param;
- if (dictionary) {
- if (param->ho + param->hl <= HB_SIZE)
- /* Circular history buffer does not wrap - copy one chunk */
- zmemcpy(dictionary, state->window + param->ho, param->hl);
- else {
- /* Circular history buffer wraps - copy two chunks */
- zmemcpy(dictionary,
- state->window + param->ho,
- HB_SIZE - param->ho);
- zmemcpy(dictionary + HB_SIZE - param->ho,
- state->window,
- param->ho + param->hl - HB_SIZE);
- }
+ if (dictionary)
+ get_history(param, state->window, dictionary);
+ if (dict_length)
+ *dict_length = param->hl;
+ return Z_OK;
+}
+
+int ZLIB_INTERNAL dfltcc_inflate_set_dictionary(strm, dictionary, dict_length)
+ z_streamp strm;
+ const Bytef *dictionary;
+ uInt dict_length;
+{
+ struct inflate_state *state = (struct inflate_state *)strm->state;
+ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
+
+ if (inflate_ensure_window(state)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
}
+
+ append_history(param, state->window, dictionary, dict_length);
+ state->havedict = 1;
+ return Z_OK;
+}
+
+int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(strm, dictionary, dict_length)
+ z_streamp strm;
+ Bytef *dictionary;
+ uInt *dict_length;
+{
+ struct inflate_state *state = (struct inflate_state *)strm->state;
+ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
+
+ if (dictionary && state->window)
+ get_history(param, state->window, dictionary);
if (dict_length)
*dict_length = param->hl;
return Z_OK;
--- a/contrib/s390/dfltcc.h
+++ b/contrib/s390/dfltcc.h
@@ -11,6 +11,8 @@ void ZLIB_INTERNAL dfltcc_copy_state OF((voidpf dst, const voidpf src,
void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
uInt size));
+void ZLIB_INTERNAL dfltcc_copy_window OF((void *dest, const void *src,
+ size_t n));
void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
#define DFLTCC_BLOCK_HEADER_BITS 3
#define DFLTCC_HLITS_COUNT_BITS 5
@@ -44,11 +46,18 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate OF((z_streamp strm,
int flush, int *ret));
int ZLIB_INTERNAL dfltcc_was_inflate_used OF((z_streamp strm));
int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm));
+int ZLIB_INTERNAL dfltcc_inflate_set_dictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dict_length));
+int ZLIB_INTERNAL dfltcc_inflate_get_dictionary OF((z_streamp strm,
+ Bytef *dictionary,
+ uInt* dict_length));
#define ZALLOC_STATE dfltcc_alloc_state
#define ZFREE_STATE ZFREE
#define ZCOPY_STATE dfltcc_copy_state
#define ZALLOC_WINDOW dfltcc_alloc_window
+#define ZCOPY_WINDOW dfltcc_copy_window
#define ZFREE_WINDOW dfltcc_free_window
#define TRY_FREE_WINDOW dfltcc_free_window
#define INFLATE_RESET_KEEP_HOOK(strm) \
@@ -77,5 +86,15 @@ int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm));
do { \
if (dfltcc_was_inflate_used((strm))) return Z_STREAM_ERROR; \
} while (0)
+#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \
+ do { \
+ if (dfltcc_can_inflate(strm)) \
+ return dfltcc_inflate_set_dictionary(strm, dict, dict_len); \
+ } while (0)
+#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \
+ do { \
+ if (dfltcc_can_inflate(strm)) \
+ return dfltcc_inflate_get_dictionary(strm, dict, dict_len); \
+ } while (0)
#endif
\ No newline at end of file
diff --git a/inflate.c b/inflate.c
index 3750152..a0e2169 100644
--- a/inflate.c
+++ b/inflate.c
@@ -93,6 +93,7 @@
#define ZFREE_STATE ZFREE
#define ZCOPY_STATE zmemcpy
#define ZALLOC_WINDOW ZALLOC
+#define ZCOPY_WINDOW zmemcpy
#define ZFREE_WINDOW ZFREE
#define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
#define INFLATE_PRIME_HOOK(strm, bits, value) do {} while (0)
@@ -101,6 +102,8 @@
#define INFLATE_NEED_UPDATEWINDOW(strm) 1
#define INFLATE_MARK_HOOK(strm) do {} while (0)
#define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0)
+#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
+#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
#endif
#ifdef MAKEFIXED
@@ -1330,6 +1333,8 @@ uInt *dictLength;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
+ INFLATE_GET_DICTIONARY_HOOK(strm, dictionary, dictLength);
+
/* copy dictionary */
if (state->whave && dictionary != Z_NULL) {
zmemcpy(dictionary, state->window + state->wnext,
@@ -1365,6 +1370,8 @@ uInt dictLength;
return Z_DATA_ERROR;
}
+ INFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength);
+
/* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */
ret = updatewindow(strm, dictionary + dictLength, dictLength);
@@ -1529,8 +1536,7 @@ z_streamp source;
}
copy->next = copy->codes + (state->next - state->codes);
if (window != Z_NULL) {
- wsize = 1U << state->wbits;
- zmemcpy(window, state->window, wsize);
+ ZCOPY_WINDOW(window, state->window, 1U << state->wbits);
}
copy->window = window;
dest->state = (struct internal_state FAR *)copy;

69
SOURCES/zlib-1.2.11-Limit-hash-table-inserts.patch

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
From 2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0 Mon Sep 17 00:00:00 2001
From: Mark Adler <madler@alumni.caltech.edu>
Date: Sat, 21 Jan 2017 01:50:26 -0800
Subject: [PATCH] Limit hash table inserts after switch from stored deflate.

This limits hash table inserts to the available data in the window
and to the sliding window size in deflate_stored(). The hash table
inserts are deferred until deflateParams() switches to a non-zero
compression level.
---
deflate.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/deflate.c b/deflate.c
index 20bda4f..d368b25 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1513,6 +1513,8 @@ local void fill_window(s)
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
@@ -1742,6 +1744,7 @@ local block_state deflate_stored(s, flush)
s->matches = 2; /* clear hash */
zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
s->strstart = s->w_size;
+ s->insert = s->strstart;
}
else {
if (s->window_size - s->strstart <= used) {
@@ -1750,12 +1753,14 @@ local block_state deflate_stored(s, flush)
zmemcpy(s->window, s->window + s->w_size, s->strstart);
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
}
zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
s->strstart += used;
+ s->insert += MIN(used, s->w_size - s->insert);
}
s->block_start = s->strstart;
- s->insert += MIN(used, s->w_size - s->insert);
}
if (s->high_water < s->strstart)
s->high_water = s->strstart;
@@ -1779,12 +1784,15 @@ local block_state deflate_stored(s, flush)
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
have += s->w_size; /* more space now */
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
}
if (have > s->strm->avail_in)
have = s->strm->avail_in;
if (have) {
read_buf(s->strm, s->window + s->strstart, have);
s->strstart += have;
+ s->insert += MIN(have, s->w_size - s->insert);
}
if (s->high_water < s->strstart)
s->high_water = s->strstart;
--
2.39.1

282
SOURCES/zlib-1.2.11-Preparation-for-Power-optimizations.patch

@ -0,0 +1,282 @@ @@ -0,0 +1,282 @@
From 14730a26e830eb2b09d1f7097910616f23c1476e Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:40:32 +0100
Subject: [PATCH] 0001-PATCH-Preparation-for-Power-optimizations.patch

---
CMakeLists.txt | 67 ++++++++++++++++++++++++++++++++++++++++++
configure | 66 +++++++++++++++++++++++++++++++++++++++++
contrib/README.contrib | 8 +++++
contrib/gcc/zifunc.h | 60 +++++++++++++++++++++++++++++++++++++
contrib/power/power.h | 4 +++
5 files changed, 205 insertions(+)
create mode 100644 contrib/gcc/zifunc.h
create mode 100644 contrib/power/power.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fe939d..e762023 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,7 @@ set(VERSION "1.2.11")
option(ASM686 "Enable building i686 assembly implementation")
option(AMD64 "Enable building amd64 assembly implementation")
+option(POWER "Enable building power implementation")
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
@@ -140,6 +141,72 @@ if(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-DASMV)
set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
endif()
+
+ # test to see if we can use a GNU indirect function to detect and load optimized code at runtime
+ CHECK_C_SOURCE_COMPILES("
+ static int test_ifunc_native(void)
+ {
+ return 1;
+ }
+ static int (*(check_ifunc_native(void)))(void)
+ {
+ return test_ifunc_native;
+ }
+ int test_ifunc(void) __attribute__ ((ifunc (\"check_ifunc_native\")));
+ int main(void)
+ {
+ return 0;
+ }
+ " HAS_C_ATTR_IFUNC)
+
+ if(HAS_C_ATTR_IFUNC)
+ add_definitions(-DHAVE_IFUNC)
+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/gcc/zifunc.h)
+ endif()
+
+ if(POWER)
+ # Test to see if we can use the optimizations for Power
+ CHECK_C_SOURCE_COMPILES("
+ #ifndef _ARCH_PPC
+ #error \"Target is not Power\"
+ #endif
+ #ifndef __BUILTIN_CPU_SUPPORTS__
+ #error \"Target doesn't support __builtin_cpu_supports()\"
+ #endif
+ int main() { return 0; }
+ " HAS_POWER_SUPPORT)
+
+ if(HAS_POWER_SUPPORT AND HAS_C_ATTR_IFUNC)
+ add_definitions(-DZ_POWER_OPT)
+
+ set(CMAKE_REQUIRED_FLAGS -mcpu=power8)
+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER8)
+
+ if(POWER8)
+ add_definitions(-DZ_POWER8)
+ set(ZLIB_POWER8 )
+
+ set_source_files_properties(
+ ${ZLIB_POWER8}
+ PROPERTIES COMPILE_FLAGS -mcpu=power8)
+ endif()
+
+ set(CMAKE_REQUIRED_FLAGS -mcpu=power9)
+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER9)
+
+ if(POWER9)
+ add_definitions(-DZ_POWER9)
+ set(ZLIB_POWER9 )
+
+ set_source_files_properties(
+ ${ZLIB_POWER9}
+ PROPERTIES COMPILE_FLAGS -mcpu=power9)
+ endif()
+
+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/power/power.h)
+ set(ZLIB_SRCS ${ZLIB_SRCS} ${ZLIB_POWER8} ${ZLIB_POWER9})
+ endif()
+ endif()
endif()
if(MSVC)
diff --git a/configure b/configure
index d026b35..0538d58 100755
--- a/configure
+++ b/configure
@@ -846,6 +846,72 @@ else
echo "Checking for sys/sdt.h ... No." | tee -a configure.log
fi
+# test to see if we can use a gnu indirection function to detect and load optimized code at runtime
+echo >> configure.log
+cat > $test.c <<EOF
+static int test_ifunc_native(void)
+{
+ return 1;
+}
+
+static int (*(check_ifunc_native(void)))(void)
+{
+ return test_ifunc_native;
+}
+
+int test_ifunc(void) __attribute__ ((ifunc ("check_ifunc_native")));
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ SFLAGS="${SFLAGS} -DHAVE_IFUNC"
+ CFLAGS="${CFLAGS} -DHAVE_IFUNC"
+ echo "Checking for attribute(ifunc) support... Yes." | tee -a configure.log
+else
+ echo "Checking for attribute(ifunc) support... No." | tee -a configure.log
+fi
+
+# Test to see if we can use the optimizations for Power
+echo >> configure.log
+cat > $test.c <<EOF
+#ifndef _ARCH_PPC
+ #error "Target is not Power"
+#endif
+#ifndef HAVE_IFUNC
+ #error "Target doesn't support ifunc"
+#endif
+#ifndef __BUILTIN_CPU_SUPPORTS__
+ #error "Target doesn't support __builtin_cpu_supports()"
+#endif
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ echo "int main(void){return 0;}" > $test.c
+
+ if tryboth $CC -c $CFLAGS -mcpu=power8 $test.c; then
+ POWER8="-DZ_POWER8"
+ PIC_OBJC="${PIC_OBJC}"
+ OBJC="${OBJC}"
+ echo "Checking for -mcpu=power8 support... Yes." | tee -a configure.log
+ else
+ echo "Checking for -mcpu=power8 support... No." | tee -a configure.log
+ fi
+
+ if tryboth $CC -c $CFLAGS -mcpu=power9 $test.c; then
+ POWER9="-DZ_POWER9"
+ PIC_OBJC="${PIC_OBJC}"
+ OBJC="${OBJC}"
+ echo "Checking for -mcpu=power9 support... Yes." | tee -a configure.log
+ else
+ echo "Checking for -mcpu=power9 support... No." | tee -a configure.log
+ fi
+
+ SFLAGS="${SFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT"
+ CFLAGS="${CFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT"
+ echo "Checking for Power optimizations support... Yes." | tee -a configure.log
+else
+ echo "Checking for Power optimizations support... No." | tee -a configure.log
+fi
+
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
diff --git a/contrib/README.contrib b/contrib/README.contrib
index b4d3b18..2a53f90 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -19,6 +19,10 @@ asm686/ by Brian Raiter <breadbox@muppetlabs.com>
blast/ by Mark Adler <madler@alumni.caltech.edu>
Decompressor for output of PKWare Data Compression Library (DCL)
+gcc/ by Matheus Castanho <msc@linux.ibm.com>
+ and Rogerio Alves <rcardoso@linux.ibm.com>
+ Optimization helpers using GCC-specific extensions
+
delphi/ by Cosmin Truta <cosmint@cs.ubbcluj.ro>
Support for Delphi and C++ Builder
@@ -63,6 +67,10 @@ minizip/ by Gilles Vollant <info@winimage.com>
pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
Support for Pascal
+power/ by Matheus Castanho <msc@linux.ibm.com>
+ and Rogerio Alves <rcardoso@linux.ibm.com>
+ Optimized functions for Power processors
+
puff/ by Mark Adler <madler@alumni.caltech.edu>
Small, low memory usage inflate. Also serves to provide an
unambiguous description of the deflate format.
diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h
new file mode 100644
index 0000000..daf4fe4
--- /dev/null
+++ b/contrib/gcc/zifunc.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2019 Matheus Castanho <msc@linux.ibm.com>, IBM
+ * 2019 Rogerio Alves <rogerio.alves@ibm.com>, IBM
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#ifndef Z_IFUNC_H_
+#define Z_IFUNC_H_
+
+/* Helpers for arch optimizations */
+
+#define Z_IFUNC(fname) \
+ typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \
+ local typeof(fname) *fname##_resolver(void)
+/* This is a helper macro to declare a resolver for an indirect function
+ * (ifunc). Let's say you have function
+ *
+ * int foo (int a);
+ *
+ * for which you want to provide different implementations, for example:
+ *
+ * int foo_clever (int a) {
+ * ... clever things ...
+ * }
+ *
+ * int foo_smart (int a) {
+ * ... smart things ...
+ * }
+ *
+ * You will have to declare foo() as an indirect function and also provide a
+ * resolver for it, to choose between foo_clever() and foo_smart() based on
+ * some criteria you define (e.g. processor features).
+ *
+ * Since most likely foo() has a default implementation somewhere in zlib, you
+ * may have to rename it so the 'foo' symbol can be used by the ifunc without
+ * conflicts.
+ *
+ * #define foo foo_default
+ * int foo (int a) {
+ * ...
+ * }
+ * #undef foo
+ *
+ * Now you just have to provide a resolver function to choose which function
+ * should be used (decided at runtime on the first call to foo()):
+ *
+ * Z_IFUNC(foo) {
+ * if (... some condition ...)
+ * return foo_clever;
+ *
+ * if (... other condition ...)
+ * return foo_smart;
+ *
+ * return foo_default;
+ * }
+ *
+ * All calls to foo() throughout the code can remain untouched, all the magic
+ * will be done by the linker using the resolver function.
+ */
+
+#endif /* Z_IFUNC_H_ */
diff --git a/contrib/power/power.h b/contrib/power/power.h
new file mode 100644
index 0000000..b42c7d6
--- /dev/null
+++ b/contrib/power/power.h
@@ -0,0 +1,4 @@
+/* Copyright (C) 2019 Matheus Castanho <msc@linux.ibm.com>, IBM
+ * 2019 Rogerio Alves <rogerio.alves@ibm.com>, IBM
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
--
2.39.1

49
SOURCES/zlib-1.2.11-covscan-issues.patch

@ -9,19 +9,6 @@ Subject: [PATCH] fixed covscan issues @@ -9,19 +9,6 @@ Subject: [PATCH] fixed covscan issues
test/crc32_test.c | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/crc32.c b/crc32.c
index 406d350..34132ea 100644
--- a/crc32.c
+++ b/crc32.c
@@ -302,7 +302,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
if (!crc32_func)
crc32_func = crc32_z_ifunc();
- return (*crc32_func)(crc, buf, len);
+ return (*crc32_func)(crc, buf, len);
}
#endif /* defined(Z_IFUNC_ASM) || defined(Z_IFUNC_NATIVE) */
diff --git a/deflate.c b/deflate.c
index 089285a..9b09718 100644
--- a/deflate.c
@ -35,40 +22,4 @@ index 089285a..9b09718 100644 @@ -35,40 +22,4 @@ index 089285a..9b09718 100644
bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate :
s->level == 0 ? deflate_stored(s, flush) :
diff --git a/test/crc32_test.c b/test/crc32_test.c
index 5d73128..2d2a6c7 100644
--- a/test/crc32_test.c
+++ b/test/crc32_test.c
@@ -11,25 +11,25 @@
# include <stdlib.h>
#endif
-void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line));
+void test_crc32 OF((uLong crc, char* buf, z_size_t len, uLong chk, int line));
int main OF((void));
typedef struct {
int line;
uLong crc;
- Byte* buf;
+ char* buf;
int len;
uLong expect;
} crc32_test;
void test_crc32(crc, buf, len, chk, line)
uLong crc;
- Byte *buf;
+ char *buf;
z_size_t len;
uLong chk;
int line;
{
- uLong res = crc32(crc, buf, len);
+ uLong res = crc32(crc, (Bytef *) buf, len);
if (res != chk) {
fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n",
line, (unsigned int)res, (unsigned int)chk);
--
2.19.1


35
SOURCES/zlib-1.2.11-cve-2022-37434.patch

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
From eff308af425b67093bab25f80f1ae950166bece1 Mon Sep 17 00:00:00 2001
From: Mark Adler <fork@madler.net>
Date: Sat, 30 Jul 2022 15:51:11 -0700
Subject: [PATCH] Fix a bug when getting a gzip header extra field with
inflate().

If the extra field was larger than the space the user provided with
inflateGetHeader(), and if multiple calls of inflate() delivered
the extra header data, then there could be a buffer overflow of the
provided space. This commit assures that provided space is not
exceeded.
---
inflate.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/inflate.c b/inflate.c
index 7be8c63..7a72897 100644
--- a/inflate.c
+++ b/inflate.c
@@ -763,9 +763,10 @@ int flush;
copy = state->length;
if (copy > have) copy = have;
if (copy) {
+ len = state->head->extra_len - state->length;
if (state->head != Z_NULL &&
- state->head->extra != Z_NULL) {
- len = state->head->extra_len - state->length;
+ state->head->extra != Z_NULL &&
+ len < state->head->extra_max) {
zmemcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ?
state->head->extra_max - len : copy);
--
2.35.3

32
SOURCES/zlib-1.2.11-cve-2022-37434_2.patch

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
From 1eb7682f845ac9e9bf9ae35bbfb3bad5dacbd91d Mon Sep 17 00:00:00 2001
From: Mark Adler <fork@madler.net>
Date: Mon, 8 Aug 2022 10:50:09 -0700
Subject: [PATCH] Fix extra field processing bug that dereferences NULL
state->head.

The recent commit to fix a gzip header extra field processing bug
introduced the new bug fixed here.
---
inflate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/inflate.c b/inflate.c
index 7a72897..2a3c4fe 100644
--- a/inflate.c
+++ b/inflate.c
@@ -763,10 +763,10 @@ int flush;
copy = state->length;
if (copy > have) copy = have;
if (copy) {
- len = state->head->extra_len - state->length;
if (state->head != Z_NULL &&
state->head->extra != Z_NULL &&
- len < state->head->extra_max) {
+ (len = state->head->extra_len - state->length) <
+ state->head->extra_max) {
zmemcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ?
state->head->extra_max - len : copy);
--
2.35.3

171
SOURCES/zlib-1.2.11-s390x-vectorize-crc32.patch

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
From 2dfdc5b7d6943c0ac60eef63e361e2a50f9da610 Mon Sep 17 00:00:00 2001
From cfbf97cb54a6d06a80e86c85869331e4e2871129 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 19 Mar 2020 11:52:03 +0100
Subject: [PATCH] s390x: vectorize crc32
@ -8,15 +8,18 @@ about them. At runtime, check whether kernel supports vector @@ -8,15 +8,18 @@ about them. At runtime, check whether kernel supports vector
extensions (it has to be not just the CPU, but also the kernel) and
choose between the regular and the vectorized implementations.
---
Makefile.in | 9 ++
configure | 28 ++++++
contrib/s390/crc32-vx.c | 195 ++++++++++++++++++++++++++++++++++++++++
crc32.c | 55 +++++++++++-
4 files changed, 285 insertions(+), 2 deletions(-)
Makefile.in | 9 ++
configure | 28 +++++
contrib/gcc/zifunc.h | 21 +++-
contrib/s390/crc32-vx.c | 195 ++++++++++++++++++++++++++++++++
contrib/s390/crc32_z_resolver.c | 41 +++++++
crc32.c | 11 +-
6 files changed, 301 insertions(+), 4 deletions(-)
create mode 100644 contrib/s390/crc32-vx.c
create mode 100644 contrib/s390/crc32_z_resolver.c

diff --git a/Makefile.in b/Makefile.in
index 6070dcc..9e9743b 100644
index d392616..63f76da 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -29,6 +29,7 @@ LDFLAGS=
@ -27,9 +30,9 @@ index 6070dcc..9e9743b 100644 @@ -27,9 +30,9 @@ index 6070dcc..9e9743b 100644
STATICLIB=libz.a
SHAREDLIB=libz.so
@@ -179,6 +180,9 @@ crc32_power8.o: $(SRCDIR)contrib/power8-crc/vec_crc32.c
crc32.o: $(SRCDIR)crc32.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
@@ -179,6 +180,9 @@ crc32.o: $(SRCDIR)crc32.c
crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c
$(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c
+crc32-vx.o: $(SRCDIR)contrib/s390/crc32-vx.c
+ $(CC) $(CFLAGS) $(VGFMAFLAG) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c
@ -37,7 +40,7 @@ index 6070dcc..9e9743b 100644 @@ -37,7 +40,7 @@ index 6070dcc..9e9743b 100644
deflate.o: $(SRCDIR)deflate.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
@@ -234,6 +238,11 @@ crc32.lo: $(SRCDIR)crc32.c
@@ -229,6 +233,11 @@ crc32.lo: $(SRCDIR)crc32.c
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
-@mv objs/crc32.o $@
@ -46,15 +49,15 @@ index 6070dcc..9e9743b 100644 @@ -46,15 +49,15 @@ index 6070dcc..9e9743b 100644
+ $(CC) $(SFLAGS) $(VGFMAFLAG) $(ZINC) -DPIC -c -o objs/crc32-vx.o $(SRCDIR)contrib/s390/crc32-vx.c
+ -@mv objs/crc32-vx.o $@
+
deflate.lo: $(SRCDIR)deflate.c
crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c
-@mkdir objs 2>/dev/null || test -d objs
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
$(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c
diff --git a/configure b/configure
index 70ed86b..7941f75 100755
index e37dac8..a4606b8 100755
--- a/configure
+++ b/configure
@@ -923,6 +923,32 @@ EOF
fi
@@ -915,6 +915,32 @@ else
echo "Checking for Power optimizations support... No." | tee -a configure.log
fi
+# check if we are compiling for s390 and binutils support vector extensions
@ -86,7 +89,7 @@ index 70ed86b..7941f75 100755 @@ -86,7 +89,7 @@ index 70ed86b..7941f75 100755
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
@@ -955,6 +981,7 @@ echo mandir = $mandir >> configure.log
@@ -947,6 +973,7 @@ echo mandir = $mandir >> configure.log
echo prefix = $prefix >> configure.log
echo sharedlibdir = $sharedlibdir >> configure.log
echo uname = $uname >> configure.log
@ -94,7 +97,7 @@ index 70ed86b..7941f75 100755 @@ -94,7 +97,7 @@ index 70ed86b..7941f75 100755
# udpate Makefile with the configure results
sed < ${SRCDIR}Makefile.in "
@@ -964,6 +991,7 @@ sed < ${SRCDIR}Makefile.in "
@@ -956,6 +983,7 @@ sed < ${SRCDIR}Makefile.in "
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
/^LDSHARED *=/s#=.*#=$LDSHARED#
/^CPP *=/s#=.*#=$CPP#
@ -102,6 +105,40 @@ index 70ed86b..7941f75 100755 @@ -102,6 +105,40 @@ index 70ed86b..7941f75 100755
/^STATICLIB *=/s#=.*#=$STATICLIB#
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h
index daf4fe4..b62379e 100644
--- a/contrib/gcc/zifunc.h
+++ b/contrib/gcc/zifunc.h
@@ -8,9 +8,28 @@
/* Helpers for arch optimizations */
+#if defined(__clang__)
+#if __has_feature(coverage_sanitizer)
+#define Z_IFUNC_NO_SANCOV __attribute__((no_sanitize("coverage")))
+#else /* __has_feature(coverage_sanitizer) */
+#define Z_IFUNC_NO_SANCOV
+#endif /* __has_feature(coverage_sanitizer) */
+#else /* __clang__ */
+#define Z_IFUNC_NO_SANCOV
+#endif /* __clang__ */
+
+#ifdef __s390__
+#define Z_IFUNC_PARAMS unsigned long hwcap
+#define Z_IFUNC_ATTRS Z_IFUNC_NO_SANCOV
+#else /* __s390__ */
+#define Z_IFUNC_PARAMS void
+#define Z_IFUNC_ATTRS
+#endif /* __s390__ */
+
#define Z_IFUNC(fname) \
typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \
- local typeof(fname) *fname##_resolver(void)
+ Z_IFUNC_ATTRS \
+ local typeof(fname) *fname##_resolver(Z_IFUNC_PARAMS)
/* This is a helper macro to declare a resolver for an indirect function
* (ifunc). Let's say you have function
*
diff --git a/contrib/s390/crc32-vx.c b/contrib/s390/crc32-vx.c
new file mode 100644
index 0000000..fa5387c
@ -303,16 +340,14 @@ index 0000000..fa5387c @@ -303,16 +340,14 @@ index 0000000..fa5387c
+
+ return ((uv4si)v2)[2];
+}
diff --git a/crc32.c b/crc32.c
index 34132ea..dfa33ef 100644
--- a/crc32.c
+++ b/crc32.c
@@ -252,12 +252,54 @@ unsigned long crc32_vpmsum(unsigned long, const unsigned char FAR *, z_size_t);
#endif
#endif
+#ifdef HAVE_S390X_VX
diff --git a/contrib/s390/crc32_z_resolver.c b/contrib/s390/crc32_z_resolver.c
new file mode 100644
index 0000000..9749cab
--- /dev/null
+++ b/contrib/s390/crc32_z_resolver.c
@@ -0,0 +1,41 @@
+#include <sys/auxv.h>
+#include "../gcc/zifunc.h"
+
+#define VX_MIN_LEN 64
+#define VX_ALIGNMENT 16L
@ -322,17 +357,17 @@ index 34132ea..dfa33ef 100644 @@ -322,17 +357,17 @@ index 34132ea..dfa33ef 100644
+
+local unsigned long s390_crc32_vx(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
+{
+ uint64_t prealign, aligned, remaining;
+ uintptr_t prealign, aligned, remaining;
+
+ if (buf == Z_NULL) return 0UL;
+
+ if (len < VX_MIN_LEN + VX_ALIGN_MASK)
+ return crc32_big(crc, buf, len);
+ return crc32_z_default(crc, buf, len);
+
+ if ((uintptr_t)buf & VX_ALIGN_MASK) {
+ prealign = VX_ALIGNMENT - ((uintptr_t)buf & VX_ALIGN_MASK);
+ len -= prealign;
+ crc = crc32_big(crc, buf, prealign);
+ crc = crc32_z_default(crc, buf, prealign);
+ buf += prealign;
+ }
+ aligned = len & ~VX_ALIGN_MASK;
@ -341,53 +376,53 @@ index 34132ea..dfa33ef 100644 @@ -341,53 +376,53 @@ index 34132ea..dfa33ef 100644
+ crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, (size_t)aligned) ^ 0xffffffff;
+
+ if (remaining)
+ crc = crc32_big(crc, buf + aligned, remaining);
+ crc = crc32_z_default(crc, buf + aligned, remaining);
+
+ return crc;
+}
+#endif
+
/* due to a quirk of gnu_indirect_function - "local" (aka static) is applied to
* crc32_z which is not desired. crc32_z_ifunc is implictly "local" */
#ifndef Z_IFUNC_ASM
local
#endif
-unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *, z_size_t)
+unsigned long (*(crc32_z_ifunc(
+#ifdef __s390__
+unsigned long hwcap
+#else
+void
+#endif
+)))(unsigned long, const unsigned char FAR *, z_size_t)
{
#if _ARCH_PWR8==1
#if defined(__BUILTIN_CPU_SUPPORTS__)
@@ -269,6 +311,11 @@ unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *,
#endif
#endif /* _ARCH_PWR8 */
+#ifdef HAVE_S390X_VX
+Z_IFUNC(crc32_z)
+{
+ if (hwcap & HWCAP_S390_VX)
+ return s390_crc32_vx;
+#endif
+
/* return a function pointer for optimized arches here */
+ return crc32_z_default;
+}
diff --git a/crc32.c b/crc32.c
index b0cda20..379fac3 100644
--- a/crc32.c
+++ b/crc32.c
@@ -199,12 +199,12 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
#ifdef DYNAMIC_CRC_TABLE
@@ -301,7 +348,11 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
static unsigned long ZEXPORT (*crc32_func)(unsigned long, const unsigned char FAR *, z_size_t) = NULL;
/* ========================================================================= */
-#ifdef Z_POWER_OPT
+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX)
/* Rename function so resolver can use its symbol. The default version will be
* returned by the resolver if the host has no support for an optimized version.
*/
#define crc32_z crc32_z_default
-#endif /* Z_POWER_OPT */
+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */
if (!crc32_func)
- crc32_func = crc32_z_ifunc();
+ crc32_func = crc32_z_ifunc(
+#ifdef __s390__
+ getauxval(AT_HWCAP)
+#endif
+ );
return (*crc32_func)(crc, buf, len);
unsigned long ZEXPORT crc32_z(crc, buf, len)
unsigned long crc;
@@ -240,10 +240,15 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
return crc ^ 0xffffffffUL;
}
-#ifdef Z_POWER_OPT
+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX)
#undef crc32_z
+#ifdef Z_POWER_OPT
#include "contrib/power/crc32_z_resolver.c"
#endif /* Z_POWER_OPT */
+#ifdef HAVE_S390X_VX
+#include "contrib/s390/crc32_z_resolver.c"
+#endif /* HAVE_S390X_VX */
+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */
/* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len)
--
2.25.1
2.39.1


83
SPECS/zlib.spec

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@

Name: zlib
Version: 1.2.11
Release: 31%{?dist}
Release: 39%{?dist}
Summary: Compression and decompression library
# /contrib/dotzlib/ have Boost license
License: zlib and Boost
@ -13,14 +13,11 @@ Source: https://www.zlib.net/zlib-%{version}.tar.xz @@ -13,14 +13,11 @@ Source: https://www.zlib.net/zlib-%{version}.tar.xz
Patch0: zlib-1.2.5-minizip-fixuncrypt.patch
# resolves: #805113
Patch1: zlib-1.2.11-optimized-s390.patch
# Backport upstream commit 2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0
# Reason: Fuzzer founds issues with unknown memory access
Patch5: zlib-1.2.11-Limit-hash-table-inserts.patch
# IBM Z optimalizations
Patch7: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-s390x.patch
# IBM CRC32 optimalization for POWER archs
Patch8: zlib-1.2.11-optimized-CRC32-framework.patch
# fixed firefox crash + added test case
Patch9: zlib-1.2.11-firefox-crash-fix.patch
# fixed covscan issues
Patch10: zlib-1.2.11-covscan-issues.patch
# fix for IBM Z optimalizations
Patch11: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-fix.patch
# permit a deflateParams() parameter change
@ -33,9 +30,35 @@ Patch14: zlib-1.2.11-inflateSyncPoint-return-value-fix.patch @@ -33,9 +30,35 @@ Patch14: zlib-1.2.11-inflateSyncPoint-return-value-fix.patch
# fixed issues found by covscan for rhel-9
# ref: https://github.com/madler/zlib/pull/554
Patch15: zlib-1.2.11-covscan-issues-rhel9.patch
# Fix for s390x vectorize CRC32
Patch16: zlib-1.2.11-s390x-vectorize-crc32.patch
# fix for IBM Z optimalizations
Patch17: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch
# Fix for CVE-2018-25032
Patch18: zlib-1.2.11-CVE-2018-25032.patch
# Fix for CVE-2022-37434
Patch19: zlib-1.2.11-cve-2022-37434.patch
Patch20: zlib-1.2.11-cve-2022-37434_2.patch

# Fix setting strm.adler on z15
Patch21: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-strm-adler-fix.patch

# Optimization for z15
Patch22: zlib-1.2.11-IBM-Z-hw-accelrated-inflate-small-window.patch

# Optimized crc32 for Power 8+ processors
# Source: https://github.com/madler/zlib/pull/750
Patch23: zlib-1.2.11-Preparation-for-Power-optimizations.patch
Patch24: zlib-1.2.11-Add-Power8-optimized-crc32.patch
Patch25: zlib-1.2.11-Fix-clang-s-behavior-on-versions-7.patch

# Fix for Unnecessary IFUNC resolver for crc32_z
# Fix for s390x vectorize CRC32
Patch26: zlib-1.2.11-s390x-vectorize-crc32.patch

# Fix for python3.11 broken libxml2 and lxml on s390x
Patch27: zlib-1.2.11-Fix-broken-libxml2-for-python311.patch

# fixed covscan issues
Patch28: zlib-1.2.11-covscan-issues.patch

BuildRequires: make
BuildRequires: automake, autoconf, libtool
@ -94,17 +117,25 @@ developing applications which use minizip. @@ -94,17 +117,25 @@ developing applications which use minizip.
%ifarch s390 s390x
%patch1 -p1 -b .optimized-deflate
%endif
%patch5 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1


iconv -f iso-8859-2 -t utf-8 < ChangeLog > ChangeLog.tmp
@ -182,10 +213,34 @@ find $RPM_BUILD_ROOT -name '*.la' -delete @@ -182,10 +213,34 @@ find $RPM_BUILD_ROOT -name '*.la' -delete


%changelog
* Mon Apr 25 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-31.1
* Thu Feb 09 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-39
- Fix covscan issue CWE-681

* Tue Feb 07 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-38
- Resolve fuzzing issue for unknown memory access

* Tue Feb 07 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-37
- Rebased Power 8 optimization patches
- Fix for Unnecessary IFUNC resolver for crc32_z
- Fix for python3.11 broken libxml2 and lxml on s390x

* Mon Dec 19 2022 Ilya Leoshkevich <iii@linux.ibm.com> - 1.2.11-36
- Inflate small window optimization for IBM z15 rhbz#2154775

* Wed Oct 12 2022 Ilya Leoshkevich <iii@linux.ibm.com> - 1.2.11-35
- Fix for IBM strm.adler rhbz#2134074

* Wed Aug 10 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-34
- Fix heap-based buffer over-read or buffer overflow in inflate in inflate.c
- Resolves: CVE-2022-37434

* Mon Apr 25 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-33
- Fix CVE-2018-25032
Resolves: CVE-2018-25032

* Tue Mar 01 2022 Ilya Leoshkevich <iii@linux.ibm.com> - 1.2.11-32
- Fix for IBM compressBound() rhbz#2056899

* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 1.2.11-31
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688

Loading…
Cancel
Save