1 diff -urN imlib-1.9.13.orig/Imlib/load.c imlib-1.9.13/Imlib/load.c
2 --- imlib-1.9.13.orig/Imlib/load.c Wed Mar 13 19:06:29 2002
3 +++ imlib-1.9.13/Imlib/load.c Thu Sep 16 17:21:01 2004
5 #include "Imlib_private.h"
8 +#define G_MAXINT ((int) 0x7fffffff)
10 /* Split the ID - damages input */
16 * Make sure we don't wrap on our memory allocations
17 + * we check G_MAXINT/4 because rend.c malloc's w * h * bpp
18 + * + 3 is safety margin
21 void * _imlib_malloc_image(unsigned int w, unsigned int h)
23 - if( w > 32767 || h > 32767)
25 - return malloc(w * h * 3);
26 + if (w <= 0 || w > 32767 ||
27 + h <= 0 || h > 32767 ||
28 + h >= (G_MAXINT/4 - 1) / w)
30 + return malloc(w * h * 3 + 3);
38 - if(ww > 32767 || hh > 32767)
39 + if (ww <= 0 || ww > 32767 ||
40 + hh <= 0 || hh > 32767 ||
41 + hh >= (G_MAXINT/sizeof(uint32)) / ww)
47 *w = gif->Image.Width;
48 *h = gif->Image.Height;
49 - if (*h > 32767 || *w > 32767)
50 + if (*h <= 0 || *h > 32767 || *w <= 0 || *w > 32767)
58 + memset(lookup, 0, sizeof(lookup));
67 @@ -994,25 +1007,25 @@
70 sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp);
71 - if (ncolors > 32766)
72 + if (ncolors <= 0 || ncolors > 32766)
74 fprintf(stderr, "IMLIB ERROR: XPM files wth colors > 32766 not supported\n");
79 + if (cpp <= 0 || cpp > 5)
81 fprintf(stderr, "IMLIB ERROR: XPM files with characters per pixel > 5 not supported\n");
86 + if (*w <= 0 || *w > 32767)
88 fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n");
93 + if (*h <= 0 || *h > 32767)
95 fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n");
97 @@ -1045,11 +1058,13 @@
100 int hascolor, iscolor;
107 + space = sizeof(col) - 1;
110 strncpy(cmap[j].str, line, cpp);
111 @@ -1072,10 +1087,10 @@
117 - if (strlen(col) + strlen(s) < sizeof(col))
119 + if (col[0] && space > 0)
120 + strcat(col, " "), space -= 1;
122 + strcat(col, s), space -= slen;
126 @@ -1105,14 +1120,17 @@
131 + if (slen < sizeof(tok));
134 + space = sizeof(col) - 1;
141 + if (col[0] && space > 0)
142 + strcat(col, " "), space -=1;
144 + strcat(col, s), space -= slen;
148 @@ -1341,12 +1359,12 @@
149 sscanf(s, "%i %i", w, h);
153 + if (a <= 0 || a > 32767)
155 fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n");
159 + if (b <= 0 || b > 32767)
161 fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n");
163 diff -urN imlib-1.9.13.orig/Imlib/utils.c imlib-1.9.13/Imlib/utils.c
164 --- imlib-1.9.13.orig/Imlib/utils.c Mon Mar 4 17:45:28 2002
165 +++ imlib-1.9.13/Imlib/utils.c Thu Sep 16 17:21:15 2004
166 @@ -1496,36 +1496,56 @@
170 + memset(lookup, 0, sizeof(lookup));
174 line = data[count++];
177 + line = strdup(line);
180 + len = strlen(line);
181 + for (i = 0; i < len; ++i)
193 sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp);
194 - if (ncolors > 32766)
195 + if (ncolors <= 0 || ncolors > 32766)
197 fprintf(stderr, "IMLIB ERROR: XPM data wth colors > 32766 not supported\n");
203 + if (cpp <= 0 || cpp > 5)
205 fprintf(stderr, "IMLIB ERROR: XPM data with characters per pixel > 5 not supported\n");
211 + if (w <= 0 || w > 32767)
213 fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for data\n");
219 + if (h <= 0 || h > 32767)
221 fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for data\n");
226 cmap = malloc(sizeof(struct _cmap) * ncolors);
227 @@ -1533,6 +1553,7 @@
235 @@ -1542,6 +1563,7 @@
242 im->alpha_data = NULL;
243 @@ -1817,6 +1839,7 @@
245 if ((ptr) && ((ptr - im->rgb_data) >= w * h * 3))
251 diff -urN imlib-1.9.13.orig/gdk_imlib/io-gif.c imlib-1.9.13/gdk_imlib/io-gif.c
252 --- imlib-1.9.13.orig/gdk_imlib/io-gif.c Mon Mar 4 17:26:51 2002
253 +++ imlib-1.9.13/gdk_imlib/io-gif.c Thu Sep 16 16:11:31 2004
256 *w = gif->Image.Width;
257 *h = gif->Image.Height;
258 - if(*h > 32767 || *w > 32767)
259 + if(*h <= 0 || *h > 32767 || *w <= 0 || *w > 32767)
263 diff -urN imlib-1.9.13.orig/gdk_imlib/io-ppm.c imlib-1.9.13/gdk_imlib/io-ppm.c
264 --- imlib-1.9.13.orig/gdk_imlib/io-ppm.c Mon Mar 4 17:26:51 2002
265 +++ imlib-1.9.13/gdk_imlib/io-ppm.c Thu Sep 16 16:13:13 2004
267 sscanf(s, "%i %i", w, h);
271 + if (a <= 0 || a > 32767)
273 fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for file\n");
277 + if (b <= 0 || b > 32767)
279 fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for file\n");
281 diff -urN imlib-1.9.13.orig/gdk_imlib/io-tiff.c imlib-1.9.13/gdk_imlib/io-tiff.c
282 --- imlib-1.9.13.orig/gdk_imlib/io-tiff.c Mon Mar 4 17:26:51 2002
283 +++ imlib-1.9.13/gdk_imlib/io-tiff.c Thu Sep 16 16:13:57 2004
288 - if(ww > 32767 || hh > 32767)
289 + if (ww <= 0 || ww > 32767 ||
290 + hh <= 0 || hh > 32767 ||
291 + hh >= (G_MAXINT/sizeof(uint32)) / ww)
295 diff -urN imlib-1.9.13.orig/gdk_imlib/io-xpm.c imlib-1.9.13/gdk_imlib/io-xpm.c
296 --- imlib-1.9.13.orig/gdk_imlib/io-xpm.c Mon Mar 4 17:26:51 2002
297 +++ imlib-1.9.13/gdk_imlib/io-xpm.c Thu Sep 16 17:08:24 2004
302 + memset(lookup, 0, sizeof(lookup));
314 sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp);
315 - if (ncolors > 32766)
316 + if (ncolors <= 0 || ncolors > 32766)
318 fprintf(stderr, "gdk_imlib ERROR: XPM files wth colors > 32766 not supported\n");
323 + if (cpp <= 0 || cpp > 5)
325 fprintf(stderr, "gdk_imlib ERROR: XPM files with characters per pixel > 5 not supported\n");
330 + if (*w <= 0 || *w > 32767)
332 fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for file\n");
337 + if (*h <= 0 || *h > 32767)
339 fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for file\n");
341 @@ -120,11 +124,13 @@
344 int hascolor, iscolor;
351 + space = sizeof(col) - 1;
354 strncpy(cmap[j].str, line, cpp);
355 @@ -147,10 +153,10 @@
361 - if (strlen(col) + strlen(s) < sizeof(col))
363 + if (col[0] && space > 0)
364 + strncat(col, " ", space), space -= 1;
366 + strcat(col, s), space -= slen;
370 @@ -180,14 +186,17 @@
375 + if (slen < sizeof(tok))
378 + space = sizeof(col) - 1;
385 + if (col[0] && space > 0)
386 + strcat(col, " "), space -= 1;
388 + strcat(col, s), space -= slen;
392 diff -urN imlib-1.9.13.orig/gdk_imlib/misc.c imlib-1.9.13/gdk_imlib/misc.c
393 --- imlib-1.9.13.orig/gdk_imlib/misc.c Mon Mar 4 17:26:51 2002
394 +++ imlib-1.9.13/gdk_imlib/misc.c Thu Sep 16 16:35:32 2004
395 @@ -1355,11 +1355,16 @@
398 * Make sure we don't wrap on our memory allocations
399 + * we check G_MAX_INT/4 because rend.c malloc's w * h * bpp
400 + * + 3 is safety margin
403 void *_gdk_malloc_image(unsigned int w, unsigned int h)
405 - if( w > 32767 || h > 32767)
406 + if (w <= 0 || w > 32767 ||
407 + h <= 0 || h > 32767 ||
408 + h >= (G_MAXINT/4 - 1) / w)
410 - return malloc(w * h * 3);
411 + return malloc(w * h * 3 + 3);
414 diff -urN imlib-1.9.13.orig/gdk_imlib/utils.c imlib-1.9.13/gdk_imlib/utils.c
415 --- imlib-1.9.13.orig/gdk_imlib/utils.c Mon Mar 4 17:26:51 2002
416 +++ imlib-1.9.13/gdk_imlib/utils.c Thu Sep 16 17:28:35 2004
417 @@ -1236,36 +1236,56 @@
421 + memset(lookup, 0, sizeof(lookup));
425 line = data[count++];
428 + line = strdup(line);
431 + len = strlen(line);
432 + for (i = 0; i < len; ++i)
444 sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp);
445 - if (ncolors > 32766)
446 + if (ncolors <= 0 || ncolors > 32766)
448 fprintf(stderr, "gdk_imlib ERROR: XPM data wth colors > 32766 not supported\n");
454 + if (cpp <= 0 || cpp > 5)
456 fprintf(stderr, "gdk_imlib ERROR: XPM data with characters per pixel > 5 not supported\n");
462 + if (w <= 0 || w > 32767)
464 fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for data\n");
470 + if (h <= 0 || h > 32767)
472 fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for data\n");
477 cmap = malloc(sizeof(struct _cmap) * ncolors);
478 @@ -1273,6 +1293,7 @@
486 @@ -1282,6 +1303,7 @@
493 im->alpha_data = NULL;
494 @@ -1355,7 +1377,7 @@
495 strcpy(col + colptr, " ");
498 - if (colptr + ls <= sizeof(col))
499 + if (colptr + ls < sizeof(col))
501 strcpy(col + colptr, s);
503 @@ -1558,6 +1580,7 @@
505 if ((ptr) && ((ptr - im->rgb_data) >= w * h * 3))