]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Added checks and comments to ensure that when using raw mode no checksumming takes...
authorNathan Moinvaziri <nathan@nathanm.com>
Wed, 8 Dec 2021 00:29:01 +0000 (19:29 -0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 9 Dec 2021 13:28:34 +0000 (14:28 +0100)
inflate.c
inflate_p.h

index 38faefe2c975e30ca766836dc2dd81ecea5230d0..44a50e61c72565556d4e0f89254f1e85ec599a7e 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -502,7 +502,9 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
                 state->head->hcrc = (int)((state->flags >> 9) & 1);
                 state->head->done = 1;
             }
-            strm->adler = state->check = functable.crc32_fold_reset(&state->crc_fold);
+            /* compute crc32 checksum if not in raw mode */
+            if ((state->wrap & 4) && state->flags)
+                strm->adler = state->check = functable.crc32_fold_reset(&state->crc_fold);
             state->mode = TYPE;
             break;
 #endif
@@ -926,7 +928,8 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
                 state->total += out;
 
                 if (INFLATE_NEED_CHECKSUM(strm) && strm->total_out) {
-                    if (state->flags)
+                    /* compute crc32 final value if not in raw mode */
+                    if ((state->wrap & 4) && state->flags)
                         strm->adler = state->check = functable.crc32_fold_final(&state->crc_fold);
                 }
                 out = left;
index 464b04fdfe1a731dbcf996af5e13ad59a69169bb..c5ba13a0c601852f559c2489c0a88dcc64aebb50 100644 (file)
@@ -158,15 +158,20 @@ static inline void inf_crc_copy(PREFIX3(stream) *strm, unsigned char *const dst,
     if (!INFLATE_NEED_CHECKSUM(strm))
         return;
 
-    /* check function to use adler32() for zlib or crc32() for gzip */
+    /* compute checksum if not in raw mode */
+    if (state->wrap & 4) {
+        /* check flags to use adler32() for zlib or crc32() for gzip */
 #ifdef GUNZIP
-    if (state->flags)
-        functable.crc32_fold_copy(&state->crc_fold, dst, src, len);
-    else
+        if (state->flags)
+            functable.crc32_fold_copy(&state->crc_fold, dst, src, len);
+        else
 #endif
-    {
+        {
+            memcpy(dst, src, len);
+            strm->adler = state->check = functable.adler32(state->check, dst, len);
+        }
+    } else {
         memcpy(dst, src, len);
-        strm->adler = state->check = functable.adler32(state->check, dst, len);
     }
 }