--- gimp-2.6.10/plug-ins/common/file-gif-load.c.orig 2011-08-26 11:44:21.281103394 +0800
+++ gimp-2.6.10/plug-ins/common/file-gif-load.c 2011-08-26 11:45:53.251146894 +0800
@@ -697,7 +697,8 @@
static gint firstcode, oldcode;
static gint clear_code, end_code;
static gint table[2][(1 << MAX_LZW_BITS)];
- static gint stack[(1 << (MAX_LZW_BITS)) * 2], *sp;
+#define STACK_SIZE ((1 << (MAX_LZW_BITS)) * 2)
+ static gint stack[STACK_SIZE], *sp;
gint i;
if (just_reset_LZW)
@@ -772,7 +773,7 @@
return firstcode;
}
- else if (code == end_code)
+ else if (code == end_code || code > max_code)
{
gint count;
guchar buf[260];
@@ -791,13 +792,14 @@
incode = code;
- if (code >= max_code)
+ if (code == max_code)
{
- *sp++ = firstcode;
+ if (sp < &(stack[STACK_SIZE]))
+ *sp++ = firstcode;
code = oldcode;
}
- while (code >= clear_code)
+ while (code >= clear_code && sp < &(stack[STACK_SIZE]))
{
*sp++ = table[1][code];
if (code == table[0][code])
@@ -808,7 +810,8 @@
code = table[0][code];
}
- *sp++ = firstcode = table[1][code];
+ if (sp < &(stack[STACK_SIZE]))
+ *sp++ = firstcode = table[1][code];
if ((code = max_code) < (1 << MAX_LZW_BITS))
{