8cf299
From 5eaae2af0defeca148c2a281873bb31a15246876 Mon Sep 17 00:00:00 2001
8cf299
From: Ilya Leoshkevich <iii@linux.ibm.com>
8cf299
Date: Thu, 2 Feb 2023 19:34:24 +0100
8cf299
Subject: [PATCH] 2155328
8cf299
8cf299
---
8cf299
 contrib/s390/dfltcc.c | 21 +++++++++++++++------
8cf299
 1 file changed, 15 insertions(+), 6 deletions(-)
8cf299
8cf299
diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c
8cf299
index 72099e7..f8dc21c 100644
8cf299
--- a/contrib/s390/dfltcc.c
8cf299
+++ b/contrib/s390/dfltcc.c
8cf299
@@ -456,7 +456,10 @@ again:
8cf299
         *strm->next_out = (Bytef)state->bi_buf;
8cf299
     /* Honor history and check value */
8cf299
     param->nt = 0; 
8cf299
-    param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
8cf299
+    if (state->wrap == 1)
8cf299
+        param->cv = strm->adler;
8cf299
+    else if (state->wrap == 2)
8cf299
+        param->cv = ZSWAP32(strm->adler);
8cf299
 
8cf299
     /* When opening a block, choose a Huffman-Table Type */
8cf299
     if (!param->bcf) {
8cf299
@@ -488,7 +491,10 @@ again:
8cf299
         state->bi_buf = 0; /* Avoid accessing next_out */
8cf299
     else
8cf299
         state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1);
8cf299
-    strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv;
8cf299
+    if (state->wrap == 1)
8cf299
+        strm->adler = param->cv;
8cf299
+    else if (state->wrap == 2)
8cf299
+        strm->adler = ZSWAP32(param->cv);
8cf299
 
8cf299
     /* Unmask the input data */
8cf299
     strm->avail_in += masked_avail_in;
8cf299
@@ -600,11 +606,12 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
8cf299
     }
8cf299
 
8cf299
     /* Translate stream to parameter block */
8cf299
-    param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32;
8cf299
+    param->cvt = ((state->wrap & 4) && state->flags) ? CVT_CRC32 : CVT_ADLER32;
8cf299
     param->sbb = state->bits;
8cf299
     if (param->hl)
8cf299
         param->nt = 0; /* Honor history for the first block */
8cf299
-    param->cv = state->flags ? ZSWAP32(state->check) : state->check;
8cf299
+    if (state->wrap & 4)
8cf299
+        param->cv = state->flags ? ZSWAP32(state->check) : state->check;
8cf299
 
8cf299
     /* Inflate */
8cf299
     do {
8cf299
@@ -615,7 +622,9 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
8cf299
     strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
8cf299
     state->last = cc == DFLTCC_CC_OK;
8cf299
     state->bits = param->sbb;
8cf299
-    strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
8cf299
+    if (state->wrap & 4)
8cf299
+        strm->adler = state->check = state->flags ?
8cf299
+                                     ZSWAP32(param->cv) : param->cv;
8cf299
     if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
8cf299
         /* Report an error if stream is corrupted */
8cf299
         state->mode = BAD;
8cf299
@@ -1077,4 +1086,4 @@ int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(strm, dictionary, dict_length)
8cf299
     if (dict_length)
8cf299
         *dict_length = param->hl;
8cf299
     return Z_OK;
8cf299
-}
8cf299
\ No newline at end of file
8cf299
+}
8cf299
-- 
8cf299
2.39.1
8cf299