1 From c76f4a08263b0cea40d2967560ac7c21f6959079 Mon Sep 17 00:00:00 2001
2 From: DRC <information@libjpeg-turbo.org>
3 Date: Thu, 5 Dec 2019 13:12:28 -0600
4 Subject: [PATCH] Huffman enc.: Fix very rare local buffer overrun
6 ... detected by ASan. This is a similar issue to the issue that was
7 fixed with 402a715f82313384ef4606660c32d8678c79f197. Apparently it is
8 possible to create a malformed JPEG image that exceeds the Huffman
9 encoder's 256-byte local buffer when attempting to losslessly tranform
10 the image. That makes sense, given that it was necessary to extend the
11 Huffman decoder's local buffer to 512 bytes in order to handle all
12 pathological cases (refer to 0463f7c9aad060fcd56e98d025ce16185279e2bc.)
14 Since this issue affected only lossless transformation, a workflow that
15 isn't generally exposed to arbitrary data exploits, and since the
16 overrun did not overflow the stack (i.e. it did not result in a segfault
17 or other user-visible issue, and valgrind didn't even detect it), it did
18 not likely pose a security risk.
22 ChangeLog.md | 10 ++++++++++
24 2 files changed, 11 insertions(+), 1 deletion(-)
26 diff --git a/jchuff.c b/jchuff.c
27 index 206958e2f..cb05055d9 100644
30 @@ -432,7 +432,7 @@ dump_buffer(working_state *state)
31 * scanning order-- 1, 8, 16, etc.), then this will produce an encoded block
32 * larger than 200 bytes.
34 -#define BUFSIZE (DCTSIZE2 * 4)
35 +#define BUFSIZE (DCTSIZE2 * 8)
37 #define LOAD_BUFFER() { \
38 if (state->free_in_buffer < BUFSIZE) { \