Skip to content

Commit c76f4a0

Browse files
committed
Huffman enc.: Fix very rare local buffer overrun
... detected by ASan. This is a similar issue to the issue that was fixed with 402a715. Apparently it is possible to create a malformed JPEG image that exceeds the Huffman encoder's 256-byte local buffer when attempting to losslessly tranform the image. That makes sense, given that it was necessary to extend the Huffman decoder's local buffer to 512 bytes in order to handle all pathological cases (refer to 0463f7c.) Since this issue affected only lossless transformation, a workflow that isn't generally exposed to arbitrary data exploits, and since the overrun did not overflow the stack (i.e. it did not result in a segfault or other user-visible issue, and valgrind didn't even detect it), it did not likely pose a security risk. Fixes #392
1 parent c0b16e3 commit c76f4a0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ JPEG images. This was known to cause a buffer overflow when attempting to
2424
decompress some such images using `tjDecompressToYUV2()` or
2525
`tjDecompressToYUVPlanes()`.
2626

27+
5. Fixed an issue, detected by ASan, whereby attempting to losslessly transform
28+
a specially-crafted malformed JPEG image containing an extremely-high-frequency
29+
coefficient block (junk image data that could never be generated by a
30+
legitimate JPEG compressor) could cause the Huffman encoder's local buffer to
31+
be overrun. (Refer to 1.4.0[9] and 1.4beta1[15].) Given that the buffer
32+
overrun was fully contained within the stack and did not cause a segfault or
33+
other user-visible errant behavior, and given that the lossless transformer
34+
(unlike the decompressor) is not generally exposed to arbitrary data exploits,
35+
this issue did not likely pose a security risk.
36+
2737

2838
2.0.3
2939
=====

jchuff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ dump_buffer(working_state *state)
432432
* scanning order-- 1, 8, 16, etc.), then this will produce an encoded block
433433
* larger than 200 bytes.
434434
*/
435-
#define BUFSIZE (DCTSIZE2 * 4)
435+
#define BUFSIZE (DCTSIZE2 * 8)
436436

437437
#define LOAD_BUFFER() { \
438438
if (state->free_in_buffer < BUFSIZE) { \

0 commit comments

Comments
 (0)