254537
From 76eda67dbc3f48c9dd6815a5aaf6014ea4a16771 Mon Sep 17 00:00:00 2001
254537
From: Robert Ancell <robert.ancell@canonical.com>
254537
Date: Wed, 2 Feb 2022 12:36:08 +1300
254537
Subject: [PATCH 1/4] Fix test GIF that was broken in the LZW code size, not
254537
 the values of the pixels
254537
254537
---
254537
 .../test-images/gif-test-suite/invalid-colors.gif | Bin 37 -> 35 bytes
254537
 1 file changed, 0 insertions(+), 0 deletions(-)
254537
254537
diff --git a/tests/test-images/gif-test-suite/invalid-colors.gif b/tests/test-images/gif-test-suite/invalid-colors.gif
254537
index c3111525ac2d977a0dbedf917f2beae610b614f8..6c3a7240e6ba58c344051351eb3581887fa314c7 100644
254537
GIT binary patch
254537
delta 11
254537
ScmY#Yo*>J{%%s7|U=08YGy!b@
254537
254537
delta 13
254537
UcmY#ZogmA>!}4E&fr-Hy01|-$Y5)KL
254537
254537
-- 
254537
GitLab
254537
254537
254537
From 0cf97225c9c227d11fc4ddf9cba8e8480672ee1b Mon Sep 17 00:00:00 2001
254537
From: Robert Ancell <robert.ancell@canonical.com>
254537
Date: Wed, 2 Feb 2022 12:38:45 +1300
254537
Subject: [PATCH 2/4] Add an assertion that checks for maximum LZW code size
254537
254537
---
254537
 gdk-pixbuf/lzw.c | 2 ++
254537
 1 file changed, 2 insertions(+)
254537
254537
diff --git a/gdk-pixbuf/lzw.c b/gdk-pixbuf/lzw.c
254537
index 105daf2b1..15293560b 100644
254537
--- a/gdk-pixbuf/lzw.c
254537
+++ b/gdk-pixbuf/lzw.c
254537
@@ -121,6 +121,8 @@ lzw_decoder_new (guint8 code_size)
254537
         LZWDecoder *self;
254537
         int i;
254537
 
254537
+        g_return_val_if_fail (code_size <= LZW_CODE_MAX, NULL);
254537
+
254537
         self = g_object_new (lzw_decoder_get_type (), NULL);
254537
 
254537
         self->min_code_size = code_size;
254537
-- 
254537
GitLab
254537
254537
254537
From 19ebba03117aefc9d0312f675f3a210ffdcc4907 Mon Sep 17 00:00:00 2001
254537
From: Robert Ancell <robert.ancell@canonical.com>
254537
Date: Wed, 2 Feb 2022 14:03:13 +1300
254537
Subject: [PATCH 3/4] Fix the check for maximum value of LZW initial code size.
254537
254537
This value is the number of bits for each symbol (i.e. colour index) decoded via LZW.
254537
The maximum LZW code is specified as 12 bits, so the value here can only be 11 as two additional code words are required (clear and end of information) that immediately uses an additional bit.
254537
This implementation has always been wrong, and the Firefox implementation has the same issue so it seems a common misinterpretation of the spec.
254537
This has been changed here to avoid an assertion later in the LZW decoder.
254537
Note that there is never any reason for a GIF to be encoded with more than 8 bits of colour information, as the colour tables only support up to 8 bits.
254537
---
254537
 gdk-pixbuf/io-gif.c | 4 ++--
254537
 1 file changed, 2 insertions(+), 2 deletions(-)
254537
254537
diff --git a/gdk-pixbuf/io-gif.c b/gdk-pixbuf/io-gif.c
254537
index 1befba155..310bdff6a 100644
254537
--- a/gdk-pixbuf/io-gif.c
254537
+++ b/gdk-pixbuf/io-gif.c
254537
@@ -499,8 +499,8 @@ gif_prepare_lzw (GifContext *context)
254537
 		/*g_message (_("GIF: EOF / read error on image data\n"));*/
