diff --git a/jdmarker.c b/jdmarker.c index a19219fa..c8771bc0 100644 --- a/jdmarker.c +++ b/jdmarker.c @@ -478,14 +478,15 @@ get_dht (j_decompress_ptr cinfo) if (index & 0x10) { /* AC table definition */ index -= 0x10; + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); htblptr = &cinfo->ac_huff_tbl_ptrs[index]; } else { /* DC table definition */ + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); htblptr = &cinfo->dc_huff_tbl_ptrs[index]; } - if (index < 0 || index >= NUM_HUFF_TBLS) - ERREXIT1(cinfo, JERR_DHT_INDEX, index); - if (*htblptr == NULL) *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); diff --git a/jdphuff.c b/jdphuff.c index 22678099..fa97aab6 100644 --- a/jdphuff.c +++ b/jdphuff.c @@ -198,6 +198,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo) * On some machines, a shift and add will be faster than a table lookup. */ +#define AVOID_TABLES #ifdef AVOID_TABLES #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) diff --git a/jquant2.c b/jquant2.c index 9b060e57..d9944705 100644 --- a/jquant2.c +++ b/jquant2.c @@ -513,6 +513,8 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor) } } + if (total == 0) + return; cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total); cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total); cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);