diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-11-01 18:40:04 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-11-01 19:01:21 +0000 |
commit | 8dcec8cc076a0cf8350ca7a6ec1d3136812e2a24 (patch) | |
tree | 5ff7ab68fd150552d15896b484bffefbc7008dcb /jpeg | |
parent | 1eebbfa373d295bdd2bad88aaef1edc368450568 (diff) | |
download | ghostpdl-8dcec8cc076a0cf8350ca7a6ec1d3136812e2a24.tar.gz |
Bug 697186: Workaround JPEG lib bug.
Commit fix for overflow. Awaiting response from IJG.
Diffstat (limited to 'jpeg')
-rw-r--r-- | jpeg/jidctint.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/jpeg/jidctint.c b/jpeg/jidctint.c index 76fe5d9cf..3ab5ee9eb 100644 --- a/jpeg/jidctint.c +++ b/jpeg/jidctint.c @@ -141,6 +141,15 @@ #endif +/* Clamp DC value to acceptable range for bug 697186 */ +#define CLAMP_DC(dcval) \ + { \ + if (dcval < -1024) \ + dcval = -1024; \ + else if (dcval > 1023) \ + dcval = 1023; \ + } + /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. * For 8-bit samples with the recommended scaling, all the variable * and constant values involved are no more than 16 bits wide, so a @@ -209,7 +218,9 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { /* AC terms all zero */ - int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(dcval); + dcval <<= PASS1_BITS; wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*1] = dcval; @@ -238,6 +249,7 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */ z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z2); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z2 <<= CONST_BITS; z3 <<= CONST_BITS; @@ -455,6 +467,7 @@ jpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp13); tmp13 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp13 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -604,6 +617,7 @@ jpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -725,6 +739,7 @@ jpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp12); tmp12 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp12 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -840,6 +855,7 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); tmp10 = (tmp0 + tmp2) << PASS1_BITS; @@ -944,6 +960,7 @@ jpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -1026,6 +1043,7 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Column 0 */ tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp4); tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]); /* Add fudge factor here for final descale. */ tmp4 += ONE << 2; @@ -1077,6 +1095,7 @@ jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* 1x1 is trivial: just take the DC coefficient divided by 8. */ quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; dcval = DEQUANTIZE(coef_block[0], quantptr[0]); + CLAMP_DC(dcval); dcval = (int) DESCALE((INT32) dcval, 3); output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; @@ -1116,6 +1135,7 @@ jpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -1288,6 +1308,7 @@ jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z3); z3 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z3 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -1483,6 +1504,7 @@ jpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp10); tmp10 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp10 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -1677,6 +1699,7 @@ jpeg_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z3); z3 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z3 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -1893,6 +1916,7 @@ jpeg_idct_13x13 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z1); z1 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z1 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -2121,6 +2145,7 @@ jpeg_idct_14x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z1); z1 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z1 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -2347,6 +2372,7 @@ jpeg_idct_15x15 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z1); z1 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z1 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -2589,6 +2615,7 @@ jpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += 1 << (CONST_BITS-PASS1_BITS-1); @@ -2865,7 +2892,9 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr, inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { /* AC terms all zero */ - int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(dcval); + dcval <<= PASS1_BITS; wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*1] = dcval; @@ -2894,6 +2923,7 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr, tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */ z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z2); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z2 <<= CONST_BITS; z3 <<= CONST_BITS; @@ -3127,6 +3157,7 @@ jpeg_idct_14x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp23 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp23); tmp23 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp23 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -3324,6 +3355,7 @@ jpeg_idct_12x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp10); tmp10 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp10 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -3502,6 +3534,7 @@ jpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp12); tmp12 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp12 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -3666,6 +3699,7 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); tmp10 = (tmp0 + tmp2) << PASS1_BITS; @@ -3822,6 +3856,7 @@ jpeg_idct_6x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -3932,6 +3967,7 @@ jpeg_idct_4x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp10); /* Odd part */ @@ -4019,6 +4055,7 @@ jpeg_idct_2x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(coef_block[0], quantptr[0]); + CLAMP_DC(tmp0); /* Add fudge factor here for final descale. */ tmp0 += ONE << 2; @@ -4068,6 +4105,7 @@ jpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -4290,6 +4328,7 @@ jpeg_idct_7x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z1); z1 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z1 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -4475,6 +4514,7 @@ jpeg_idct_6x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z3); z3 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z3 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -4641,6 +4681,7 @@ jpeg_idct_5x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(z3); z3 <<= CONST_BITS; /* Add fudge factor here for final descale. */ z3 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -4808,7 +4849,9 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr, inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { /* AC terms all zero */ - int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(dcval); + dcval <<= PASS1_BITS; wsptr[4*0] = dcval; wsptr[4*1] = dcval; @@ -4979,6 +5022,7 @@ jpeg_idct_3x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp0 <<= CONST_BITS; /* Add fudge factor here for final descale. */ tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); @@ -5086,6 +5130,7 @@ jpeg_idct_2x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); tmp10 = (tmp0 + tmp2) << CONST_BITS; @@ -5160,6 +5205,7 @@ jpeg_idct_1x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, /* Even part */ tmp0 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]); + CLAMP_DC(tmp0); /* Add fudge factor here for final descale. */ tmp0 += ONE << 2; |