254537
 		return -1;
254537
 	}
254537
-        
254537
-        if (context->lzw_set_code_size > 12) {
254537
+
254537
+        if (context->lzw_set_code_size >= 12) {
254537
                 g_set_error_literal (context->error,
254537
                                      GDK_PIXBUF_ERROR,
254537
                                      GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
254537
-- 
254537
GitLab
254537
254537
254537
From 449441210921c8ed417b0c4d5edbccd2d57e23f8 Mon Sep 17 00:00:00 2001
254537
From: Robert Ancell <robert.ancell@canonical.com>
254537
Date: Wed, 2 Feb 2022 14:19:06 +1300
254537
Subject: [PATCH 4/4] Add tests for GIF files with invalid LZW code sizes
254537
254537
---
254537
 tests/test-images/fail/overflow-codes-max.gif      | Bin 0 -> 65 bytes
254537
 tests/test-images/fail/overflow-codes.gif          | Bin 0 -> 35 bytes
254537
 tests/test-images/gif-test-suite/TESTS             |   2 ++
254537
 tests/test-images/gif-test-suite/invalid-code.conf |  11 +++++++++++
254537
 tests/test-images/gif-test-suite/invalid-code.gif  | Bin 0 -> 35 bytes
254537
 .../gif-test-suite/overflow-codes-max.conf         |  11 +++++++++++
254537
 .../gif-test-suite/overflow-codes-max.gif          | Bin 0 -> 65 bytes
254537
 .../test-images/gif-test-suite/overflow-codes.conf |  11 +++++++++++
254537
 .../test-images/gif-test-suite/overflow-codes.gif  | Bin 0 -> 35 bytes
254537
 9 files changed, 35 insertions(+)
254537
 create mode 100644 tests/test-images/fail/overflow-codes-max.gif
254537
 create mode 100644 tests/test-images/fail/overflow-codes.gif
254537
 create mode 100644 tests/test-images/gif-test-suite/invalid-code.conf
254537
 create mode 100644 tests/test-images/gif-test-suite/invalid-code.gif
254537
 create mode 100644 tests/test-images/gif-test-suite/overflow-codes-max.conf
254537
 create mode 100644 tests/test-images/gif-test-suite/overflow-codes-max.gif
254537
 create mode 100644 tests/test-images/gif-test-suite/overflow-codes.conf
254537
 create mode 100644 tests/test-images/gif-test-suite/overflow-codes.gif
254537
254537
diff --git a/tests/test-images/fail/overflow-codes-max.gif b/tests/test-images/fail/overflow-codes-max.gif
254537
new file mode 100644
254537
index 0000000000000000000000000000000000000000..3d507ca7daa790c9370e69a2ab277f55d749a013
254537
GIT binary patch
254537
literal 65
254537
ncmZ?wbhEHbWMW`q_`m=H|NsBj0ns24hW`ozAU1Bm$Y2csUc3i2
254537
254537
literal 0
254537
HcmV?d00001
254537
254537
diff --git a/tests/test-images/fail/overflow-codes.gif b/tests/test-images/fail/overflow-codes.gif
254537
new file mode 100644
254537
index 0000000000000000000000000000000000000000..c38053872ae2e3378ff6fb8f3eaff839fa5d35ed
254537
GIT binary patch
254537
literal 35
254537
jcmZ?wbhEHbWMW`q_`m=H|NsBj0ns241|B8>Mh0sDhc^Z!
254537
254537
literal 0
254537
HcmV?d00001
254537
254537
diff --git a/tests/test-images/gif-test-suite/TESTS b/tests/test-images/gif-test-suite/TESTS
254537
index 1d4a3f13f..bc573acf4 100644
254537
--- a/tests/test-images/gif-test-suite/TESTS
254537
+++ b/tests/test-images/gif-test-suite/TESTS
254537
@@ -44,6 +44,8 @@ max-height
254537
 255-codes
254537
 large-codes
254537
 max-codes
254537
+#overflow-codes
254537
+#overflow-codes-max
254537
 transparent
254537
 invalid-transparent
254537
 disabled-transparent
254537
diff --git a/tests/test-images/gif-test-suite/invalid-code.conf b/tests/test-images/gif-test-suite/invalid-code.conf
254537
new file mode 100644
254537
index 000000000..3bf287b4e
254537
--- /dev/null
254537
+++ b/tests/test-images/gif-test-suite/invalid-code.conf
254537
@@ -0,0 +1,11 @@
254537
+# Automatically generated, do not edit!
254537
+[config]
254537
+input = invalid-code.gif
254537
+version = GIF89a
254537
+width = 2
254537
+height = 2
254537
+background = #000000
254537
+loop-count = 0
254537
+force-animation = no
254537
+frames = 
254537
+
254537
diff --git a/tests/test-images/gif-test-suite/invalid-code.gif b/tests/test-images/gif-test-suite/invalid-code.gif
254537
new file mode 100644
254537
index 0000000000000000000000000000000000000000..7d929c9431c0c5b7cd53f636f7711d47385f88b2
254537
GIT binary patch
254537
literal 35
254537
jcmZ?wbhEHbWMW`q_`m=H|NsBj0ns241}3Ke{~4?Sjj;#^
254537
254537
literal 0
254537
HcmV?d00001
254537
254537
diff --git a/tests/test-images/gif-test-suite/overflow-codes-max.conf b/tests/test-images/gif-test-suite/overflow-codes-max.conf
254537
new file mode 100644
254537
index 000000000..f6d3f38d8
254537
--- /dev/null
254537
+++ b/tests/test-images/gif-test-suite/overflow-codes-max.conf
254537
@@ -0,0 +1,11 @@
254537
+# Automatically generated, do not edit!
254537
+[config]
254537
+input = overflow-codes-max.gif
254537
+version = GIF89a
254537
+width = 2
254537
+height = 2
254537
+background = #000000
254537
+loop-count = 0
254537
+force-animation = no
254537
+frames = 
254537
+
254537
diff --git a/tests/test-images/gif-test-suite/overflow-codes-max.gif b/tests/test-images/gif-test-suite/overflow-codes-max.gif
254537
new file mode 100644
254537
index 0000000000000000000000000000000000000000..3d507ca7daa790c9370e69a2ab277f55d749a013
254537
GIT binary patch
254537
literal 65
254537
ncmZ?wbhEHbWMW`q_`m=H|NsBj0ns24hW`ozAU1Bm$Y2csUc3i2
254537
254537
literal 0
254537
HcmV?d00001
254537
254537
diff --git a/tests/test-images/gif-test-suite/overflow-codes.conf b/tests/test-images/gif-test-suite/overflow-codes.conf
254537
new file mode 100644
254537
index 000000000..19f57fa74
254537
--- /dev/null
254537
+++ b/tests/test-images/gif-test-suite/overflow-codes.conf
254537
@@ -0,0 +1,11 @@
254537
+# Automatically generated, do not edit!
254537
+[config]
254537
+input = overflow-codes.gif
254537
+version = GIF89a
254537
+width = 2
254537
+height = 2
254537
+background = #000000
254537
+loop-count = 0
254537
+force-animation = no
254537
+frames = 
254537
+
254537
diff --git a/tests/test-images/gif-test-suite/overflow-codes.gif b/tests/test-images/gif-test-suite/overflow-codes.gif
254537
new file mode 100644
254537
index 0000000000000000000000000000000000000000..c38053872ae2e3378ff6fb8f3eaff839fa5d35ed
254537
GIT binary patch
254537
literal 35
254537
jcmZ?wbhEHbWMW`q_`m=H|NsBj0ns241|B8>Mh0sDhc^Z!
254537
254537
literal 0
254537
HcmV?d00001
254537
254537
-- 
254537
GitLab
254537