diff --git a/SOURCES/zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch b/SOURCES/zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch new file mode 100644 index 0000000..f347d42 --- /dev/null +++ b/SOURCES/zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch @@ -0,0 +1,197 @@ +Subject: [PATCH] Fixed DFLTCC compression level switching issues + +--- + configure | 2 +- + contrib/s390/dfltcc.c | 52 ++++++++++++++++++++++++++++++----- + contrib/s390/dfltcc_deflate.h | 2 ++ + deflate.c | 12 ++++---- + test/infcover.c | 2 +- + 5 files changed, 56 insertions(+), 14 deletions(-) + +diff --git a/configure b/configure +index bfe4386..6fa0474 100755 +--- a/configure ++++ b/configure +@@ -838,7 +838,7 @@ cat > $test.c << EOF + #include + int main() { return 0; } + EOF +-if try ${CC} ${CFLAGS} $test.c; then ++ if try $CC -c $CFLAGS $test.c; then + echo "Checking for sys/sdt.h ... Yes." | tee -a configure.log + CFLAGS="$CFLAGS -DHAVE_SYS_SDT_H" + SFLAGS="$SFLAGS -DHAVE_SYS_SDT_H" +diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c +index d88a0d6..94a196f 100644 +--- a/contrib/s390/dfltcc.c ++++ b/contrib/s390/dfltcc.c +@@ -350,8 +350,12 @@ int ZLIB_INTERNAL dfltcc_deflate(strm, flush, result) + int soft_bcc; + int no_flush; + +- if (!dfltcc_can_deflate(strm)) ++ if (!dfltcc_can_deflate(strm)) { ++ /* Clear history. */ ++ if (flush == Z_FULL_FLUSH) ++ param->hl = 0; + return 0; ++ } + + again: + masked_avail_in = 0; +@@ -376,7 +380,8 @@ again: + /* Clear history. */ + if (flush == Z_FULL_FLUSH) + param->hl = 0; +- *result = need_more; ++ /* Trigger block post-processing if necessary. */ ++ *result = no_flush ? need_more : block_done; + return 1; + } + +@@ -403,13 +408,18 @@ again: + param->bcf = 0; + dfltcc_state->block_threshold = + strm->total_in + dfltcc_state->block_size; +- if (strm->avail_out == 0) { +- *result = need_more; +- return 1; +- } + } + } + ++ /* No space for compressed data. If we proceed, dfltcc_cmpr() will return ++ * DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still ++ * set BCF=1, which is wrong. Avoid complications and return early. ++ */ ++ if (strm->avail_out == 0) { ++ *result = need_more; ++ return 1; ++ } ++ + /* The caller gave us too much data. Pass only one block worth of + * uncompressed data to DFLTCC and mask the rest, so that on the next + * iteration we start a new block. +@@ -737,10 +747,15 @@ __attribute__((constructor)) local void init_globals(void) + * compiling with -m31, gcc defaults to ESA mode, however, since the kernel + * is 64-bit, it's always z/Architecture mode at runtime. + */ +- __asm__ volatile(".machinemode push\n" ++ __asm__ volatile( ++#ifndef __clang__ ++ ".machinemode push\n" + ".machinemode zarch\n" ++#endif + "stfle %[facilities]\n" ++#ifndef __clang__ + ".machinemode pop\n" ++#endif + : [facilities] "=Q" (cpu_facilities) + , [r0] "+r" (r0) + : +@@ -872,6 +887,28 @@ int ZLIB_INTERNAL dfltcc_deflate_params(strm, level, strategy, flush) + return Z_OK; + } + ++int ZLIB_INTERNAL dfltcc_deflate_done(strm, flush) ++ z_streamp strm; ++ int flush; ++{ ++ deflate_state FAR *state = (deflate_state FAR *)strm->state; ++ struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state); ++ struct dfltcc_param_v0 FAR *param = &dfltcc_state->param; ++ ++ /* When deflate(Z_FULL_FLUSH) is called with small avail_out, it might ++ * close the block without resetting the compression state. Detect this ++ * situation and return that deflation is not done. ++ */ ++ if (flush == Z_FULL_FLUSH && strm->avail_out == 0) ++ return 0; ++ ++ /* Return that deflation is not done if DFLTCC is used and either it ++ * buffered some data (Continuation Flag is set), or has not written EOBS ++ * yet (Block-Continuation Flag is set). ++ */ ++ return !dfltcc_can_deflate(strm) || (!param->cf && !param->bcf); ++} ++ + /* + Preloading history. + */ +@@ -925,6 +962,7 @@ int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(strm, dictionary, dict_length) + + append_history(param, state->window, dictionary, dict_length); + state->strstart = 1; /* Add FDICT to zlib header */ ++ state->block_start = state->strstart; /* Make deflate_stored happy */ + return Z_OK; + } + +diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h +index de36784..914daa4 100644 +--- a/contrib/s390/dfltcc_deflate.h ++++ b/contrib/s390/dfltcc_deflate.h +@@ -11,6 +11,7 @@ int ZLIB_INTERNAL dfltcc_deflate_params OF((z_streamp strm, + int level, + int strategy, + int *flush)); ++int ZLIB_INTERNAL dfltcc_deflate_done OF((z_streamp strm, int flush)); + int ZLIB_INTERNAL dfltcc_deflate_set_dictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dict_length)); +@@ -41,6 +42,7 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm, + if (err == Z_STREAM_ERROR) \ + return err; \ + } while (0) ++#define DEFLATE_DONE dfltcc_deflate_done + #define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \ + do { \ + if (dfltcc_can_deflate((strm))) \ +diff --git a/deflate.c b/deflate.c +index d907a1b..085abbe 100644 +--- a/deflate.c ++++ b/deflate.c +@@ -75,6 +75,7 @@ const char deflate_copyright[] = + #define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0) + #define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0) + #define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0) ++#define DEFLATE_DONE(strm, flush) 1 + #define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0) + #define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0 + #define DEFLATE_HOOK(strm, flush, bstate) 0 +@@ -605,14 +606,15 @@ int ZEXPORT deflateParams(strm, level, strategy) + DEFLATE_PARAMS_HOOK(strm, level, strategy, &hook_flush); + func = configuration_table[s->level].func; + +- if ((strategy != s->strategy || func != configuration_table[level].func || +- hook_flush != Z_NO_FLUSH) && s->last_flush != -2) { ++ if (((strategy != s->strategy || func != configuration_table[level].func) && ++ s->last_flush != -2) || hook_flush != Z_NO_FLUSH) { + /* Flush the last buffer: */ +- int err = deflate(strm, RANK(hook_flush) > RANK(Z_BLOCK) ? +- hook_flush : Z_BLOCK); ++ int flush = RANK(hook_flush) > RANK(Z_BLOCK) ? hook_flush : Z_BLOCK; ++ int err = deflate(strm, flush); + if (err == Z_STREAM_ERROR) + return err; +- if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) ++ if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead || ++ !DEFLATE_DONE(strm, flush)) + return Z_BUF_ERROR; + } + if (s->level != level) { +diff --git a/test/infcover.c b/test/infcover.c +index a34cd17..a208219 100644 +--- a/test/infcover.c ++++ b/test/infcover.c +@@ -373,7 +373,7 @@ local void cover_support(void) + mem_setup(&strm); + strm.avail_in = 0; + strm.next_in = Z_NULL; +- ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream)); ++ ret = inflateInit_(&strm, &ZLIB_VERSION[1], (int)sizeof(z_stream)); + assert(ret == Z_VERSION_ERROR); + mem_done(&strm, "wrong version"); + +-- +2.26.0 + diff --git a/SOURCES/zlib-1.2.11-inflateSyncPoint-return-value-fix.patch b/SOURCES/zlib-1.2.11-inflateSyncPoint-return-value-fix.patch new file mode 100644 index 0000000..f9b3756 --- /dev/null +++ b/SOURCES/zlib-1.2.11-inflateSyncPoint-return-value-fix.patch @@ -0,0 +1,45 @@ +Subject: [PATCH] Fixed inflateSyncPoint() bad return value on z15 + +--- + contrib/s390/dfltcc.h | 4 ++++ + inflate.c | 2 ++ + 2 files changed, 6 insertions(+) + +diff --git a/contrib/s390/dfltcc.h b/contrib/s390/dfltcc.h +index 574e84c..7960626 100644 +--- a/contrib/s390/dfltcc.h ++++ b/contrib/s390/dfltcc.h +@@ -51,5 +51,9 @@ int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm)); + do { \ + if (dfltcc_was_inflate_used((strm))) return -(1L << 16); \ + } while (0) ++#define INFLATE_SYNC_POINT_HOOK(strm) \ ++ do { \ ++ if (dfltcc_was_inflate_used((strm))) return Z_STREAM_ERROR; \ ++ } while (0) + + #endif +\ No newline at end of file +diff --git a/inflate.c b/inflate.c +index f77c2ae..596034c 100644 +--- a/inflate.c ++++ b/inflate.c +@@ -100,6 +100,7 @@ + #define INFLATE_NEED_CHECKSUM(strm) 1 + #define INFLATE_NEED_UPDATEWINDOW(strm) 1 + #define INFLATE_MARK_HOOK(strm) do {} while (0) ++#define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0) + #endif + + #ifdef MAKEFIXED +@@ -1483,6 +1484,7 @@ z_streamp strm; + struct inflate_state FAR *state; + + if (inflateStateCheck(strm)) return Z_STREAM_ERROR; ++ INFLATE_SYNC_POINT_HOOK(strm); + state = (struct inflate_state FAR *)strm->state; + return state->mode == STORED && state->bits == 0; + } +-- +2.26.0 + diff --git a/SPECS/zlib.spec b/SPECS/zlib.spec index a215618..430856e 100644 --- a/SPECS/zlib.spec +++ b/SPECS/zlib.spec @@ -3,7 +3,7 @@ Name: zlib Version: 1.2.11 -Release: 16%{?dist} +Release: 16.2%{?dist} Summary: The compression and decompression library # /contrib/dotzlib/ have Boost license License: zlib and Boost @@ -26,6 +26,10 @@ Patch5: zlib-1.2.11-covscan-issues.patch Patch6: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-fix.patch # permit a deflateParams() parameter change Patch7: zlib-1.2.11-permit-deflateParams-change.patch +# fixed DFLTCC compression level switching issues +Patch8: zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch +# fixed inflateSyncPoint() bad return value on z15 +Patch9: zlib-1.2.11-inflateSyncPoint-return-value-fix.patch BuildRequires: automake, autoconf, libtool @@ -86,6 +90,8 @@ developing applications which use minizip. %patch5 -p1 %patch6 -p1 %patch7 -p1 +%patch8 -p1 +%patch9 -p1 iconv -f iso-8859-2 -t utf-8 < ChangeLog > ChangeLog.tmp mv ChangeLog.tmp ChangeLog @@ -165,6 +171,12 @@ find $RPM_BUILD_ROOT -name '*.la' -delete %changelog +* Wed Feb 24 2021 Ondrej Dubaj - 1.2.11-16.2 +- Fixed inflateSyncPoint() bad return value on z15 (#1932270) + +* Mon Jun 15 2020 Ondrej Dubaj - 1.2.11-16.1 +- Fixed DFLTCC compression level switching issues (#1926104) + * Mon Jun 15 2020 Ondrej Dubaj - 1.2.11-16 - Permit a deflateParams() parameter change - Another fix for Z hardware-accelerated deflate for s390x architectures