blob: 3fef2bc1ebd29487d7bba211f1ed8b5d0179fe35 [file] [log] [blame]
Andrew Geisslerc723b722021-01-08 16:14:09 -06001From bdd3acbd48a575d418ba6bf1b32d7bda2fae1c81 Mon Sep 17 00:00:00 2001
2From: Robert Ancell <robert.ancell@canonical.com>
3Date: Mon, 30 Nov 2020 12:26:12 +1300
4Subject: [PATCH 02/13] gif: Fix LZW decoder accepting invalid LZW code.
5
6The code value after a reset wasn't being validated, which means we would
7accept invalid codes. This could cause an infinite loop in the decoder.
8
9Fixes CVE-2020-29385
10
11Fixes https://gitlab.gnome.org/GNOME/gdk-pixbuf/-/issues/164
12
13Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/gdk-pixbuf/-/commit/bdd3acbd48a575d418ba6bf1b32d7bda2fae1c81]
14CVE: CVE-2020-29385
15Signed-off-by: Chee Yang Lee <chee.yang.lee@intel.com>
16
17---
18 gdk-pixbuf/lzw.c | 13 +++++++------
19 1 files changed, 7 insertions(+), 6 deletions(-)
20 create mode 100644 tests/test-images/fail/hang_114.gif
21
22diff --git a/gdk-pixbuf/lzw.c b/gdk-pixbuf/lzw.c
23index 9e052a6f7..105daf2b1 100644
24--- a/gdk-pixbuf/lzw.c
25+++ b/gdk-pixbuf/lzw.c
26@@ -195,19 +195,20 @@ lzw_decoder_feed (LZWDecoder *self,
27 if (self->last_code != self->clear_code && self->code_table_size < MAX_CODES) {
28 if (self->code < self->code_table_size)
29 add_code (self, self->code);
30- else if (self->code == self->code_table_size)
31+ else
32 add_code (self, self->last_code);
33- else {
34- /* Invalid code received - just stop here */
35- self->last_code = self->eoi_code;
36- return output_length;
37- }
38
39 /* When table is full increase code size */
40 if (self->code_table_size == (1 << self->code_size) && self->code_size < LZW_CODE_MAX)
41 self->code_size++;
42 }
43
44+ /* Invalid code received - just stop here */
45+ if (self->code >= self->code_table_size) {
46+ self->last_code = self->eoi_code;
47+ return output_length;
48+ }
49+
50 /* Convert codeword into indexes */
51 n_written += write_indexes (self, output + n_written, output_length - n_written);
52 }
53--
542.25.1
55