diff options
| author | Nathan Moinvaziri <nathan@nathanm.com> | 2021-12-07 19:29:01 -0500 |
|---|---|---|
| committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-12-09 14:28:34 +0100 |
| commit | 5b0ffa63f22d4870ae68de38c34f7ec437e7edb1 (patch) | |
| tree | bc6d01b7661f4d13d1fae3dda2a5610ec934bb5a | |
| parent | 6f8a474c5cdf8ef332f5602c0cab3447a23d8304 (diff) | |
| download | Project-Tick-5b0ffa63f22d4870ae68de38c34f7ec437e7edb1.tar.gz Project-Tick-5b0ffa63f22d4870ae68de38c34f7ec437e7edb1.zip | |
Added checks and comments to ensure that when using raw mode no checksumming takes place.
| -rw-r--r-- | inflate.c | 7 | ||||
| -rw-r--r-- | inflate_p.h | 17 |
2 files changed, 16 insertions, 8 deletions
@@ -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 464b04fdfe..c5ba13a0c6 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); } } |
