summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gmail.com>2020-12-07 23:15:40 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2020-12-07 23:15:40 +0000
commitf1467ce6aafa26b8fad30b7fae185afaf3a484f5 (patch)
tree4fb0bf828c10019e2e489d28d8895b17eb187bb4
parent3c6779c37482d8c322446629a5407d7bd912b23d (diff)
parentbdd3acbd48a575d418ba6bf1b32d7bda2fae1c81 (diff)
downloadgdk-pixbuf-f1467ce6aafa26b8fad30b7fae185afaf3a484f5.tar.gz
Merge branch 'lzw-loop' into 'master'
gif: Fix LZW decoder accepting invalid LZW code. Closes #164 See merge request GNOME/gdk-pixbuf!92
-rw-r--r--gdk-pixbuf/lzw.c13
-rw-r--r--tests/test-images/fail/hang_114.gifbin0 -> 5561 bytes
2 files changed, 7 insertions, 6 deletions
diff --git a/gdk-pixbuf/lzw.c b/gdk-pixbuf/lzw.c
index 9e052a6f7..105daf2b1 100644
--- a/gdk-pixbuf/lzw.c
+++ b/gdk-pixbuf/lzw.c
@@ -195,19 +195,20 @@ lzw_decoder_feed (LZWDecoder *self,
if (self->last_code != self->clear_code && self->code_table_size < MAX_CODES) {
if (self->code < self->code_table_size)
add_code (self, self->code);
- else if (self->code == self->code_table_size)
+ else
add_code (self, self->last_code);
- else {
- /* Invalid code received - just stop here */
- self->last_code = self->eoi_code;
- return output_length;
- }
/* When table is full increase code size */
if (self->code_table_size == (1 << self->code_size) && self->code_size < LZW_CODE_MAX)
self->code_size++;
}
+ /* Invalid code received - just stop here */
+ if (self->code >= self->code_table_size) {
+ self->last_code = self->eoi_code;
+ return output_length;
+ }
+
/* Convert codeword into indexes */
n_written += write_indexes (self, output + n_written, output_length - n_written);
}
diff --git a/tests/test-images/fail/hang_114.gif b/tests/test-images/fail/hang_114.gif
new file mode 100644
index 000000000..4d7d252cb
--- /dev/null
+++ b/tests/test-images/fail/hang_114.gif
Binary files differ