From 06b926fbb6716af72c27465da42e082bd3d5dcfb Mon Sep 17 00:00:00 2001 From: Greg Tucker Date: Thu, 25 Oct 2018 14:43:27 -0700 Subject: [PATCH] igzip: Fix portability issue when bad window size passed If a user passes an invalid size for window bits it could have triggered an undefined shift by larger than variable size. Change-Id: Ib2999b094af075596be3333418667ae9b498e2ae Signed-off-by: Greg Tucker --- igzip/igzip.c | 13 ++++++++----- include/igzip_lib.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/igzip/igzip.c b/igzip/igzip.c index b9e04c7..de7e010 100644 --- a/igzip/igzip.c +++ b/igzip/igzip.c @@ -933,13 +933,16 @@ static inline void reset_match_history(struct isal_zstream *stream) static void inline set_dist_mask(struct isal_zstream *stream) { struct isal_zstate *state = &stream->internal_state; - uint32_t hist_size = (1 << (stream->hist_bits)); + uint32_t hist_size; - if (stream->hist_bits != 0 && hist_size < IGZIP_HIST_SIZE) - state->dist_mask = hist_size - 1; - else + if (stream->hist_bits > ISAL_DEF_MAX_HIST_BITS || stream->hist_bits == 0) + stream->hist_bits = ISAL_DEF_MAX_HIST_BITS; + + hist_size = (1 << (stream->hist_bits)); + state->dist_mask = hist_size - 1; + + if (IGZIP_HIST_SIZE < ISAL_DEF_HIST_SIZE && state->dist_mask > IGZIP_HIST_SIZE - 1) state->dist_mask = IGZIP_HIST_SIZE - 1; - } static void inline set_hash_mask(struct isal_zstream *stream) diff --git a/include/igzip_lib.h b/include/igzip_lib.h index eedfded..ffa9cd2 100644 --- a/include/igzip_lib.h +++ b/include/igzip_lib.h @@ -84,6 +84,7 @@ extern "C" { #define ISAL_DEF_MAX_HDR_SIZE 328 #define ISAL_DEF_MAX_CODE_LEN 15 #define ISAL_DEF_HIST_SIZE (32*IGZIP_K) +#define ISAL_DEF_MAX_HIST_BITS 15 #define ISAL_DEF_LIT_SYMBOLS 257 #define ISAL_DEF_LEN_SYMBOLS 29