--- gimp-2.8.2/plug-ins/common/file-xwd.c
+++ file-xwd.c
@@ -1685,6 +1685,9 @@
   maxblue = 0; while (bluemask >> (blueshift + maxblue)) maxblue++;
   maxblue = (1 << maxblue) - 1;
 
+
+  if(maxred > sizeof(redmap) || maxgreen > sizeof(greenmap) || maxblue > sizeof(bluemap))
+	  return -1;
   /* Set map-arrays for red, green, blue */
   for (red = 0; red <= maxred; red++)
     redmap[red] = (red * 255) / maxred;
@@ -1913,6 +1916,9 @@
       maxblue = 0; while (bluemask >> (blueshift + maxblue)) maxblue++;
       maxblue = (1 << maxblue) - 1;
 
+
+      if(maxred > sizeof(redmap) || maxgreen > sizeof(greenmap) || maxblue > sizeof(bluemap))
+	  return -1;
       /* Set map-arrays for red, green, blue */
       for (red = 0; red <= maxred; red++)
         redmap[red] = (red * 255) / maxred;
