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 <greg.b.tucker@intel.com>
This commit is contained in:
Greg Tucker
2018-10-25 14:43:27 -07:00
parent b4dfd61d06
commit 06b926fbb6
2 changed files with 9 additions and 5 deletions

View File

@@ -933,13 +933,16 @@ static inline void reset_match_history(struct isal_zstream *stream)
static void inline set_dist_mask(struct isal_zstream *stream) static void inline set_dist_mask(struct isal_zstream *stream)
{ {
struct isal_zstate *state = &stream->internal_state; 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) if (stream->hist_bits > ISAL_DEF_MAX_HIST_BITS || stream->hist_bits == 0)
state->dist_mask = hist_size - 1; stream->hist_bits = ISAL_DEF_MAX_HIST_BITS;
else
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; state->dist_mask = IGZIP_HIST_SIZE - 1;
} }
static void inline set_hash_mask(struct isal_zstream *stream) static void inline set_hash_mask(struct isal_zstream *stream)

View File

@@ -84,6 +84,7 @@ extern "C" {
#define ISAL_DEF_MAX_HDR_SIZE 328 #define ISAL_DEF_MAX_HDR_SIZE 328
#define ISAL_DEF_MAX_CODE_LEN 15 #define ISAL_DEF_MAX_CODE_LEN 15
#define ISAL_DEF_HIST_SIZE (32*IGZIP_K) #define ISAL_DEF_HIST_SIZE (32*IGZIP_K)
#define ISAL_DEF_MAX_HIST_BITS 15
#define ISAL_DEF_LIT_SYMBOLS 257 #define ISAL_DEF_LIT_SYMBOLS 257
#define ISAL_DEF_LEN_SYMBOLS 29 #define ISAL_DEF_LEN_SYMBOLS 29