From: Nathan Moinvaziri Date: Wed, 8 Dec 2021 00:29:01 +0000 (-0500) Subject: Added checks and comments to ensure that when using raw mode no checksumming takes... X-Git-Tag: 2.1.0-beta1~480 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b0ffa63f22d4870ae68de38c34f7ec437e7edb1;p=thirdparty%2Fzlib-ng.git Added checks and comments to ensure that when using raw mode no checksumming takes place. --- diff --git a/inflate.c b/inflate.c index 38faefe2c..44a50e61c 100644 --- 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; diff --git a/inflate_p.h b/inflate_p.h index 464b04fdf..c5ba13a0c 100644 --- a/inflate_p.h +++ b/inflate_p.h @@ -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); } }