Contents of /trunk/imlib/patches/imlib-1.9.15-libpng15.patch
Parent Directory | Revision Log
Revision 1313 -
(show annotations)
(download)
Tue May 3 16:40:43 2011 UTC (13 years, 4 months ago) by niro
File size: 10250 byte(s)
Tue May 3 16:40:43 2011 UTC (13 years, 4 months ago) by niro
File size: 10250 byte(s)
added patch to support libpng-1.5
1 | diff -Naur imlib-1.9.15/Imlib/load.c imlib-1.9.15-magellan/Imlib/load.c |
2 | --- imlib-1.9.15/Imlib/load.c 2004-09-21 02:23:20.000000000 +0200 |
3 | +++ imlib-1.9.15-magellan/Imlib/load.c 2011-05-03 18:02:14.000000000 +0200 |
4 | @@ -4,6 +4,8 @@ |
5 | #include "Imlib_private.h" |
6 | #include <setjmp.h> |
7 | |
8 | +#define G_MAXINT ((int) 0x7fffffff) |
9 | + |
10 | /* Split the ID - damages input */ |
11 | |
12 | static char * |
13 | @@ -41,13 +43,17 @@ |
14 | |
15 | /* |
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 |
19 | */ |
20 | |
21 | void * _imlib_malloc_image(unsigned int w, unsigned int h) |
22 | { |
23 | - if( w > 32767 || h > 32767) |
24 | + if (w <= 0 || w > 32767 || |
25 | + h <= 0 || h > 32767 || |
26 | + h >= (G_MAXINT/4 - 1) / w) |
27 | return NULL; |
28 | - return malloc(w * h * 3); |
29 | + return malloc(w * h * 3 + 3); |
30 | } |
31 | |
32 | #ifdef HAVE_LIBJPEG |
33 | @@ -191,12 +197,12 @@ |
34 | png_destroy_read_struct(&png_ptr, NULL, NULL); |
35 | return NULL; |
36 | } |
37 | - if (setjmp(png_ptr->jmpbuf)) |
38 | + if (setjmp(png_jmpbuf(png_ptr))) |
39 | { |
40 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
41 | return NULL; |
42 | } |
43 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
44 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) |
45 | { |
46 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
47 | return NULL; |
48 | @@ -254,7 +260,8 @@ |
49 | png_read_image(png_ptr, lines); |
50 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
51 | ptr = data; |
52 | - if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
53 | + if (color_type == PNG_COLOR_TYPE_GRAY |
54 | + || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
55 | { |
56 | for (y = 0; y < *h; y++) |
57 | { |
58 | @@ -279,6 +286,7 @@ |
59 | } |
60 | } |
61 | } |
62 | +#if 0 |
63 | else if (color_type == PNG_COLOR_TYPE_GRAY) |
64 | { |
65 | for (y = 0; y < *h; y++) |
66 | @@ -294,6 +302,7 @@ |
67 | } |
68 | } |
69 | } |
70 | +#endif |
71 | else |
72 | { |
73 | for (y = 0; y < *h; y++) |
74 | @@ -360,7 +369,9 @@ |
75 | npix = ww * hh; |
76 | *w = (int)ww; |
77 | *h = (int)hh; |
78 | - if(ww > 32767 || hh > 32767) |
79 | + if (ww <= 0 || ww > 32767 || |
80 | + hh <= 0 || hh > 32767 || |
81 | + hh >= (G_MAXINT/sizeof(uint32)) / ww) |
82 | { |
83 | TIFFClose(tif); |
84 | return NULL; |
85 | @@ -463,7 +474,7 @@ |
86 | } |
87 | *w = gif->Image.Width; |
88 | *h = gif->Image.Height; |
89 | - if (*h > 32767 || *w > 32767) |
90 | + if (*h <= 0 || *h > 32767 || *w <= 0 || *w > 32767) |
91 | { |
92 | return NULL; |
93 | } |
94 | @@ -1000,7 +1011,12 @@ |
95 | comment = 0; |
96 | quote = 0; |
97 | context = 0; |
98 | + memset(lookup, 0, sizeof(lookup)); |
99 | + |
100 | line = malloc(lsz); |
101 | + if (!line) |
102 | + return NULL; |
103 | + |
104 | while (!done) |
105 | { |
106 | pc = c; |
107 | @@ -1029,25 +1045,25 @@ |
108 | { |
109 | /* Header */ |
110 | sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp); |
111 | - if (ncolors > 32766) |
112 | + if (ncolors <= 0 || ncolors > 32766) |
113 | { |
114 | fprintf(stderr, "IMLIB ERROR: XPM files wth colors > 32766 not supported\n"); |
115 | free(line); |
116 | return NULL; |
117 | } |
118 | - if (cpp > 5) |
119 | + if (cpp <= 0 || cpp > 5) |
120 | { |
121 | fprintf(stderr, "IMLIB ERROR: XPM files with characters per pixel > 5 not supported\n"); |
122 | free(line); |
123 | return NULL; |
124 | } |
125 | - if (*w > 32767) |
126 | + if (*w <= 0 || *w > 32767) |
127 | { |
128 | fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); |
129 | free(line); |
130 | return NULL; |
131 | } |
132 | - if (*h > 32767) |
133 | + if (*h <= 0 || *h > 32767) |
134 | { |
135 | fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); |
136 | free(line); |
137 | @@ -1080,11 +1096,13 @@ |
138 | { |
139 | int slen; |
140 | int hascolor, iscolor; |
141 | + int space; |
142 | |
143 | iscolor = 0; |
144 | hascolor = 0; |
145 | tok[0] = 0; |
146 | col[0] = 0; |
147 | + space = sizeof(col) - 1; |
148 | s[0] = 0; |
149 | len = strlen(line); |
150 | strncpy(cmap[j].str, line, cpp); |
151 | @@ -1107,11 +1125,10 @@ |
152 | { |
153 | if (k >= len) |
154 | { |
155 | - if (col[0]) |
156 | - strcat(col, " "); |
157 | - if (strlen(col) + strlen(s) < sizeof(col)) |
158 | - strcat(col, s); |
159 | - } |
160 | + if (col[0] && space > 0) |
161 | + strcat(col, " "), space -= 1; |
162 | + if (slen <= space) |
163 | + strcat(col, s), space -= slen; } |
164 | if (col[0]) |
165 | { |
166 | if (!strcasecmp(col, "none")) |
167 | @@ -1140,15 +1157,17 @@ |
168 | } |
169 | } |
170 | } |
171 | + if (slen < sizeof(tok)); |
172 | strcpy(tok, s); |
173 | col[0] = 0; |
174 | + space = sizeof(col) - 1; |
175 | } |
176 | else |
177 | { |
178 | - if (col[0]) |
179 | - strcat(col, " "); |
180 | - strcat(col, s); |
181 | - } |
182 | + if (col[0] && space > 0) |
183 | + strcat(col, " "), space -=1; |
184 | + if (slen <= space) |
185 | + strcat(col, s), space -= slen; } |
186 | } |
187 | } |
188 | } |
189 | @@ -1376,12 +1395,12 @@ |
190 | sscanf(s, "%i %i", w, h); |
191 | a = *w; |
192 | b = *h; |
193 | - if (a > 32767) |
194 | + if (a <= 0 || a > 32767) |
195 | { |
196 | fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); |
197 | return NULL; |
198 | } |
199 | - if (b > 32767) |
200 | + if (b <= 0 || b > 32767) |
201 | { |
202 | fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); |
203 | return NULL; |
204 | diff -Naur imlib-1.9.15/Imlib/save.c imlib-1.9.15-magellan/Imlib/save.c |
205 | --- imlib-1.9.15/Imlib/save.c 2004-09-21 02:22:59.000000000 +0200 |
206 | +++ imlib-1.9.15-magellan/Imlib/save.c 2011-05-03 18:03:59.000000000 +0200 |
207 | @@ -342,7 +342,7 @@ |
208 | png_destroy_write_struct(&png_ptr, (png_infopp) NULL); |
209 | return 0; |
210 | } |
211 | - if (setjmp(png_ptr->jmpbuf)) |
212 | + if (setjmp(png_jmpbuf(png_ptr))) |
213 | { |
214 | fclose(f); |
215 | png_destroy_write_struct(&png_ptr, (png_infopp) NULL); |
216 | diff -Naur imlib-1.9.15/Imlib/utils.c imlib-1.9.15-magellan/Imlib/utils.c |
217 | --- imlib-1.9.15/Imlib/utils.c 2004-09-21 02:22:59.000000000 +0200 |
218 | +++ imlib-1.9.15-magellan/Imlib/utils.c 2011-05-03 18:06:41.000000000 +0200 |
219 | @@ -1496,36 +1496,56 @@ |
220 | context = 0; |
221 | ptr = NULL; |
222 | end = NULL; |
223 | + memset(lookup, 0, sizeof(lookup)); |
224 | |
225 | while (!done) |
226 | { |
227 | line = data[count++]; |
228 | + if (!line) |
229 | + break; |
230 | + line = strdup(line); |
231 | + if (!line) |
232 | + break; |
233 | + len = strlen(line); |
234 | + for (i = 0; i < len; ++i) |
235 | + { |
236 | + c = line[i]; |
237 | + if (c < 32) |
238 | + line[i] = 32; |
239 | + else if (c > 127) |
240 | + line[i] = 127; |
241 | + } |
242 | + |
243 | if (context == 0) |
244 | { |
245 | /* Header */ |
246 | sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp); |
247 | - if (ncolors > 32766) |
248 | + if (ncolors <= 0 || ncolors > 32766) |
249 | { |
250 | fprintf(stderr, "IMLIB ERROR: XPM data wth colors > 32766 not supported\n"); |
251 | free(im); |
252 | + free(line); |
253 | return NULL; |
254 | } |
255 | - if (cpp > 5) |
256 | + if (cpp <= 0 || cpp > 5) |
257 | { |
258 | fprintf(stderr, "IMLIB ERROR: XPM data with characters per pixel > 5 not supported\n"); |
259 | free(im); |
260 | + free(line); |
261 | return NULL; |
262 | } |
263 | - if (w > 32767) |
264 | + if (w <= 0 || w > 32767) |
265 | { |
266 | fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for data\n"); |
267 | free(im); |
268 | + free(line); |
269 | return NULL; |
270 | } |
271 | - if (h > 32767) |
272 | + if (h <= 0 || h > 32767) |
273 | { |
274 | fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for data\n"); |
275 | free(im); |
276 | + free(line); |
277 | return NULL; |
278 | } |
279 | cmap = malloc(sizeof(struct _cmap) * ncolors); |
280 | @@ -1533,6 +1553,7 @@ |
281 | if (!cmap) |
282 | { |
283 | free(im); |
284 | + free(line); |
285 | return NULL; |
286 | } |
287 | im->rgb_width = w; |
288 | @@ -1542,6 +1563,7 @@ |
289 | { |
290 | free(cmap); |
291 | free(im); |
292 | + free(line); |
293 | return NULL; |
294 | } |
295 | im->alpha_data = NULL; |
296 | @@ -1817,6 +1839,7 @@ |
297 | } |
298 | if ((ptr) && ((ptr - im->rgb_data) >= w * h * 3)) |
299 | done = 1; |
300 | + free(line); |
301 | } |
302 | if (!transp) |
303 | { |
304 | @@ -1959,13 +1982,13 @@ |
305 | return NULL; |
306 | } |
307 | |
308 | - if (setjmp(png_ptr->jmpbuf)) |
309 | + if (setjmp(png_jmpbuf(png_ptr))) |
310 | { |
311 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
312 | return NULL; |
313 | } |
314 | |
315 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
316 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) |
317 | { |
318 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
319 | return NULL; |
320 | diff -Naur imlib-1.9.15/gdk_imlib/io-png.c imlib-1.9.15-magellan/gdk_imlib/io-png.c |
321 | --- imlib-1.9.15/gdk_imlib/io-png.c 2002-03-04 18:06:29.000000000 +0100 |
322 | +++ imlib-1.9.15-magellan/gdk_imlib/io-png.c 2011-05-03 17:56:26.000000000 +0200 |
323 | @@ -40,13 +40,13 @@ |
324 | return NULL; |
325 | } |
326 | |
327 | - if (setjmp(png_ptr->jmpbuf)) |
328 | + if (setjmp(png_jmpbuf(png_ptr))) |
329 | { |
330 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
331 | return NULL; |
332 | } |
333 | |
334 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
335 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) |
336 | { |
337 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
338 | return NULL; |
339 | @@ -275,13 +275,13 @@ |
340 | return NULL; |
341 | } |
342 | |
343 | - if (setjmp(png_ptr->jmpbuf)) |
344 | + if (setjmp(png_jmpbuf(png_ptr))) |
345 | { |
346 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
347 | return NULL; |
348 | } |
349 | |
350 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
351 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) |
352 | { |
353 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
354 | return NULL; |
355 | @@ -301,6 +301,9 @@ |
356 | /* Setup Translators */ |
357 | if (color_type == PNG_COLOR_TYPE_PALETTE) |
358 | png_set_expand(png_ptr); |
359 | + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) |
360 | + png_set_expand(png_ptr); |
361 | + |
362 | png_set_strip_16(png_ptr); |
363 | png_set_packing(png_ptr); |
364 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) |
365 | @@ -440,13 +443,13 @@ |
366 | return NULL; |
367 | } |
368 | |
369 | - if (setjmp(png_ptr->jmpbuf)) |
370 | + if (setjmp(png_jmpbuf(png_ptr))) |
371 | { |
372 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
373 | return NULL; |
374 | } |
375 | |
376 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
377 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) |
378 | { |
379 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
380 | return NULL; |
381 | @@ -635,7 +638,7 @@ |
382 | png_destroy_write_struct(&png_ptr, (png_infopp) NULL); |
383 | return 0; |
384 | } |
385 | - if (setjmp(png_ptr->jmpbuf)) |
386 | + if (setjmp(png_jmpbuf(png_ptr))) |
387 | { |
388 | fclose(f); |
389 | png_destroy_write_struct(&png_ptr, (png_infopp) NULL); |