Fix a bug in the 64-bit Huffman encoder that Google discovered when encoding some very specific (and proprietary) aerial images using quality=98, an optimized Huffman table, and the ISLOW DCT. These images were causing the Huffman bit buffer to overflow, because the code for encoding the DC coefficient was using the equivalent of the 32-bit version of EMIT_BITS(). Thus, when 64-bit code was used, the DC coefficient code was not properly checking how many bits were in the buffer before attempting to add more bits to it. This issue appears to have existed in all versions of libjpeg-turbo.

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.4.x@1547 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2015-05-06 22:41:12 +00:00
parent 96869f4b6e
commit a8b6ea2f8d
2 changed files with 8 additions and 5 deletions

View File

@@ -37,6 +37,11 @@ h2v2 merged upsampling were not properly checking for the existence of DSPr2.
version of the accelerated Huffman codec was not being compiled in when version of the accelerated Huffman codec was not being compiled in when
libjpeg-turbo was built on OS X. Oops. libjpeg-turbo was built on OS X. Oops.
[7] Fixed an extremely rare bug in the Huffman encoder that caused 64-bit
builds of libjpeg-turbo to incorrectly encode a few specific test images when
quality=98, an optimized Huffman table, and the slow integer forward DCT were
used.
1.4.0 1.4.0
===== =====

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2014 D. R. Commander. * Copyright (C) 2009-2011, 2014-2015 D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains Huffman entropy encoding routines. * This file contains Huffman entropy encoding routines.
@@ -520,16 +520,14 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
/* Emit the Huffman-coded symbol for the number of bits */ /* Emit the Huffman-coded symbol for the number of bits */
code = dctbl->ehufco[nbits]; code = dctbl->ehufco[nbits];
size = dctbl->ehufsi[nbits]; size = dctbl->ehufsi[nbits];
PUT_BITS(code, size) EMIT_BITS(code, size)
CHECKBUF15()
/* Mask off any extra bits in code */ /* Mask off any extra bits in code */
temp2 &= (((INT32) 1)<<nbits) - 1; temp2 &= (((INT32) 1)<<nbits) - 1;
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
PUT_BITS(temp2, nbits) EMIT_BITS(temp2, nbits)
CHECKBUF15()
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */