OLD | NEW |
| 1 |
1 /* pngset.c - storage of image information into info struct | 2 /* pngset.c - storage of image information into info struct |
2 * | 3 * |
3 * Last changed in libpng 1.6.3 [July 18, 2013] | 4 * Last changed in libpng 1.6.19 [November 12, 2015] |
4 * Copyright (c) 1998-2013 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson |
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
7 * | 8 * |
8 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
9 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
10 * and license in png.h | 11 * and license in png.h |
11 * | 12 * |
12 * The functions here are used during reads to store data from the file | 13 * The functions here are used during reads to store data from the file |
13 * into the info struct, and during writes to store application data | 14 * into the info struct, and during writes to store application data |
14 * into the info struct for writing into the file. This abstracts the | 15 * into the info struct for writing into the file. This abstracts the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 xy.redx = red_x; | 52 xy.redx = red_x; |
52 xy.redy = red_y; | 53 xy.redy = red_y; |
53 xy.greenx = green_x; | 54 xy.greenx = green_x; |
54 xy.greeny = green_y; | 55 xy.greeny = green_y; |
55 xy.bluex = blue_x; | 56 xy.bluex = blue_x; |
56 xy.bluey = blue_y; | 57 xy.bluey = blue_y; |
57 xy.whitex = white_x; | 58 xy.whitex = white_x; |
58 xy.whitey = white_y; | 59 xy.whitey = white_y; |
59 | 60 |
60 if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy, | 61 if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy, |
61 2/* override with app values*/)) | 62 2/* override with app values*/) != 0) |
62 info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; | 63 info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; |
63 | 64 |
64 png_colorspace_sync_info(png_ptr, info_ptr); | 65 png_colorspace_sync_info(png_ptr, info_ptr); |
65 } | 66 } |
66 | 67 |
67 void PNGFAPI | 68 void PNGFAPI |
68 png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, | 69 png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, |
69 png_fixed_point int_red_X, png_fixed_point int_red_Y, | 70 png_fixed_point int_red_X, png_fixed_point int_red_Y, |
70 png_fixed_point int_red_Z, png_fixed_point int_green_X, | 71 png_fixed_point int_red_Z, png_fixed_point int_green_X, |
71 png_fixed_point int_green_Y, png_fixed_point int_green_Z, | 72 png_fixed_point int_green_Y, png_fixed_point int_green_Z, |
(...skipping 10 matching lines...) Expand all Loading... |
82 XYZ.red_X = int_red_X; | 83 XYZ.red_X = int_red_X; |
83 XYZ.red_Y = int_red_Y; | 84 XYZ.red_Y = int_red_Y; |
84 XYZ.red_Z = int_red_Z; | 85 XYZ.red_Z = int_red_Z; |
85 XYZ.green_X = int_green_X; | 86 XYZ.green_X = int_green_X; |
86 XYZ.green_Y = int_green_Y; | 87 XYZ.green_Y = int_green_Y; |
87 XYZ.green_Z = int_green_Z; | 88 XYZ.green_Z = int_green_Z; |
88 XYZ.blue_X = int_blue_X; | 89 XYZ.blue_X = int_blue_X; |
89 XYZ.blue_Y = int_blue_Y; | 90 XYZ.blue_Y = int_blue_Y; |
90 XYZ.blue_Z = int_blue_Z; | 91 XYZ.blue_Z = int_blue_Z; |
91 | 92 |
92 if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, &XYZ, 2)) | 93 if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, |
| 94 &XYZ, 2) != 0) |
93 info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; | 95 info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; |
94 | 96 |
95 png_colorspace_sync_info(png_ptr, info_ptr); | 97 png_colorspace_sync_info(png_ptr, info_ptr); |
96 } | 98 } |
97 | 99 |
98 # ifdef PNG_FLOATING_POINT_SUPPORTED | 100 # ifdef PNG_FLOATING_POINT_SUPPORTED |
99 void PNGAPI | 101 void PNGAPI |
100 png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, | 102 png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, |
101 double white_x, double white_y, double red_x, double red_y, | 103 double white_x, double white_y, double red_x, double red_y, |
102 double green_x, double green_y, double blue_x, double blue_y) | 104 double green_x, double green_y, double blue_x, double blue_y) |
(...skipping 11 matching lines...) Expand all Loading... |
114 | 116 |
115 void PNGAPI | 117 void PNGAPI |
116 png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, | 118 png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, |
117 double red_Y, double red_Z, double green_X, double green_Y, double green_Z, | 119 double red_Y, double red_Z, double green_X, double green_Y, double green_Z, |
118 double blue_X, double blue_Y, double blue_Z) | 120 double blue_X, double blue_Y, double blue_Z) |
119 { | 121 { |
120 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, | 122 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, |
121 png_fixed(png_ptr, red_X, "cHRM Red X"), | 123 png_fixed(png_ptr, red_X, "cHRM Red X"), |
122 png_fixed(png_ptr, red_Y, "cHRM Red Y"), | 124 png_fixed(png_ptr, red_Y, "cHRM Red Y"), |
123 png_fixed(png_ptr, red_Z, "cHRM Red Z"), | 125 png_fixed(png_ptr, red_Z, "cHRM Red Z"), |
124 png_fixed(png_ptr, green_X, "cHRM Red X"), | 126 png_fixed(png_ptr, green_X, "cHRM Green X"), |
125 png_fixed(png_ptr, green_Y, "cHRM Red Y"), | 127 png_fixed(png_ptr, green_Y, "cHRM Green Y"), |
126 png_fixed(png_ptr, green_Z, "cHRM Red Z"), | 128 png_fixed(png_ptr, green_Z, "cHRM Green Z"), |
127 png_fixed(png_ptr, blue_X, "cHRM Red X"), | 129 png_fixed(png_ptr, blue_X, "cHRM Blue X"), |
128 png_fixed(png_ptr, blue_Y, "cHRM Red Y"), | 130 png_fixed(png_ptr, blue_Y, "cHRM Blue Y"), |
129 png_fixed(png_ptr, blue_Z, "cHRM Red Z")); | 131 png_fixed(png_ptr, blue_Z, "cHRM Blue Z")); |
130 } | 132 } |
131 # endif /* PNG_FLOATING_POINT_SUPPORTED */ | 133 # endif /* FLOATING_POINT */ |
132 | 134 |
133 #endif /* PNG_cHRM_SUPPORTED */ | 135 #endif /* cHRM */ |
134 | 136 |
135 #ifdef PNG_gAMA_SUPPORTED | 137 #ifdef PNG_gAMA_SUPPORTED |
136 void PNGFAPI | 138 void PNGFAPI |
137 png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, | 139 png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, |
138 png_fixed_point file_gamma) | 140 png_fixed_point file_gamma) |
139 { | 141 { |
140 png_debug1(1, "in %s storage function", "gAMA"); | 142 png_debug1(1, "in %s storage function", "gAMA"); |
141 | 143 |
142 if (png_ptr == NULL || info_ptr == NULL) | 144 if (png_ptr == NULL || info_ptr == NULL) |
143 return; | 145 return; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 183 |
182 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in | 184 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in |
183 * version 1.2.1 | 185 * version 1.2.1 |
184 */ | 186 */ |
185 info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr, | 187 info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr, |
186 PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16)))); | 188 PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16)))); |
187 | 189 |
188 if (info_ptr->hist == NULL) | 190 if (info_ptr->hist == NULL) |
189 { | 191 { |
190 png_warning(png_ptr, "Insufficient memory for hIST chunk data"); | 192 png_warning(png_ptr, "Insufficient memory for hIST chunk data"); |
| 193 |
191 return; | 194 return; |
192 } | 195 } |
193 | 196 |
194 info_ptr->free_me |= PNG_FREE_HIST; | 197 info_ptr->free_me |= PNG_FREE_HIST; |
195 | 198 |
196 for (i = 0; i < info_ptr->num_palette; i++) | 199 for (i = 0; i < info_ptr->num_palette; i++) |
197 info_ptr->hist[i] = hist[i]; | 200 info_ptr->hist[i] = hist[i]; |
198 | 201 |
199 info_ptr->valid |= PNG_INFO_hIST; | 202 info_ptr->valid |= PNG_INFO_hIST; |
200 } | 203 } |
(...skipping 18 matching lines...) Expand all Loading... |
219 info_ptr->filter_type = (png_byte)filter_type; | 222 info_ptr->filter_type = (png_byte)filter_type; |
220 info_ptr->interlace_type = (png_byte)interlace_type; | 223 info_ptr->interlace_type = (png_byte)interlace_type; |
221 | 224 |
222 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, | 225 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, |
223 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, | 226 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
224 info_ptr->compression_type, info_ptr->filter_type); | 227 info_ptr->compression_type, info_ptr->filter_type); |
225 | 228 |
226 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 229 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
227 info_ptr->channels = 1; | 230 info_ptr->channels = 1; |
228 | 231 |
229 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) | 232 else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) |
230 info_ptr->channels = 3; | 233 info_ptr->channels = 3; |
231 | 234 |
232 else | 235 else |
233 info_ptr->channels = 1; | 236 info_ptr->channels = 1; |
234 | 237 |
235 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) | 238 if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) |
236 info_ptr->channels++; | 239 info_ptr->channels++; |
237 | 240 |
238 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); | 241 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); |
239 | 242 |
240 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); | 243 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); |
241 } | 244 } |
242 | 245 |
243 #ifdef PNG_oFFs_SUPPORTED | 246 #ifdef PNG_oFFs_SUPPORTED |
244 void PNGAPI | 247 void PNGAPI |
245 png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr, | 248 png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr, |
(...skipping 16 matching lines...) Expand all Loading... |
262 png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, | 265 png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, |
263 png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, | 266 png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, |
264 int nparams, png_const_charp units, png_charpp params) | 267 int nparams, png_const_charp units, png_charpp params) |
265 { | 268 { |
266 png_size_t length; | 269 png_size_t length; |
267 int i; | 270 int i; |
268 | 271 |
269 png_debug1(1, "in %s storage function", "pCAL"); | 272 png_debug1(1, "in %s storage function", "pCAL"); |
270 | 273 |
271 if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL | 274 if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL |
272 || (nparams > 0 && params == NULL)) | 275 || (nparams > 0 && params == NULL)) |
273 return; | 276 return; |
274 | 277 |
275 length = strlen(purpose) + 1; | 278 length = strlen(purpose) + 1; |
276 png_debug1(3, "allocating purpose for info (%lu bytes)", | 279 png_debug1(3, "allocating purpose for info (%lu bytes)", |
277 (unsigned long)length); | 280 (unsigned long)length); |
278 | 281 |
279 /* TODO: validate format of calibration name and unit name */ | 282 /* TODO: validate format of calibration name and unit name */ |
280 | 283 |
281 /* Check that the type matches the specification. */ | 284 /* Check that the type matches the specification. */ |
282 if (type < 0 || type > 3) | 285 if (type < 0 || type > 3) |
283 png_error(png_ptr, "Invalid pCAL equation type"); | 286 png_error(png_ptr, "Invalid pCAL equation type"); |
284 | 287 |
285 if (nparams < 0 || nparams > 255) | 288 if (nparams < 0 || nparams > 255) |
286 png_error(png_ptr, "Invalid pCAL parameter count"); | 289 png_error(png_ptr, "Invalid pCAL parameter count"); |
287 | 290 |
288 /* Validate params[nparams] */ | 291 /* Validate params[nparams] */ |
289 for (i=0; i<nparams; ++i) | 292 for (i=0; i<nparams; ++i) |
| 293 { |
290 if (params[i] == NULL || | 294 if (params[i] == NULL || |
291 !png_check_fp_string(params[i], strlen(params[i]))) | 295 !png_check_fp_string(params[i], strlen(params[i]))) |
292 png_error(png_ptr, "Invalid format for pCAL parameter"); | 296 png_error(png_ptr, "Invalid format for pCAL parameter"); |
| 297 } |
293 | 298 |
294 info_ptr->pcal_purpose = png_voidcast(png_charp, | 299 info_ptr->pcal_purpose = png_voidcast(png_charp, |
295 png_malloc_warn(png_ptr, length)); | 300 png_malloc_warn(png_ptr, length)); |
296 | 301 |
297 if (info_ptr->pcal_purpose == NULL) | 302 if (info_ptr->pcal_purpose == NULL) |
298 { | 303 { |
299 png_warning(png_ptr, "Insufficient memory for pCAL purpose"); | 304 png_warning(png_ptr, "Insufficient memory for pCAL purpose"); |
| 305 |
300 return; | 306 return; |
301 } | 307 } |
302 | 308 |
303 memcpy(info_ptr->pcal_purpose, purpose, length); | 309 memcpy(info_ptr->pcal_purpose, purpose, length); |
304 | 310 |
305 png_debug(3, "storing X0, X1, type, and nparams in info"); | 311 png_debug(3, "storing X0, X1, type, and nparams in info"); |
306 info_ptr->pcal_X0 = X0; | 312 info_ptr->pcal_X0 = X0; |
307 info_ptr->pcal_X1 = X1; | 313 info_ptr->pcal_X1 = X1; |
308 info_ptr->pcal_type = (png_byte)type; | 314 info_ptr->pcal_type = (png_byte)type; |
309 info_ptr->pcal_nparams = (png_byte)nparams; | 315 info_ptr->pcal_nparams = (png_byte)nparams; |
310 | 316 |
311 length = strlen(units) + 1; | 317 length = strlen(units) + 1; |
312 png_debug1(3, "allocating units for info (%lu bytes)", | 318 png_debug1(3, "allocating units for info (%lu bytes)", |
313 (unsigned long)length); | 319 (unsigned long)length); |
314 | 320 |
315 info_ptr->pcal_units = png_voidcast(png_charp, | 321 info_ptr->pcal_units = png_voidcast(png_charp, |
316 png_malloc_warn(png_ptr, length)); | 322 png_malloc_warn(png_ptr, length)); |
317 | 323 |
318 if (info_ptr->pcal_units == NULL) | 324 if (info_ptr->pcal_units == NULL) |
319 { | 325 { |
320 png_warning(png_ptr, "Insufficient memory for pCAL units"); | 326 png_warning(png_ptr, "Insufficient memory for pCAL units"); |
| 327 |
321 return; | 328 return; |
322 } | 329 } |
323 | 330 |
324 memcpy(info_ptr->pcal_units, units, length); | 331 memcpy(info_ptr->pcal_units, units, length); |
325 | 332 |
326 info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, | 333 info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, |
327 (png_size_t)((nparams + 1) * (sizeof (png_charp))))); | 334 (png_size_t)((nparams + 1) * (sizeof (png_charp))))); |
328 | 335 |
329 if (info_ptr->pcal_params == NULL) | 336 if (info_ptr->pcal_params == NULL) |
330 { | 337 { |
331 png_warning(png_ptr, "Insufficient memory for pCAL params"); | 338 png_warning(png_ptr, "Insufficient memory for pCAL params"); |
| 339 |
332 return; | 340 return; |
333 } | 341 } |
334 | 342 |
335 memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp))); | 343 memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp))); |
336 | 344 |
337 for (i = 0; i < nparams; i++) | 345 for (i = 0; i < nparams; i++) |
338 { | 346 { |
339 length = strlen(params[i]) + 1; | 347 length = strlen(params[i]) + 1; |
340 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, | 348 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, |
341 (unsigned long)length); | 349 (unsigned long)length); |
342 | 350 |
343 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); | 351 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); |
344 | 352 |
345 if (info_ptr->pcal_params[i] == NULL) | 353 if (info_ptr->pcal_params[i] == NULL) |
346 { | 354 { |
347 png_warning(png_ptr, "Insufficient memory for pCAL parameter"); | 355 png_warning(png_ptr, "Insufficient memory for pCAL parameter"); |
| 356 |
348 return; | 357 return; |
349 } | 358 } |
350 | 359 |
351 memcpy(info_ptr->pcal_params[i], params[i], length); | 360 memcpy(info_ptr->pcal_params[i], params[i], length); |
352 } | 361 } |
353 | 362 |
354 info_ptr->valid |= PNG_INFO_pCAL; | 363 info_ptr->valid |= PNG_INFO_pCAL; |
355 info_ptr->free_me |= PNG_FREE_PCAL; | 364 info_ptr->free_me |= PNG_FREE_PCAL; |
356 } | 365 } |
357 #endif | 366 #endif |
(...skipping 29 matching lines...) Expand all Loading... |
387 ++lengthw; | 396 ++lengthw; |
388 | 397 |
389 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); | 398 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); |
390 | 399 |
391 info_ptr->scal_s_width = png_voidcast(png_charp, | 400 info_ptr->scal_s_width = png_voidcast(png_charp, |
392 png_malloc_warn(png_ptr, lengthw)); | 401 png_malloc_warn(png_ptr, lengthw)); |
393 | 402 |
394 if (info_ptr->scal_s_width == NULL) | 403 if (info_ptr->scal_s_width == NULL) |
395 { | 404 { |
396 png_warning(png_ptr, "Memory allocation failed while processing sCAL"); | 405 png_warning(png_ptr, "Memory allocation failed while processing sCAL"); |
| 406 |
397 return; | 407 return; |
398 } | 408 } |
399 | 409 |
400 memcpy(info_ptr->scal_s_width, swidth, lengthw); | 410 memcpy(info_ptr->scal_s_width, swidth, lengthw); |
401 | 411 |
402 ++lengthh; | 412 ++lengthh; |
403 | 413 |
404 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); | 414 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); |
405 | 415 |
406 info_ptr->scal_s_height = png_voidcast(png_charp, | 416 info_ptr->scal_s_height = png_voidcast(png_charp, |
407 png_malloc_warn(png_ptr, lengthh)); | 417 png_malloc_warn(png_ptr, lengthh)); |
408 | 418 |
409 if (info_ptr->scal_s_height == NULL) | 419 if (info_ptr->scal_s_height == NULL) |
410 { | 420 { |
411 png_free (png_ptr, info_ptr->scal_s_width); | 421 png_free (png_ptr, info_ptr->scal_s_width); |
412 info_ptr->scal_s_width = NULL; | 422 info_ptr->scal_s_width = NULL; |
413 | 423 |
414 png_warning(png_ptr, "Memory allocation failed while processing sCAL"); | 424 png_warning(png_ptr, "Memory allocation failed while processing sCAL"); |
| 425 |
415 return; | 426 return; |
416 } | 427 } |
417 | 428 |
418 memcpy(info_ptr->scal_s_height, sheight, lengthh); | 429 memcpy(info_ptr->scal_s_height, sheight, lengthh); |
419 | 430 |
420 info_ptr->valid |= PNG_INFO_sCAL; | 431 info_ptr->valid |= PNG_INFO_sCAL; |
421 info_ptr->free_me |= PNG_FREE_SCAL; | 432 info_ptr->free_me |= PNG_FREE_SCAL; |
422 } | 433 } |
423 | 434 |
424 # ifdef PNG_FLOATING_POINT_SUPPORTED | 435 # ifdef PNG_FLOATING_POINT_SUPPORTED |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 info_ptr->phys_unit_type = (png_byte)unit_type; | 506 info_ptr->phys_unit_type = (png_byte)unit_type; |
496 info_ptr->valid |= PNG_INFO_pHYs; | 507 info_ptr->valid |= PNG_INFO_pHYs; |
497 } | 508 } |
498 #endif | 509 #endif |
499 | 510 |
500 void PNGAPI | 511 void PNGAPI |
501 png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, | 512 png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, |
502 png_const_colorp palette, int num_palette) | 513 png_const_colorp palette, int num_palette) |
503 { | 514 { |
504 | 515 |
| 516 png_uint_32 max_palette_length; |
| 517 |
505 png_debug1(1, "in %s storage function", "PLTE"); | 518 png_debug1(1, "in %s storage function", "PLTE"); |
506 | 519 |
507 if (png_ptr == NULL || info_ptr == NULL) | 520 if (png_ptr == NULL || info_ptr == NULL) |
508 return; | 521 return; |
509 | 522 |
510 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) | 523 max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? |
| 524 (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; |
| 525 |
| 526 if (num_palette < 0 || num_palette > (int) max_palette_length) |
511 { | 527 { |
512 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 528 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
513 png_error(png_ptr, "Invalid palette length"); | 529 png_error(png_ptr, "Invalid palette length"); |
514 | 530 |
515 else | 531 else |
516 { | 532 { |
517 png_warning(png_ptr, "Invalid palette length"); | 533 png_warning(png_ptr, "Invalid palette length"); |
| 534 |
518 return; | 535 return; |
519 } | 536 } |
520 } | 537 } |
521 | 538 |
522 if ((num_palette > 0 && palette == NULL) || | 539 if ((num_palette > 0 && palette == NULL) || |
523 (num_palette == 0 | 540 (num_palette == 0 |
524 # ifdef PNG_MNG_FEATURES_SUPPORTED | 541 # ifdef PNG_MNG_FEATURES_SUPPORTED |
525 && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 | 542 && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 |
526 # endif | 543 # endif |
527 )) | 544 )) |
528 { | 545 { |
529 png_chunk_report(png_ptr, "Invalid palette", PNG_CHUNK_ERROR); | 546 png_error(png_ptr, "Invalid palette"); |
530 return; | |
531 } | 547 } |
532 | 548 |
533 /* It may not actually be necessary to set png_ptr->palette here; | 549 /* It may not actually be necessary to set png_ptr->palette here; |
534 * we do it for backward compatibility with the way the png_handle_tRNS | 550 * we do it for backward compatibility with the way the png_handle_tRNS |
535 * function used to do the allocation. | 551 * function used to do the allocation. |
536 * | 552 * |
537 * 1.6.0: the above statement appears to be incorrect; something has to set | 553 * 1.6.0: the above statement appears to be incorrect; something has to set |
538 * the palette inside png_struct on read. | 554 * the palette inside png_struct on read. |
539 */ | 555 */ |
540 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); | 556 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); |
541 | 557 |
542 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead | 558 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead |
543 * of num_palette entries, in case of an invalid PNG file that has | 559 * of num_palette entries, in case of an invalid PNG file or incorrect |
544 * too-large sample values. | 560 * call to png_set_PLTE() with too-large sample values. |
545 */ | 561 */ |
546 png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, | 562 png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, |
547 PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); | 563 PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); |
548 | 564 |
549 if (num_palette > 0) | 565 if (num_palette > 0) |
550 memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color))); | 566 memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color))); |
551 info_ptr->palette = png_ptr->palette; | 567 info_ptr->palette = png_ptr->palette; |
552 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; | 568 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; |
553 | 569 |
554 info_ptr->free_me |= PNG_FREE_PLTE; | 570 info_ptr->free_me |= PNG_FREE_PLTE; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 602 |
587 void PNGAPI | 603 void PNGAPI |
588 png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, | 604 png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, |
589 int srgb_intent) | 605 int srgb_intent) |
590 { | 606 { |
591 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); | 607 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); |
592 | 608 |
593 if (png_ptr == NULL || info_ptr == NULL) | 609 if (png_ptr == NULL || info_ptr == NULL) |
594 return; | 610 return; |
595 | 611 |
596 if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent)) | 612 if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, |
| 613 srgb_intent) != 0) |
597 { | 614 { |
598 /* This causes the gAMA and cHRM to be written too */ | 615 /* This causes the gAMA and cHRM to be written too */ |
599 info_ptr->colorspace.flags |= | 616 info_ptr->colorspace.flags |= |
600 PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; | 617 PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; |
601 } | 618 } |
602 | 619 |
603 png_colorspace_sync_info(png_ptr, info_ptr); | 620 png_colorspace_sync_info(png_ptr, info_ptr); |
604 } | 621 } |
605 #endif /* sRGB */ | 622 #endif /* sRGB */ |
606 | 623 |
(...skipping 22 matching lines...) Expand all Loading... |
629 * the info_ptr color_type field to png_colorspace_set_ICC because in the | 646 * the info_ptr color_type field to png_colorspace_set_ICC because in the |
630 * write case it has not yet been stored in png_ptr. | 647 * write case it has not yet been stored in png_ptr. |
631 */ | 648 */ |
632 { | 649 { |
633 int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name, | 650 int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name, |
634 proflen, profile, info_ptr->color_type); | 651 proflen, profile, info_ptr->color_type); |
635 | 652 |
636 png_colorspace_sync_info(png_ptr, info_ptr); | 653 png_colorspace_sync_info(png_ptr, info_ptr); |
637 | 654 |
638 /* Don't do any of the copying if the profile was bad, or inconsistent. */ | 655 /* Don't do any of the copying if the profile was bad, or inconsistent. */ |
639 if (!result) | 656 if (result == 0) |
640 return; | 657 return; |
641 | 658 |
642 /* But do write the gAMA and cHRM chunks from the profile. */ | 659 /* But do write the gAMA and cHRM chunks from the profile. */ |
643 info_ptr->colorspace.flags |= | 660 info_ptr->colorspace.flags |= |
644 PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; | 661 PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; |
645 } | 662 } |
646 | 663 |
647 length = strlen(name)+1; | 664 length = strlen(name)+1; |
648 new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length)); | 665 new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length)); |
649 | 666 |
650 if (new_iccp_name == NULL) | 667 if (new_iccp_name == NULL) |
651 { | 668 { |
652 png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk"); | 669 png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk"); |
| 670 |
653 return; | 671 return; |
654 } | 672 } |
655 | 673 |
656 memcpy(new_iccp_name, name, length); | 674 memcpy(new_iccp_name, name, length); |
657 new_iccp_profile = png_voidcast(png_bytep, | 675 new_iccp_profile = png_voidcast(png_bytep, |
658 png_malloc_warn(png_ptr, proflen)); | 676 png_malloc_warn(png_ptr, proflen)); |
659 | 677 |
660 if (new_iccp_profile == NULL) | 678 if (new_iccp_profile == NULL) |
661 { | 679 { |
662 png_free(png_ptr, new_iccp_name); | 680 png_free(png_ptr, new_iccp_name); |
663 png_benign_error(png_ptr, | 681 png_benign_error(png_ptr, |
664 "Insufficient memory to process iCCP profile"); | 682 "Insufficient memory to process iCCP profile"); |
| 683 |
665 return; | 684 return; |
666 } | 685 } |
667 | 686 |
668 memcpy(new_iccp_profile, profile, proflen); | 687 memcpy(new_iccp_profile, profile, proflen); |
669 | 688 |
670 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); | 689 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); |
671 | 690 |
672 info_ptr->iccp_proflen = proflen; | 691 info_ptr->iccp_proflen = proflen; |
673 info_ptr->iccp_name = new_iccp_name; | 692 info_ptr->iccp_name = new_iccp_name; |
674 info_ptr->iccp_profile = new_iccp_profile; | 693 info_ptr->iccp_profile = new_iccp_profile; |
675 info_ptr->free_me |= PNG_FREE_ICCP; | 694 info_ptr->free_me |= PNG_FREE_ICCP; |
676 info_ptr->valid |= PNG_INFO_iCCP; | 695 info_ptr->valid |= PNG_INFO_iCCP; |
677 } | 696 } |
678 #endif | 697 #endif |
679 | 698 |
680 #ifdef PNG_TEXT_SUPPORTED | 699 #ifdef PNG_TEXT_SUPPORTED |
681 void PNGAPI | 700 void PNGAPI |
682 png_set_text(png_const_structrp png_ptr, png_inforp info_ptr, | 701 png_set_text(png_const_structrp png_ptr, png_inforp info_ptr, |
683 png_const_textp text_ptr, int num_text) | 702 png_const_textp text_ptr, int num_text) |
684 { | 703 { |
685 int ret; | 704 int ret; |
686 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); | 705 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); |
687 | 706 |
688 if (ret) | 707 if (ret != 0) |
689 png_error(png_ptr, "Insufficient memory to store text"); | 708 png_error(png_ptr, "Insufficient memory to store text"); |
690 } | 709 } |
691 | 710 |
692 int /* PRIVATE */ | 711 int /* PRIVATE */ |
693 png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, | 712 png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, |
694 png_const_textp text_ptr, int num_text) | 713 png_const_textp text_ptr, int num_text) |
695 { | 714 { |
696 int i; | 715 int i; |
697 | 716 |
698 png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" : | 717 png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11U : |
699 (unsigned long)png_ptr->chunk_name); | 718 (unsigned long)png_ptr->chunk_name); |
700 | 719 |
701 if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) | 720 if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) |
702 return(0); | 721 return(0); |
703 | 722 |
704 /* Make sure we have enough space in the "text" array in info_struct | 723 /* Make sure we have enough space in the "text" array in info_struct |
705 * to hold all of the incoming text_ptr objects. This compare can't overflow | 724 * to hold all of the incoming text_ptr objects. This compare can't overflow |
706 * because max_text >= num_text (anyway, subtract of two positive integers | 725 * because max_text >= num_text (anyway, subtract of two positive integers |
707 * can't overflow in any case.) | 726 * can't overflow in any case.) |
708 */ | 727 */ |
709 if (num_text > info_ptr->max_text - info_ptr->num_text) | 728 if (num_text > info_ptr->max_text - info_ptr->num_text) |
710 { | 729 { |
711 int old_num_text = info_ptr->num_text; | 730 int old_num_text = info_ptr->num_text; |
712 int max_text; | 731 int max_text; |
713 png_textp new_text = NULL; | 732 png_textp new_text = NULL; |
714 | 733 |
715 /* Calculate an appropriate max_text, checking for overflow. */ | 734 /* Calculate an appropriate max_text, checking for overflow. */ |
716 max_text = old_num_text; | 735 max_text = old_num_text; |
717 if (num_text <= INT_MAX - max_text) | 736 if (num_text <= INT_MAX - max_text) |
718 { | 737 { |
719 max_text += num_text; | 738 max_text += num_text; |
720 | 739 |
721 /* Round up to a multiple of 8 */ | 740 /* Round up to a multiple of 8 */ |
722 if (max_text < INT_MAX-8) | 741 if (max_text < INT_MAX-8) |
723 max_text = (max_text + 8) & ~0x7; | 742 max_text = (max_text + 8) & ~0x7; |
724 | 743 |
725 else | 744 else |
726 max_text = INT_MAX; | 745 max_text = INT_MAX; |
727 | 746 |
728 /* Now allocate a new array and copy the old members in, this does all | 747 /* Now allocate a new array and copy the old members in; this does all |
729 * the overflow checks. | 748 * the overflow checks. |
730 */ | 749 */ |
731 new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, | 750 new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, |
732 info_ptr->text, old_num_text, max_text-old_num_text, | 751 info_ptr->text, old_num_text, max_text-old_num_text, |
733 sizeof *new_text)); | 752 sizeof *new_text)); |
734 } | 753 } |
735 | 754 |
736 if (new_text == NULL) | 755 if (new_text == NULL) |
737 { | 756 { |
738 png_chunk_report(png_ptr, "too many text chunks", | 757 png_chunk_report(png_ptr, "too many text chunks", |
739 PNG_CHUNK_WRITE_ERROR); | 758 PNG_CHUNK_WRITE_ERROR); |
| 759 |
740 return 1; | 760 return 1; |
741 } | 761 } |
742 | 762 |
743 png_free(png_ptr, info_ptr->text); | 763 png_free(png_ptr, info_ptr->text); |
744 | 764 |
745 info_ptr->text = new_text; | 765 info_ptr->text = new_text; |
746 info_ptr->free_me |= PNG_FREE_TEXT; | 766 info_ptr->free_me |= PNG_FREE_TEXT; |
747 info_ptr->max_text = max_text; | 767 info_ptr->max_text = max_text; |
748 /* num_text is adjusted below as the entries are copied in */ | 768 /* num_text is adjusted below as the entries are copied in */ |
749 | 769 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 | 805 |
786 else | 806 else |
787 lang_len = 0; | 807 lang_len = 0; |
788 | 808 |
789 if (text_ptr[i].lang_key != NULL) | 809 if (text_ptr[i].lang_key != NULL) |
790 lang_key_len = strlen(text_ptr[i].lang_key); | 810 lang_key_len = strlen(text_ptr[i].lang_key); |
791 | 811 |
792 else | 812 else |
793 lang_key_len = 0; | 813 lang_key_len = 0; |
794 } | 814 } |
795 # else /* PNG_iTXt_SUPPORTED */ | 815 # else /* iTXt */ |
796 { | 816 { |
797 png_chunk_report(png_ptr, "iTXt chunk not supported", | 817 png_chunk_report(png_ptr, "iTXt chunk not supported", |
798 PNG_CHUNK_WRITE_ERROR); | 818 PNG_CHUNK_WRITE_ERROR); |
799 continue; | 819 continue; |
800 } | 820 } |
801 # endif | 821 # endif |
802 | 822 |
803 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') | 823 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') |
804 { | 824 { |
805 text_length = 0; | 825 text_length = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
818 textp->compression = text_ptr[i].compression; | 838 textp->compression = text_ptr[i].compression; |
819 } | 839 } |
820 | 840 |
821 textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr, | 841 textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr, |
822 key_len + text_length + lang_len + lang_key_len + 4)); | 842 key_len + text_length + lang_len + lang_key_len + 4)); |
823 | 843 |
824 if (textp->key == NULL) | 844 if (textp->key == NULL) |
825 { | 845 { |
826 png_chunk_report(png_ptr, "text chunk: out of memory", | 846 png_chunk_report(png_ptr, "text chunk: out of memory", |
827 PNG_CHUNK_WRITE_ERROR); | 847 PNG_CHUNK_WRITE_ERROR); |
| 848 |
828 return 1; | 849 return 1; |
829 } | 850 } |
830 | 851 |
831 png_debug2(2, "Allocated %lu bytes at %p in png_set_text", | 852 png_debug2(2, "Allocated %lu bytes at %p in png_set_text", |
832 (unsigned long)(png_uint_32) | 853 (unsigned long)(png_uint_32) |
833 (key_len + lang_len + lang_key_len + text_length + 4), | 854 (key_len + lang_len + lang_key_len + text_length + 4), |
834 textp->key); | 855 textp->key); |
835 | 856 |
836 memcpy(textp->key, text_ptr[i].key, key_len); | 857 memcpy(textp->key, text_ptr[i].key, key_len); |
837 *(textp->key + key_len) = '\0'; | 858 *(textp->key + key_len) = '\0'; |
838 | 859 |
839 if (text_ptr[i].compression > 0) | 860 if (text_ptr[i].compression > 0) |
840 { | 861 { |
841 textp->lang = textp->key + key_len + 1; | 862 textp->lang = textp->key + key_len + 1; |
842 memcpy(textp->lang, text_ptr[i].lang, lang_len); | 863 memcpy(textp->lang, text_ptr[i].lang, lang_len); |
843 *(textp->lang + lang_len) = '\0'; | 864 *(textp->lang + lang_len) = '\0'; |
844 textp->lang_key = textp->lang + lang_len + 1; | 865 textp->lang_key = textp->lang + lang_len + 1; |
845 memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); | 866 memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); |
846 *(textp->lang_key + lang_key_len) = '\0'; | 867 *(textp->lang_key + lang_key_len) = '\0'; |
847 textp->text = textp->lang_key + lang_key_len + 1; | 868 textp->text = textp->lang_key + lang_key_len + 1; |
848 } | 869 } |
849 | 870 |
850 else | 871 else |
851 { | 872 { |
852 textp->lang=NULL; | 873 textp->lang=NULL; |
853 textp->lang_key=NULL; | 874 textp->lang_key=NULL; |
854 textp->text = textp->key + key_len + 1; | 875 textp->text = textp->key + key_len + 1; |
855 } | 876 } |
856 | 877 |
857 if (text_length) | 878 if (text_length != 0) |
858 memcpy(textp->text, text_ptr[i].text, text_length); | 879 memcpy(textp->text, text_ptr[i].text, text_length); |
859 | 880 |
860 *(textp->text + text_length) = '\0'; | 881 *(textp->text + text_length) = '\0'; |
861 | 882 |
862 # ifdef PNG_iTXt_SUPPORTED | 883 # ifdef PNG_iTXt_SUPPORTED |
863 if (textp->compression > 0) | 884 if (textp->compression > 0) |
864 { | 885 { |
865 textp->text_length = 0; | 886 textp->text_length = 0; |
866 textp->itxt_length = text_length; | 887 textp->itxt_length = text_length; |
867 } | 888 } |
(...skipping 14 matching lines...) Expand all Loading... |
882 #endif | 903 #endif |
883 | 904 |
884 #ifdef PNG_tIME_SUPPORTED | 905 #ifdef PNG_tIME_SUPPORTED |
885 void PNGAPI | 906 void PNGAPI |
886 png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr, | 907 png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr, |
887 png_const_timep mod_time) | 908 png_const_timep mod_time) |
888 { | 909 { |
889 png_debug1(1, "in %s storage function", "tIME"); | 910 png_debug1(1, "in %s storage function", "tIME"); |
890 | 911 |
891 if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL || | 912 if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL || |
892 (png_ptr->mode & PNG_WROTE_tIME)) | 913 (png_ptr->mode & PNG_WROTE_tIME) != 0) |
893 return; | 914 return; |
894 | 915 |
895 if (mod_time->month == 0 || mod_time->month > 12 || | 916 if (mod_time->month == 0 || mod_time->month > 12 || |
896 mod_time->day == 0 || mod_time->day > 31 || | 917 mod_time->day == 0 || mod_time->day > 31 || |
897 mod_time->hour > 23 || mod_time->minute > 59 || | 918 mod_time->hour > 23 || mod_time->minute > 59 || |
898 mod_time->second > 60) | 919 mod_time->second > 60) |
899 { | 920 { |
900 png_warning(png_ptr, "Ignoring invalid time value"); | 921 png_warning(png_ptr, "Ignoring invalid time value"); |
| 922 |
901 return; | 923 return; |
902 } | 924 } |
903 | 925 |
904 info_ptr->mod_time = *mod_time; | 926 info_ptr->mod_time = *mod_time; |
905 info_ptr->valid |= PNG_INFO_tIME; | 927 info_ptr->valid |= PNG_INFO_tIME; |
906 } | 928 } |
907 #endif | 929 #endif |
908 | 930 |
909 #ifdef PNG_tRNS_SUPPORTED | 931 #ifdef PNG_tRNS_SUPPORTED |
910 void PNGAPI | 932 void PNGAPI |
911 png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, | 933 png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, |
912 png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) | 934 png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) |
913 { | 935 { |
914 png_debug1(1, "in %s storage function", "tRNS"); | 936 png_debug1(1, "in %s storage function", "tRNS"); |
915 | 937 |
916 if (png_ptr == NULL || info_ptr == NULL) | 938 if (png_ptr == NULL || info_ptr == NULL) |
| 939 |
917 return; | 940 return; |
918 | 941 |
919 if (trans_alpha != NULL) | 942 if (trans_alpha != NULL) |
920 { | 943 { |
921 /* It may not actually be necessary to set png_ptr->trans_alpha here; | 944 /* It may not actually be necessary to set png_ptr->trans_alpha here; |
922 * we do it for backward compatibility with the way the png_handle_tRNS | 945 * we do it for backward compatibility with the way the png_handle_tRNS |
923 * function used to do the allocation. | 946 * function used to do the allocation. |
924 * | 947 * |
925 * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively | 948 * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively |
926 * relies on png_set_tRNS storing the information in png_struct | 949 * relies on png_set_tRNS storing the information in png_struct |
927 * (otherwise it won't be there for the code in pngrtran.c). | 950 * (otherwise it won't be there for the code in pngrtran.c). |
928 */ | 951 */ |
929 | 952 |
930 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); | 953 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); |
931 | 954 |
932 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ | 955 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ |
933 png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep, | 956 png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep, |
934 png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); | 957 png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); |
935 | 958 |
936 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) | 959 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) |
937 memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); | 960 memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); |
938 } | 961 } |
939 | 962 |
940 if (trans_color != NULL) | 963 if (trans_color != NULL) |
941 { | 964 { |
942 int sample_max = (1 << info_ptr->bit_depth); | 965 #ifdef PNG_WARNINGS_SUPPORTED |
943 | 966 if (info_ptr->bit_depth < 16) |
944 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && | 967 { |
945 trans_color->gray > sample_max) || | 968 int sample_max = (1 << info_ptr->bit_depth) - 1; |
946 (info_ptr->color_type == PNG_COLOR_TYPE_RGB && | 969 |
947 (trans_color->red > sample_max || | 970 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && |
948 trans_color->green > sample_max || | 971 trans_color->gray > sample_max) || |
949 trans_color->blue > sample_max))) | 972 (info_ptr->color_type == PNG_COLOR_TYPE_RGB && |
950 png_warning(png_ptr, | 973 (trans_color->red > sample_max || |
951 "tRNS chunk has out-of-range samples for bit_depth"); | 974 trans_color->green > sample_max || |
| 975 trans_color->blue > sample_max))) |
| 976 png_warning(png_ptr, |
| 977 "tRNS chunk has out-of-range samples for bit_depth"); |
| 978 } |
| 979 #endif |
952 | 980 |
953 info_ptr->trans_color = *trans_color; | 981 info_ptr->trans_color = *trans_color; |
954 | 982 |
955 if (num_trans == 0) | 983 if (num_trans == 0) |
956 num_trans = 1; | 984 num_trans = 1; |
957 } | 985 } |
958 | 986 |
959 info_ptr->num_trans = (png_uint_16)num_trans; | 987 info_ptr->num_trans = (png_uint_16)num_trans; |
960 | 988 |
961 if (num_trans != 0) | 989 if (num_trans != 0) |
(...skipping 26 matching lines...) Expand all Loading... |
988 * overflows. Notice that the parameters are (int) and (size_t) | 1016 * overflows. Notice that the parameters are (int) and (size_t) |
989 */ | 1017 */ |
990 np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, | 1018 np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, |
991 info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, | 1019 info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, |
992 sizeof *np)); | 1020 sizeof *np)); |
993 | 1021 |
994 if (np == NULL) | 1022 if (np == NULL) |
995 { | 1023 { |
996 /* Out of memory or too many chunks */ | 1024 /* Out of memory or too many chunks */ |
997 png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR); | 1025 png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR); |
| 1026 |
998 return; | 1027 return; |
999 } | 1028 } |
1000 | 1029 |
1001 png_free(png_ptr, info_ptr->splt_palettes); | 1030 png_free(png_ptr, info_ptr->splt_palettes); |
1002 info_ptr->splt_palettes = np; | 1031 info_ptr->splt_palettes = np; |
1003 info_ptr->free_me |= PNG_FREE_SPLT; | 1032 info_ptr->free_me |= PNG_FREE_SPLT; |
1004 | 1033 |
1005 np += info_ptr->splt_palettes_num; | 1034 np += info_ptr->splt_palettes_num; |
1006 | 1035 |
1007 do | 1036 do |
1008 { | 1037 { |
1009 png_size_t length; | 1038 png_size_t length; |
1010 | 1039 |
1011 /* Skip invalid input entries */ | 1040 /* Skip invalid input entries */ |
1012 if (entries->name == NULL || entries->entries == NULL) | 1041 if (entries->name == NULL || entries->entries == NULL) |
1013 { | 1042 { |
1014 /* png_handle_sPLT doesn't do this, so this is an app error */ | 1043 /* png_handle_sPLT doesn't do this, so this is an app error */ |
1015 png_app_error(png_ptr, "png_set_sPLT: invalid sPLT"); | 1044 png_app_error(png_ptr, "png_set_sPLT: invalid sPLT"); |
1016 /* Just skip the invalid entry */ | 1045 /* Just skip the invalid entry */ |
1017 continue; | 1046 continue; |
1018 } | 1047 } |
1019 | 1048 |
1020 np->depth = entries->depth; | 1049 np->depth = entries->depth; |
1021 | 1050 |
1022 /* In the even of out-of-memory just return - there's no point keeping on | 1051 /* In the event of out-of-memory just return - there's no point keeping |
1023 * trying to add sPLT chunks. | 1052 * on trying to add sPLT chunks. |
1024 */ | 1053 */ |
1025 length = strlen(entries->name) + 1; | 1054 length = strlen(entries->name) + 1; |
1026 np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length)); | 1055 np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length)); |
1027 | 1056 |
1028 if (np->name == NULL) | 1057 if (np->name == NULL) |
1029 break; | 1058 break; |
1030 | 1059 |
1031 memcpy(np->name, entries->name, length); | 1060 memcpy(np->name, entries->name, length); |
1032 | 1061 |
1033 /* IMPORTANT: we have memory now that won't get freed if something else | 1062 /* IMPORTANT: we have memory now that won't get freed if something else |
1034 * goes wrong, this code must free it. png_malloc_array produces no | 1063 * goes wrong; this code must free it. png_malloc_array produces no |
1035 * warnings, use a png_chunk_report (below) if there is an error. | 1064 * warnings; use a png_chunk_report (below) if there is an error. |
1036 */ | 1065 */ |
1037 np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr, | 1066 np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr, |
1038 entries->nentries, sizeof (png_sPLT_entry))); | 1067 entries->nentries, sizeof (png_sPLT_entry))); |
1039 | 1068 |
1040 if (np->entries == NULL) | 1069 if (np->entries == NULL) |
1041 { | 1070 { |
1042 png_free(png_ptr, np->name); | 1071 png_free(png_ptr, np->name); |
| 1072 np->name = NULL; |
1043 break; | 1073 break; |
1044 } | 1074 } |
1045 | 1075 |
1046 np->nentries = entries->nentries; | 1076 np->nentries = entries->nentries; |
1047 /* This multiply can't overflow because png_malloc_array has already | 1077 /* This multiply can't overflow because png_malloc_array has already |
1048 * checked it when doing the allocation. | 1078 * checked it when doing the allocation. |
1049 */ | 1079 */ |
1050 memcpy(np->entries, entries->entries, | 1080 memcpy(np->entries, entries->entries, |
1051 entries->nentries * sizeof (png_sPLT_entry)); | 1081 entries->nentries * sizeof (png_sPLT_entry)); |
1052 | 1082 |
1053 /* Note that 'continue' skips the advance of the out pointer and out | 1083 /* Note that 'continue' skips the advance of the out pointer and out |
1054 * count, so an invalid entry is not added. | 1084 * count, so an invalid entry is not added. |
1055 */ | 1085 */ |
1056 info_ptr->valid |= PNG_INFO_sPLT; | 1086 info_ptr->valid |= PNG_INFO_sPLT; |
1057 ++(info_ptr->splt_palettes_num); | 1087 ++(info_ptr->splt_palettes_num); |
1058 ++np; | 1088 ++np; |
1059 } | 1089 } |
1060 while (++entries, --nentries); | 1090 while (++entries, --nentries); |
1061 | 1091 |
1062 if (nentries > 0) | 1092 if (nentries > 0) |
1063 png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); | 1093 png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); |
1064 } | 1094 } |
1065 #endif /* PNG_sPLT_SUPPORTED */ | 1095 #endif /* sPLT */ |
1066 | 1096 |
1067 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED | 1097 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED |
1068 static png_byte | 1098 static png_byte |
1069 check_location(png_const_structrp png_ptr, int location) | 1099 check_location(png_const_structrp png_ptr, int location) |
1070 { | 1100 { |
1071 location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT); | 1101 location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT); |
1072 | 1102 |
1073 /* New in 1.6.0; copy the location and check it. This is an API | 1103 /* New in 1.6.0; copy the location and check it. This is an API |
1074 * change, previously the app had to use the | 1104 * change; previously the app had to use the |
1075 * png_set_unknown_chunk_location API below for each chunk. | 1105 * png_set_unknown_chunk_location API below for each chunk. |
1076 */ | 1106 */ |
1077 if (location == 0 && !(png_ptr->mode & PNG_IS_READ_STRUCT)) | 1107 if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
1078 { | 1108 { |
1079 /* Write struct, so unknown chunks come from the app */ | 1109 /* Write struct, so unknown chunks come from the app */ |
1080 png_app_warning(png_ptr, | 1110 png_app_warning(png_ptr, |
1081 "png_set_unknown_chunks now expects a valid location"); | 1111 "png_set_unknown_chunks now expects a valid location"); |
1082 /* Use the old behavior */ | 1112 /* Use the old behavior */ |
1083 location = (png_byte)(png_ptr->mode & | 1113 location = (png_byte)(png_ptr->mode & |
1084 (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)); | 1114 (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)); |
1085 } | 1115 } |
1086 | 1116 |
1087 /* This need not be an internal error - if the app calls | 1117 /* This need not be an internal error - if the app calls |
(...skipping 14 matching lines...) Expand all Loading... |
1102 return (png_byte)location; | 1132 return (png_byte)location; |
1103 } | 1133 } |
1104 | 1134 |
1105 void PNGAPI | 1135 void PNGAPI |
1106 png_set_unknown_chunks(png_const_structrp png_ptr, | 1136 png_set_unknown_chunks(png_const_structrp png_ptr, |
1107 png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) | 1137 png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) |
1108 { | 1138 { |
1109 png_unknown_chunkp np; | 1139 png_unknown_chunkp np; |
1110 | 1140 |
1111 if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 || | 1141 if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 || |
1112 unknowns == NULL) | 1142 unknowns == NULL) |
1113 return; | 1143 return; |
1114 | 1144 |
1115 /* Check for the failure cases where support has been disabled at compile | 1145 /* Check for the failure cases where support has been disabled at compile |
1116 * time. This code is hardly ever compiled - it's here because | 1146 * time. This code is hardly ever compiled - it's here because |
1117 * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this | 1147 * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this |
1118 * code) but may be meaningless if the read or write handling of unknown | 1148 * code) but may be meaningless if the read or write handling of unknown |
1119 * chunks is not compiled in. | 1149 * chunks is not compiled in. |
1120 */ | 1150 */ |
1121 # if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \ | 1151 # if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \ |
1122 defined(PNG_READ_SUPPORTED) | 1152 defined(PNG_READ_SUPPORTED) |
1123 if (png_ptr->mode & PNG_IS_READ_STRUCT) | 1153 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
1124 { | 1154 { |
1125 png_app_error(png_ptr, "no unknown chunk support on read"); | 1155 png_app_error(png_ptr, "no unknown chunk support on read"); |
| 1156 |
1126 return; | 1157 return; |
1127 } | 1158 } |
1128 # endif | 1159 # endif |
1129 # if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \ | 1160 # if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \ |
1130 defined(PNG_WRITE_SUPPORTED) | 1161 defined(PNG_WRITE_SUPPORTED) |
1131 if (!(png_ptr->mode & PNG_IS_READ_STRUCT)) | 1162 if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
1132 { | 1163 { |
1133 png_app_error(png_ptr, "no unknown chunk support on write"); | 1164 png_app_error(png_ptr, "no unknown chunk support on write"); |
| 1165 |
1134 return; | 1166 return; |
1135 } | 1167 } |
1136 # endif | 1168 # endif |
1137 | 1169 |
1138 /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that | 1170 /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that |
1139 * unknown critical chunks could be lost with just a warning resulting in | 1171 * unknown critical chunks could be lost with just a warning resulting in |
1140 * undefined behavior. Now png_chunk_report is used to provide behavior | 1172 * undefined behavior. Now png_chunk_report is used to provide behavior |
1141 * appropriate to read or write. | 1173 * appropriate to read or write. |
1142 */ | 1174 */ |
1143 np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, | 1175 np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, |
1144 info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, | 1176 info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, |
1145 sizeof *np)); | 1177 sizeof *np)); |
1146 | 1178 |
1147 if (np == NULL) | 1179 if (np == NULL) |
1148 { | 1180 { |
1149 png_chunk_report(png_ptr, "too many unknown chunks", | 1181 png_chunk_report(png_ptr, "too many unknown chunks", |
1150 PNG_CHUNK_WRITE_ERROR); | 1182 PNG_CHUNK_WRITE_ERROR); |
| 1183 |
1151 return; | 1184 return; |
1152 } | 1185 } |
1153 | 1186 |
1154 png_free(png_ptr, info_ptr->unknown_chunks); | 1187 png_free(png_ptr, info_ptr->unknown_chunks); |
1155 info_ptr->unknown_chunks = np; /* safe because it is initialized */ | 1188 info_ptr->unknown_chunks = np; /* safe because it is initialized */ |
1156 info_ptr->free_me |= PNG_FREE_UNKN; | 1189 info_ptr->free_me |= PNG_FREE_UNKN; |
1157 | 1190 |
1158 np += info_ptr->unknown_chunks_num; | 1191 np += info_ptr->unknown_chunks_num; |
1159 | 1192 |
1160 /* Increment unknown_chunks_num each time round the loop to protect the | 1193 /* Increment unknown_chunks_num each time round the loop to protect the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 * | 1240 * |
1208 * TODO: add a png_app_warning in 1.7 | 1241 * TODO: add a png_app_warning in 1.7 |
1209 */ | 1242 */ |
1210 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && | 1243 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && |
1211 chunk < info_ptr->unknown_chunks_num) | 1244 chunk < info_ptr->unknown_chunks_num) |
1212 { | 1245 { |
1213 if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0) | 1246 if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0) |
1214 { | 1247 { |
1215 png_app_error(png_ptr, "invalid unknown chunk location"); | 1248 png_app_error(png_ptr, "invalid unknown chunk location"); |
1216 /* Fake out the pre 1.6.0 behavior: */ | 1249 /* Fake out the pre 1.6.0 behavior: */ |
1217 if ((location & PNG_HAVE_IDAT)) /* undocumented! */ | 1250 if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */ |
1218 location = PNG_AFTER_IDAT; | 1251 location = PNG_AFTER_IDAT; |
1219 | 1252 |
1220 else | 1253 else |
1221 location = PNG_HAVE_IHDR; /* also undocumented */ | 1254 location = PNG_HAVE_IHDR; /* also undocumented */ |
1222 } | 1255 } |
1223 | 1256 |
1224 info_ptr->unknown_chunks[chunk].location = | 1257 info_ptr->unknown_chunks[chunk].location = |
1225 check_location(png_ptr, location); | 1258 check_location(png_ptr, location); |
1226 } | 1259 } |
1227 } | 1260 } |
1228 #endif | 1261 #endif /* STORE_UNKNOWN_CHUNKS */ |
1229 | |
1230 | 1262 |
1231 #ifdef PNG_MNG_FEATURES_SUPPORTED | 1263 #ifdef PNG_MNG_FEATURES_SUPPORTED |
1232 png_uint_32 PNGAPI | 1264 png_uint_32 PNGAPI |
1233 png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features) | 1265 png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features) |
1234 { | 1266 { |
1235 png_debug(1, "in png_permit_mng_features"); | 1267 png_debug(1, "in png_permit_mng_features"); |
1236 | 1268 |
1237 if (png_ptr == NULL) | 1269 if (png_ptr == NULL) |
1238 return 0; | 1270 return 0; |
1239 | 1271 |
1240 png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES; | 1272 png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES; |
1241 | 1273 |
1242 return png_ptr->mng_features_permitted; | 1274 return png_ptr->mng_features_permitted; |
1243 } | 1275 } |
1244 #endif | 1276 #endif |
1245 | 1277 |
1246 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 1278 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
1247 static unsigned int | 1279 static unsigned int |
1248 add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep) | 1280 add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep) |
1249 { | 1281 { |
1250 unsigned int i; | 1282 unsigned int i; |
1251 | 1283 |
1252 /* Utility function: update the 'keep' state of a chunk if it is already in | 1284 /* Utility function: update the 'keep' state of a chunk if it is already in |
1253 * the list, otherwise add it to the list. | 1285 * the list, otherwise add it to the list. |
1254 */ | 1286 */ |
1255 for (i=0; i<count; ++i, list += 5) if (memcmp(list, add, 4) == 0) | 1287 for (i=0; i<count; ++i, list += 5) |
1256 { | 1288 { |
1257 list[4] = (png_byte)keep; | 1289 if (memcmp(list, add, 4) == 0) |
1258 return count; | 1290 { |
| 1291 list[4] = (png_byte)keep; |
| 1292 |
| 1293 return count; |
| 1294 } |
1259 } | 1295 } |
1260 | 1296 |
1261 if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT) | 1297 if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT) |
1262 { | 1298 { |
1263 ++count; | 1299 ++count; |
1264 memcpy(list, add, 4); | 1300 memcpy(list, add, 4); |
1265 list[4] = (png_byte)keep; | 1301 list[4] = (png_byte)keep; |
1266 } | 1302 } |
1267 | 1303 |
1268 return count; | 1304 return count; |
1269 } | 1305 } |
1270 | 1306 |
1271 void PNGAPI | 1307 void PNGAPI |
1272 png_set_keep_unknown_chunks(png_structrp png_ptr, int keep, | 1308 png_set_keep_unknown_chunks(png_structrp png_ptr, int keep, |
1273 png_const_bytep chunk_list, int num_chunks_in) | 1309 png_const_bytep chunk_list, int num_chunks_in) |
1274 { | 1310 { |
1275 png_bytep new_list; | 1311 png_bytep new_list; |
1276 unsigned int num_chunks, old_num_chunks; | 1312 unsigned int num_chunks, old_num_chunks; |
1277 | 1313 |
1278 if (png_ptr == NULL) | 1314 if (png_ptr == NULL) |
1279 return; | 1315 return; |
1280 | 1316 |
1281 if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST) | 1317 if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST) |
1282 { | 1318 { |
1283 png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep"); | 1319 png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep"); |
| 1320 |
1284 return; | 1321 return; |
1285 } | 1322 } |
1286 | 1323 |
1287 if (num_chunks_in <= 0) | 1324 if (num_chunks_in <= 0) |
1288 { | 1325 { |
1289 png_ptr->unknown_default = keep; | 1326 png_ptr->unknown_default = keep; |
1290 | 1327 |
1291 /* '0' means just set the flags, so stop here */ | 1328 /* '0' means just set the flags, so stop here */ |
1292 if (num_chunks_in == 0) | 1329 if (num_chunks_in == 0) |
1293 return; | 1330 return; |
(...skipping 18 matching lines...) Expand all Loading... |
1312 115, 67, 65, 76, '\0', /* sCAL */ | 1349 115, 67, 65, 76, '\0', /* sCAL */ |
1313 115, 80, 76, 84, '\0', /* sPLT */ | 1350 115, 80, 76, 84, '\0', /* sPLT */ |
1314 115, 84, 69, 82, '\0', /* sTER */ | 1351 115, 84, 69, 82, '\0', /* sTER */ |
1315 115, 82, 71, 66, '\0', /* sRGB */ | 1352 115, 82, 71, 66, '\0', /* sRGB */ |
1316 116, 69, 88, 116, '\0', /* tEXt */ | 1353 116, 69, 88, 116, '\0', /* tEXt */ |
1317 116, 73, 77, 69, '\0', /* tIME */ | 1354 116, 73, 77, 69, '\0', /* tIME */ |
1318 122, 84, 88, 116, '\0' /* zTXt */ | 1355 122, 84, 88, 116, '\0' /* zTXt */ |
1319 }; | 1356 }; |
1320 | 1357 |
1321 chunk_list = chunks_to_ignore; | 1358 chunk_list = chunks_to_ignore; |
1322 num_chunks = (sizeof chunks_to_ignore)/5; | 1359 num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U; |
1323 } | 1360 } |
1324 | 1361 |
1325 else /* num_chunks_in > 0 */ | 1362 else /* num_chunks_in > 0 */ |
1326 { | 1363 { |
1327 if (chunk_list == NULL) | 1364 if (chunk_list == NULL) |
1328 { | 1365 { |
1329 /* Prior to 1.6.0 this was silently ignored, now it is an app_error | 1366 /* Prior to 1.6.0 this was silently ignored, now it is an app_error |
1330 * which can be switched off. | 1367 * which can be switched off. |
1331 */ | 1368 */ |
1332 png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list"); | 1369 png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list"); |
| 1370 |
1333 return; | 1371 return; |
1334 } | 1372 } |
1335 | 1373 |
1336 num_chunks = num_chunks_in; | 1374 num_chunks = num_chunks_in; |
1337 } | 1375 } |
1338 | 1376 |
1339 old_num_chunks = png_ptr->num_chunk_list; | 1377 old_num_chunks = png_ptr->num_chunk_list; |
1340 if (png_ptr->chunk_list == NULL) | 1378 if (png_ptr->chunk_list == NULL) |
1341 old_num_chunks = 0; | 1379 old_num_chunks = 0; |
1342 | 1380 |
1343 /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow. | 1381 /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow. |
1344 */ | 1382 */ |
1345 if (num_chunks + old_num_chunks > UINT_MAX/5) | 1383 if (num_chunks + old_num_chunks > UINT_MAX/5) |
1346 { | 1384 { |
1347 png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks"); | 1385 png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks"); |
| 1386 |
1348 return; | 1387 return; |
1349 } | 1388 } |
1350 | 1389 |
1351 /* If these chunks are being reset to the default then no more memory is | 1390 /* If these chunks are being reset to the default then no more memory is |
1352 * required because add_one_chunk above doesn't extend the list if the 'keep' | 1391 * required because add_one_chunk above doesn't extend the list if the 'keep' |
1353 * parameter is the default. | 1392 * parameter is the default. |
1354 */ | 1393 */ |
1355 if (keep) | 1394 if (keep != 0) |
1356 { | 1395 { |
1357 new_list = png_voidcast(png_bytep, png_malloc(png_ptr, | 1396 new_list = png_voidcast(png_bytep, png_malloc(png_ptr, |
1358 5 * (num_chunks + old_num_chunks))); | 1397 5 * (num_chunks + old_num_chunks))); |
1359 | 1398 |
1360 if (old_num_chunks > 0) | 1399 if (old_num_chunks > 0) |
1361 memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); | 1400 memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); |
1362 } | 1401 } |
1363 | 1402 |
1364 else if (old_num_chunks > 0) | 1403 else if (old_num_chunks > 0) |
1365 new_list = png_ptr->chunk_list; | 1404 new_list = png_ptr->chunk_list; |
1366 | 1405 |
1367 else | 1406 else |
1368 new_list = NULL; | 1407 new_list = NULL; |
1369 | 1408 |
1370 /* Add the new chunks together with each one's handling code. If the chunk | 1409 /* Add the new chunks together with each one's handling code. If the chunk |
1371 * already exists the code is updated, otherwise the chunk is added to the | 1410 * already exists the code is updated, otherwise the chunk is added to the |
1372 * end. (In libpng 1.6.0 order no longer matters because this code enforces | 1411 * end. (In libpng 1.6.0 order no longer matters because this code enforces |
1373 * the earlier convention that the last setting is the one that is used.) | 1412 * the earlier convention that the last setting is the one that is used.) |
1374 */ | 1413 */ |
1375 if (new_list != NULL) | 1414 if (new_list != NULL) |
1376 { | 1415 { |
1377 png_const_bytep inlist; | 1416 png_const_bytep inlist; |
1378 png_bytep outlist; | 1417 png_bytep outlist; |
1379 unsigned int i; | 1418 unsigned int i; |
1380 | 1419 |
1381 for (i=0; i<num_chunks; ++i) | 1420 for (i=0; i<num_chunks; ++i) |
| 1421 { |
1382 old_num_chunks = add_one_chunk(new_list, old_num_chunks, | 1422 old_num_chunks = add_one_chunk(new_list, old_num_chunks, |
1383 chunk_list+5*i, keep); | 1423 chunk_list+5*i, keep); |
| 1424 } |
1384 | 1425 |
1385 /* Now remove any spurious 'default' entries. */ | 1426 /* Now remove any spurious 'default' entries. */ |
1386 num_chunks = 0; | 1427 num_chunks = 0; |
1387 for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5) | 1428 for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5) |
| 1429 { |
1388 if (inlist[4]) | 1430 if (inlist[4]) |
1389 { | 1431 { |
1390 if (outlist != inlist) | 1432 if (outlist != inlist) |
1391 memcpy(outlist, inlist, 5); | 1433 memcpy(outlist, inlist, 5); |
1392 outlist += 5; | 1434 outlist += 5; |
1393 ++num_chunks; | 1435 ++num_chunks; |
1394 } | 1436 } |
| 1437 } |
1395 | 1438 |
1396 /* This means the application has removed all the specialized handling. */ | 1439 /* This means the application has removed all the specialized handling. */ |
1397 if (num_chunks == 0) | 1440 if (num_chunks == 0) |
1398 { | 1441 { |
1399 if (png_ptr->chunk_list != new_list) | 1442 if (png_ptr->chunk_list != new_list) |
1400 png_free(png_ptr, new_list); | 1443 png_free(png_ptr, new_list); |
1401 | 1444 |
1402 new_list = NULL; | 1445 new_list = NULL; |
1403 } | 1446 } |
1404 } | 1447 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 #ifdef PNG_INFO_IMAGE_SUPPORTED | 1479 #ifdef PNG_INFO_IMAGE_SUPPORTED |
1437 void PNGAPI | 1480 void PNGAPI |
1438 png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, | 1481 png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, |
1439 png_bytepp row_pointers) | 1482 png_bytepp row_pointers) |
1440 { | 1483 { |
1441 png_debug1(1, "in %s storage function", "rows"); | 1484 png_debug1(1, "in %s storage function", "rows"); |
1442 | 1485 |
1443 if (png_ptr == NULL || info_ptr == NULL) | 1486 if (png_ptr == NULL || info_ptr == NULL) |
1444 return; | 1487 return; |
1445 | 1488 |
1446 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) | 1489 if (info_ptr->row_pointers != NULL && |
| 1490 (info_ptr->row_pointers != row_pointers)) |
1447 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); | 1491 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
1448 | 1492 |
1449 info_ptr->row_pointers = row_pointers; | 1493 info_ptr->row_pointers = row_pointers; |
1450 | 1494 |
1451 if (row_pointers) | 1495 if (row_pointers != NULL) |
1452 info_ptr->valid |= PNG_INFO_IDAT; | 1496 info_ptr->valid |= PNG_INFO_IDAT; |
1453 } | 1497 } |
1454 #endif | 1498 #endif |
1455 | 1499 |
1456 void PNGAPI | 1500 void PNGAPI |
1457 png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) | 1501 png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) |
1458 { | 1502 { |
1459 if (png_ptr == NULL) | 1503 if (png_ptr == NULL) |
1460 return; | 1504 return; |
1461 | 1505 |
1462 if (size == 0 || size > PNG_UINT_31_MAX) | 1506 if (size == 0 || size > PNG_UINT_31_MAX) |
1463 png_error(png_ptr, "invalid compression buffer size"); | 1507 png_error(png_ptr, "invalid compression buffer size"); |
1464 | 1508 |
1465 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED | 1509 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
1466 if (png_ptr->mode & PNG_IS_READ_STRUCT) | 1510 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
1467 { | 1511 { |
1468 png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ | 1512 png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ |
1469 return; | 1513 return; |
1470 } | 1514 } |
1471 # endif | 1515 # endif |
1472 | 1516 |
1473 # ifdef PNG_WRITE_SUPPORTED | 1517 # ifdef PNG_WRITE_SUPPORTED |
1474 if (!(png_ptr->mode & PNG_IS_READ_STRUCT)) | 1518 if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
1475 { | 1519 { |
1476 if (png_ptr->zowner != 0) | 1520 if (png_ptr->zowner != 0) |
1477 { | 1521 { |
1478 png_warning(png_ptr, | 1522 png_warning(png_ptr, |
1479 "Compression buffer size cannot be changed because it is in use"); | 1523 "Compression buffer size cannot be changed because it is in use"); |
| 1524 |
1480 return; | 1525 return; |
1481 } | 1526 } |
1482 | 1527 |
| 1528 #ifndef __COVERITY__ |
| 1529 /* Some compilers complain that this is always false. However, it |
| 1530 * can be true when integer overflow happens. |
| 1531 */ |
1483 if (size > ZLIB_IO_MAX) | 1532 if (size > ZLIB_IO_MAX) |
1484 { | 1533 { |
1485 png_warning(png_ptr, | 1534 png_warning(png_ptr, |
1486 "Compression buffer size limited to system maximum"); | 1535 "Compression buffer size limited to system maximum"); |
1487 size = ZLIB_IO_MAX; /* must fit */ | 1536 size = ZLIB_IO_MAX; /* must fit */ |
1488 } | 1537 } |
1489 | 1538 #endif |
1490 else if (size < 6) | 1539 |
| 1540 if (size < 6) |
1491 { | 1541 { |
1492 /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH | 1542 /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH |
1493 * if this is permitted. | 1543 * if this is permitted. |
1494 */ | 1544 */ |
1495 png_warning(png_ptr, | 1545 png_warning(png_ptr, |
1496 "Compression buffer size cannot be reduced below 6"); | 1546 "Compression buffer size cannot be reduced below 6"); |
| 1547 |
1497 return; | 1548 return; |
1498 } | 1549 } |
1499 | 1550 |
1500 if (png_ptr->zbuffer_size != size) | 1551 if (png_ptr->zbuffer_size != size) |
1501 { | 1552 { |
1502 png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); | 1553 png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); |
1503 png_ptr->zbuffer_size = (uInt)size; | 1554 png_ptr->zbuffer_size = (uInt)size; |
1504 } | 1555 } |
1505 } | 1556 } |
1506 # endif | 1557 # endif |
1507 } | 1558 } |
1508 | 1559 |
1509 void PNGAPI | 1560 void PNGAPI |
1510 png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) | 1561 png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) |
1511 { | 1562 { |
1512 if (png_ptr && info_ptr) | 1563 if (png_ptr != NULL && info_ptr != NULL) |
1513 info_ptr->valid &= ~mask; | 1564 info_ptr->valid &= ~mask; |
1514 } | 1565 } |
1515 | 1566 |
1516 | 1567 |
1517 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 1568 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
1518 /* This function was added to libpng 1.2.6 */ | 1569 /* This function was added to libpng 1.2.6 */ |
1519 void PNGAPI | 1570 void PNGAPI |
1520 png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, | 1571 png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, |
1521 png_uint_32 user_height_max) | 1572 png_uint_32 user_height_max) |
1522 { | 1573 { |
1523 /* Images with dimensions larger than these limits will be | 1574 /* Images with dimensions larger than these limits will be |
1524 * rejected by png_set_IHDR(). To accept any PNG datastream | 1575 * rejected by png_set_IHDR(). To accept any PNG datastream |
1525 * regardless of dimensions, set both limits to 0x7ffffffL. | 1576 * regardless of dimensions, set both limits to 0x7fffffff. |
1526 */ | 1577 */ |
1527 if (png_ptr == NULL) | 1578 if (png_ptr == NULL) |
1528 return; | 1579 return; |
1529 | 1580 |
1530 png_ptr->user_width_max = user_width_max; | 1581 png_ptr->user_width_max = user_width_max; |
1531 png_ptr->user_height_max = user_height_max; | 1582 png_ptr->user_height_max = user_height_max; |
1532 } | 1583 } |
1533 | 1584 |
1534 /* This function was added to libpng 1.4.0 */ | 1585 /* This function was added to libpng 1.4.0 */ |
1535 void PNGAPI | 1586 void PNGAPI |
1536 png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max) | 1587 png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max) |
1537 { | 1588 { |
1538 if (png_ptr) | 1589 if (png_ptr != NULL) |
1539 png_ptr->user_chunk_cache_max = user_chunk_cache_max; | 1590 png_ptr->user_chunk_cache_max = user_chunk_cache_max; |
1540 } | 1591 } |
1541 | 1592 |
1542 /* This function was added to libpng 1.4.1 */ | 1593 /* This function was added to libpng 1.4.1 */ |
1543 void PNGAPI | 1594 void PNGAPI |
1544 png_set_chunk_malloc_max (png_structrp png_ptr, | 1595 png_set_chunk_malloc_max (png_structrp png_ptr, |
1545 png_alloc_size_t user_chunk_malloc_max) | 1596 png_alloc_size_t user_chunk_malloc_max) |
1546 { | 1597 { |
1547 if (png_ptr) | 1598 if (png_ptr != NULL) |
1548 png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; | 1599 png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; |
1549 } | 1600 } |
1550 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ | 1601 #endif /* ?SET_USER_LIMITS */ |
1551 | 1602 |
1552 | 1603 |
1553 #ifdef PNG_BENIGN_ERRORS_SUPPORTED | 1604 #ifdef PNG_BENIGN_ERRORS_SUPPORTED |
1554 void PNGAPI | 1605 void PNGAPI |
1555 png_set_benign_errors(png_structrp png_ptr, int allowed) | 1606 png_set_benign_errors(png_structrp png_ptr, int allowed) |
1556 { | 1607 { |
1557 png_debug(1, "in png_set_benign_errors"); | 1608 png_debug(1, "in png_set_benign_errors"); |
1558 | 1609 |
1559 /* If allowed is 1, png_benign_error() is treated as a warning. | 1610 /* If allowed is 1, png_benign_error() is treated as a warning. |
1560 * | 1611 * |
1561 * If allowed is 0, png_benign_error() is treated as an error (which | 1612 * If allowed is 0, png_benign_error() is treated as an error (which |
1562 * is the default behavior if png_set_benign_errors() is not called). | 1613 * is the default behavior if png_set_benign_errors() is not called). |
1563 */ | 1614 */ |
1564 | 1615 |
1565 if (allowed) | 1616 if (allowed != 0) |
1566 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN | | 1617 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN | |
1567 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN; | 1618 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN; |
1568 | 1619 |
1569 else | 1620 else |
1570 png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN | | 1621 png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN | |
1571 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN); | 1622 PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN); |
1572 } | 1623 } |
1573 #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ | 1624 #endif /* BENIGN_ERRORS */ |
1574 | 1625 |
1575 #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED | 1626 #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED |
1576 /* Whether to report invalid palette index; added at libng-1.5.10. | 1627 /* Whether to report invalid palette index; added at libng-1.5.10. |
1577 * It is possible for an indexed (color-type==3) PNG file to contain | 1628 * It is possible for an indexed (color-type==3) PNG file to contain |
1578 * pixels with invalid (out-of-range) indexes if the PLTE chunk has | 1629 * pixels with invalid (out-of-range) indexes if the PLTE chunk has |
1579 * fewer entries than the image's bit-depth would allow. We recover | 1630 * fewer entries than the image's bit-depth would allow. We recover |
1580 * from this gracefully by filling any incomplete palette with zeroes | 1631 * from this gracefully by filling any incomplete palette with zeros |
1581 * (opaque black). By default, when this occurs libpng will issue | 1632 * (opaque black). By default, when this occurs libpng will issue |
1582 * a benign error. This API can be used to override that behavior. | 1633 * a benign error. This API can be used to override that behavior. |
1583 */ | 1634 */ |
1584 void PNGAPI | 1635 void PNGAPI |
1585 png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) | 1636 png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) |
1586 { | 1637 { |
1587 png_debug(1, "in png_set_check_for_invalid_index"); | 1638 png_debug(1, "in png_set_check_for_invalid_index"); |
1588 | 1639 |
1589 if (allowed > 0) | 1640 if (allowed > 0) |
1590 png_ptr->num_palette_max = 0; | 1641 png_ptr->num_palette_max = 0; |
1591 | 1642 |
1592 else | 1643 else |
1593 png_ptr->num_palette_max = -1; | 1644 png_ptr->num_palette_max = -1; |
1594 } | 1645 } |
1595 #endif | 1646 #endif |
1596 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 1647 #endif /* READ || WRITE */ |
OLD | NEW |