Skip to content

Commit a8b6ea2

Browse files
committed
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
1 parent 96869f4 commit a8b6ea2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ChangeLog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ h2v2 merged upsampling were not properly checking for the existence of DSPr2.
3737
version of the accelerated Huffman codec was not being compiled in when
3838
libjpeg-turbo was built on OS X. Oops.
3939

40+
[7] Fixed an extremely rare bug in the Huffman encoder that caused 64-bit
41+
builds of libjpeg-turbo to incorrectly encode a few specific test images when
42+
quality=98, an optimized Huffman table, and the slow integer forward DCT were
43+
used.
44+
4045

4146
1.4.0
4247
=====

jchuff.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file was part of the Independent JPEG Group's software:
55
* Copyright (C) 1991-1997, Thomas G. Lane.
66
* libjpeg-turbo Modifications:
7-
* Copyright (C) 2009-2011, 2014 D. R. Commander.
7+
* Copyright (C) 2009-2011, 2014-2015 D. R. Commander.
88
* For conditions of distribution and use, see the accompanying README file.
99
*
1010
* This file contains Huffman entropy encoding routines.
@@ -520,16 +520,14 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
520520
/* Emit the Huffman-coded symbol for the number of bits */
521521
code = dctbl->ehufco[nbits];
522522
size = dctbl->ehufsi[nbits];
523-
PUT_BITS(code, size)
524-
CHECKBUF15()
523+
EMIT_BITS(code, size)
525524

526525
/* Mask off any extra bits in code */
527526
temp2 &= (((INT32) 1)<<nbits) - 1;
528527

529528
/* Emit that number of bits of the value, if positive, */
530529
/* or the complement of its magnitude, if negative. */
531-
PUT_BITS(temp2, nbits)
532-
CHECKBUF15()
530+
EMIT_BITS(temp2, nbits)
533531

534532
/* Encode the AC coefficients per section F.1.2.2 */
535533

0 commit comments

Comments
 (0)