Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: third_party/libpng/pngrutil.c

Issue 1118002: libpng: update to 1.2.43 (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libpng/pngrtran.c ('k') | third_party/libpng/pngset.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngrutil.c - utilities to read a PNG file 2 /* pngrutil.c - utilities to read a PNG file
3 * 3 *
4 * Last changed in libpng 1.2.37 [June 4, 2009] 4 * Last changed in libpng 1.2.43 [February 25, 2010]
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (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.)
9 * 8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
10 * This file contains routines that are only called from within 13 * This file contains routines that are only called from within
11 * libpng itself during the course of reading an image. 14 * libpng itself during the course of reading an image.
12 */ 15 */
13 16
14 #define PNG_INTERNAL 17 #define PNG_INTERNAL
18 #define PNG_NO_PEDANTIC_WARNINGS
15 #include "png.h" 19 #include "png.h"
16 #if defined(PNG_READ_SUPPORTED) 20 #ifdef PNG_READ_SUPPORTED
17 21
18 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) 22 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
19 # define WIN32_WCE_OLD 23 # define WIN32_WCE_OLD
20 #endif 24 #endif
21 25
22 #ifdef PNG_FLOATING_POINT_SUPPORTED 26 #ifdef PNG_FLOATING_POINT_SUPPORTED
23 # if defined(WIN32_WCE_OLD) 27 # ifdef WIN32_WCE_OLD
24 /* The strtod() function is not supported on WindowsCE */ 28 /* The strtod() function is not supported on WindowsCE */
25 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **end ptr) 29 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr,
30 char **endptr)
26 { 31 {
27 double result = 0; 32 double result = 0;
28 int len; 33 int len;
29 wchar_t *str, *end; 34 wchar_t *str, *end;
30 35
31 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); 36 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
32 str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t)); 37 str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t));
33 if ( NULL != str ) 38 if ( NULL != str )
34 { 39 {
35 MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); 40 MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 { 211 {
207 crc = png_get_uint_32(crc_bytes); 212 crc = png_get_uint_32(crc_bytes);
208 return ((int)(crc != png_ptr->crc)); 213 return ((int)(crc != png_ptr->crc));
209 } 214 }
210 else 215 else
211 return (0); 216 return (0);
212 } 217 }
213 218
214 #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \ 219 #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
215 defined(PNG_READ_iCCP_SUPPORTED) 220 defined(PNG_READ_iCCP_SUPPORTED)
221 static png_size_t
222 png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size,
223 png_bytep output, png_size_t output_size)
224 {
225 png_size_t count = 0;
226
227 png_ptr->zstream.next_in = (png_bytep)data; /* const_cast: VALID */
228 png_ptr->zstream.avail_in = size;
229
230 while (1)
231 {
232 int ret, avail;
233
234 /* Reset the output buffer each time round - we empty it
235 * after every inflate call.
236 */
237 png_ptr->zstream.next_out = png_ptr->zbuf;
238 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
239
240 ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
241 avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out;
242
243 /* First copy/count any new output - but only if we didn't
244 * get an error code.
245 */
246 if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0)
247 {
248 if (output != 0 && output_size > count)
249 {
250 int copy = output_size - count;
251 if (avail < copy) copy = avail;
252 png_memcpy(output + count, png_ptr->zbuf, copy);
253 }
254 count += avail;
255 }
256
257 if (ret == Z_OK)
258 continue;
259
260 /* Termination conditions - always reset the zstream, it
261 * must be left in inflateInit state.
262 */
263 png_ptr->zstream.avail_in = 0;
264 inflateReset(&png_ptr->zstream);
265
266 if (ret == Z_STREAM_END)
267 return count; /* NOTE: may be zero. */
268
269 /* Now handle the error codes - the API always returns 0
270 * and the error message is dumped into the uncompressed
271 * buffer if available.
272 */
273 {
274 char *msg, umsg[52];
275 if (png_ptr->zstream.msg != 0)
276 msg = png_ptr->zstream.msg;
277 else
278 {
279 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
280 switch (ret)
281 {
282 case Z_BUF_ERROR:
283 msg = "Buffer error in compressed datastream in %s chunk";
284 break;
285 case Z_DATA_ERROR:
286 msg = "Data error in compressed datastream in %s chunk";
287 break;
288 default:
289 msg = "Incomplete compressed datastream in %s chunk";
290 break;
291 }
292
293 png_snprintf(umsg, sizeof umsg, msg, png_ptr->chunk_name);
294 msg = umsg;
295 #else
296 msg = "Damaged compressed datastream in chunk other than IDAT";
297 #endif
298 }
299
300 png_warning(png_ptr, msg);
301 }
302
303 /* 0 means an error - notice that this code simple ignores
304 * zero length compressed chunks as a result.
305 */
306 return 0;
307 }
308 }
309
216 /* 310 /*
217 * Decompress trailing data in a chunk. The assumption is that chunkdata 311 * Decompress trailing data in a chunk. The assumption is that chunkdata
218 * points at an allocated area holding the contents of a chunk with a 312 * points at an allocated area holding the contents of a chunk with a
219 * trailing compressed part. What we get back is an allocated area 313 * trailing compressed part. What we get back is an allocated area
220 * holding the original prefix part and an uncompressed version of the 314 * holding the original prefix part and an uncompressed version of the
221 * trailing part (the malloc area passed in is freed). 315 * trailing part (the malloc area passed in is freed).
222 */ 316 */
223 void /* PRIVATE */ 317 void /* PRIVATE */
224 png_decompress_chunk(png_structp png_ptr, int comp_type, 318 png_decompress_chunk(png_structp png_ptr, int comp_type,
225 png_size_t chunklength, 319 png_size_t chunklength,
226 png_size_t prefix_size, png_size_t *newlength) 320 png_size_t prefix_size, png_size_t *newlength)
227 { 321 {
228 static PNG_CONST char msg[] = "Error decoding compressed text"; 322 /* The caller should guarantee this */
229 png_charp text; 323 if (prefix_size > chunklength)
230 png_size_t text_size; 324 {
231 325 /* The recovery is to delete the chunk. */
232 if (comp_type == PNG_COMPRESSION_TYPE_BASE) 326 png_warning(png_ptr, "invalid chunklength");
233 { 327 prefix_size = 0; /* To delete everything */
234 int ret = Z_OK; 328 }
235 png_ptr->zstream.next_in = (png_bytep)(png_ptr->chunkdata + prefix_size); 329
236 png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size); 330 else if (comp_type == PNG_COMPRESSION_TYPE_BASE)
237 png_ptr->zstream.next_out = png_ptr->zbuf; 331 {
238 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 332 png_size_t expanded_size = png_inflate(png_ptr,
239 333 » » (png_bytep)(png_ptr->chunkdata + prefix_size),
240 text_size = 0; 334 chunklength - prefix_size,
241 text = NULL; 335 » » 0/*output*/, 0/*output size*/);
SkyLined 2010/03/18 16:34:46 Seems to me like the code decompresses twice, once
agl 2010/03/18 16:50:41 I agree that this isn't great. It could probably b
242 336
243 while (png_ptr->zstream.avail_in) 337 /* Now check the limits on this chunk - if the limit fails the
244 { 338 * compressed data will be removed, the prefix will remain.
245 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); 339 */
246 if (ret != Z_OK && ret != Z_STREAM_END) 340 #ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
341 if (png_ptr->user_chunk_malloc_max &&
342 (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1))
343 #else
344 if ((PNG_USER_CHUNK_MALLOC_MAX > 0) &&
345 prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1)
346 #endif
347 png_warning(png_ptr, "Exceeded size limit while expanding chunk");
348
349 /* If the size is zero either there was an error and a message
350 * has already been output (warning) or the size really is zero
351 * and we have nothing to do - the code will exit through the
352 * error case below.
353 */
354 else if (expanded_size > 0)
355 {
356 /* Success (maybe) - really uncompress the chunk. */
357 » png_size_t new_size = 0;
358 » png_charp text = png_malloc_warn(png_ptr,
359 » » » prefix_size + expanded_size + 1);
360
361 if (text != NULL)
247 { 362 {
248 if (png_ptr->zstream.msg != NULL) 363 » png_memcpy(text, png_ptr->chunkdata, prefix_size);
249 png_warning(png_ptr, png_ptr->zstream.msg); 364 » new_size = png_inflate(png_ptr,
250 else 365 (png_bytep)(png_ptr->chunkdata + prefix_size),
251 png_warning(png_ptr, msg); 366 » » chunklength - prefix_size,
252 inflateReset(&png_ptr->zstream); 367 (png_bytep)(text + prefix_size), expanded_size);
253 png_ptr->zstream.avail_in = 0; 368 » text[prefix_size + expanded_size] = 0; /* just in case */
254 369
255 if (text == NULL) 370 » if (new_size == expanded_size)
256 { 371 » {
257 text_size = prefix_size + png_sizeof(msg) + 1; 372 » png_free(png_ptr, png_ptr->chunkdata);
258 text = (png_charp)png_malloc_warn(png_ptr, text_size); 373 » png_ptr->chunkdata = text;
259 if (text == NULL) 374 » *newlength = prefix_size + expanded_size;
260 { 375 » return; /* The success return! */
261 png_free(png_ptr, png_ptr->chunkdata); 376 » }
262 png_ptr->chunkdata = NULL; 377
263 png_error(png_ptr, "Not enough memory to decompress chunk"); 378 » png_warning(png_ptr, "png_inflate logic error");
264 } 379 » png_free(png_ptr, text);
265 png_memcpy(text, png_ptr->chunkdata, prefix_size); 380 » }
266 } 381 » else
267 382 png_warning(png_ptr, "Not enough memory to decompress chunk.");
268 text[text_size - 1] = 0x00; 383 }
269 384 }
270 /* Copy what we can of the error message into the text chunk */ 385
271 text_size = (png_size_t)(chunklength -
272 (text - png_ptr->chunkdata) - 1);
273 if (text_size > png_sizeof(msg))
274 text_size = png_sizeof(msg);
275 png_memcpy(text + prefix_size, msg, text_size);
276 break;
277 }
278 if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
279 {
280 if (text == NULL)
281 {
282 text_size = prefix_size +
283 png_ptr->zbuf_size - png_ptr->zstream.avail_out;
284 text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
285 if (text == NULL)
286 {
287 png_free(png_ptr, png_ptr->chunkdata);
288 png_ptr->chunkdata = NULL;
289 png_error(png_ptr,
290 "Not enough memory to decompress chunk.");
291 }
292 png_memcpy(text + prefix_size, png_ptr->zbuf,
293 text_size - prefix_size);
294 png_memcpy(text, png_ptr->chunkdata, prefix_size);
295 *(text + text_size) = 0x00;
296 }
297 else
298 {
299 png_charp tmp;
300
301 tmp = text;
302 text = (png_charp)png_malloc_warn(png_ptr,
303 (png_uint_32)(text_size +
304 png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
305 if (text == NULL)
306 {
307 png_free(png_ptr, tmp);
308 png_free(png_ptr, png_ptr->chunkdata);
309 png_ptr->chunkdata = NULL;
310 png_error(png_ptr,
311 "Not enough memory to decompress chunk..");
312 }
313 png_memcpy(text, tmp, text_size);
314 png_free(png_ptr, tmp);
315 png_memcpy(text + text_size, png_ptr->zbuf,
316 (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
317 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
318 *(text + text_size) = 0x00;
319 }
320 if (ret == Z_STREAM_END)
321 break;
322 else
323 {
324 png_ptr->zstream.next_out = png_ptr->zbuf;
325 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
326 }
327 }
328 }
329 if (ret != Z_STREAM_END)
330 {
331 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
332 char umsg[52];
333
334 if (ret == Z_BUF_ERROR)
335 png_snprintf(umsg, 52,
336 "Buffer error in compressed datastream in %s chunk",
337 png_ptr->chunk_name);
338
339 else if (ret == Z_DATA_ERROR)
340 png_snprintf(umsg, 52,
341 "Data error in compressed datastream in %s chunk",
342 png_ptr->chunk_name);
343
344 else
345 png_snprintf(umsg, 52,
346 "Incomplete compressed datastream in %s chunk",
347 png_ptr->chunk_name);
348
349 png_warning(png_ptr, umsg);
350 #else
351 png_warning(png_ptr,
352 "Incomplete compressed datastream in chunk other than IDAT");
353 #endif
354 text_size = prefix_size;
355 if (text == NULL)
356 {
357 text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
358 if (text == NULL)
359 {
360 png_free(png_ptr, png_ptr->chunkdata);
361 png_ptr->chunkdata = NULL;
362 png_error(png_ptr, "Not enough memory for text.");
363 }
364 png_memcpy(text, png_ptr->chunkdata, prefix_size);
365 }
366 *(text + text_size) = 0x00;
367 }
368
369 inflateReset(&png_ptr->zstream);
370 png_ptr->zstream.avail_in = 0;
371
372 png_free(png_ptr, png_ptr->chunkdata);
373 png_ptr->chunkdata = text;
374 *newlength=text_size;
375 }
376 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ 386 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
377 { 387 {
378 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
379 char umsg[50]; 388 char umsg[50];
380 389
381 png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type); 390 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
391 png_snprintf(umsg, sizeof umsg, "Unknown zTXt compression type %d", comp_t ype);
382 png_warning(png_ptr, umsg); 392 png_warning(png_ptr, umsg);
383 #else 393 #else
384 png_warning(png_ptr, "Unknown zTXt compression type"); 394 png_warning(png_ptr, "Unknown zTXt compression type");
385 #endif 395 #endif
386 396
387 *(png_ptr->chunkdata + prefix_size) = 0x00; 397 /* The recovery is to simply drop the data. */
388 *newlength = prefix_size; 398 }
389 } 399
400 /* Generic error return - leave the prefix, delete the compressed
401 * data, reallocate the chunkdata to remove the potentially large
402 * amount of compressed data.
403 */
404 {
405 png_charp text = png_malloc_warn(png_ptr, prefix_size + 1);
406 if (text != NULL)
407 {
408 » if (prefix_size > 0)
409 png_memcpy(text, png_ptr->chunkdata, prefix_size);
410 » png_free(png_ptr, png_ptr->chunkdata);
411 » png_ptr->chunkdata = text;
412
413 » /* This is an extra zero in the 'uncompressed' part. */
414 » *(png_ptr->chunkdata + prefix_size) = 0x00;
415 }
416 /* Ignore a malloc error here - it is safe. */
417 }
418
419 *newlength = prefix_size;
390 } 420 }
391 #endif 421 #endif
392 422
393 /* Read and check the IDHR chunk */ 423 /* Read and check the IDHR chunk */
394 void /* PRIVATE */ 424 void /* PRIVATE */
395 png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 425 png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
396 { 426 {
397 png_byte buf[13]; 427 png_byte buf[13];
398 png_uint_32 width, height; 428 png_uint_32 width, height;
399 int bit_depth, color_type, compression_type, filter_type; 429 int bit_depth, color_type, compression_type, filter_type;
(...skipping 20 matching lines...) Expand all
420 compression_type = buf[10]; 450 compression_type = buf[10];
421 filter_type = buf[11]; 451 filter_type = buf[11];
422 interlace_type = buf[12]; 452 interlace_type = buf[12];
423 453
424 /* Set internal variables */ 454 /* Set internal variables */
425 png_ptr->width = width; 455 png_ptr->width = width;
426 png_ptr->height = height; 456 png_ptr->height = height;
427 png_ptr->bit_depth = (png_byte)bit_depth; 457 png_ptr->bit_depth = (png_byte)bit_depth;
428 png_ptr->interlaced = (png_byte)interlace_type; 458 png_ptr->interlaced = (png_byte)interlace_type;
429 png_ptr->color_type = (png_byte)color_type; 459 png_ptr->color_type = (png_byte)color_type;
430 #if defined(PNG_MNG_FEATURES_SUPPORTED) 460 #ifdef PNG_MNG_FEATURES_SUPPORTED
431 png_ptr->filter_type = (png_byte)filter_type; 461 png_ptr->filter_type = (png_byte)filter_type;
432 #endif 462 #endif
433 png_ptr->compression_type = (png_byte)compression_type; 463 png_ptr->compression_type = (png_byte)compression_type;
434 464
435 /* Find number of channels */ 465 /* Find number of channels */
436 switch (png_ptr->color_type) 466 switch (png_ptr->color_type)
437 { 467 {
438 case PNG_COLOR_TYPE_GRAY: 468 case PNG_COLOR_TYPE_GRAY:
439 case PNG_COLOR_TYPE_PALETTE: 469 case PNG_COLOR_TYPE_PALETTE:
440 png_ptr->channels = 1; 470 png_ptr->channels = 1;
(...skipping 22 matching lines...) Expand all
463 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 493 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
464 color_type, interlace_type, compression_type, filter_type); 494 color_type, interlace_type, compression_type, filter_type);
465 } 495 }
466 496
467 /* Read and check the palette */ 497 /* Read and check the palette */
468 void /* PRIVATE */ 498 void /* PRIVATE */
469 png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 499 png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
470 { 500 {
471 png_color palette[PNG_MAX_PALETTE_LENGTH]; 501 png_color palette[PNG_MAX_PALETTE_LENGTH];
472 int num, i; 502 int num, i;
473 #ifndef PNG_NO_POINTER_INDEXING 503 #ifdef PNG_POINTER_INDEXING_SUPPORTED
474 png_colorp pal_ptr; 504 png_colorp pal_ptr;
475 #endif 505 #endif
476 506
477 png_debug(1, "in png_handle_PLTE"); 507 png_debug(1, "in png_handle_PLTE");
478 508
479 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 509 if (!(png_ptr->mode & PNG_HAVE_IHDR))
480 png_error(png_ptr, "Missing IHDR before PLTE"); 510 png_error(png_ptr, "Missing IHDR before PLTE");
481 511
482 else if (png_ptr->mode & PNG_HAVE_IDAT) 512 else if (png_ptr->mode & PNG_HAVE_IDAT)
483 { 513 {
484 png_warning(png_ptr, "Invalid PLTE after IDAT"); 514 png_warning(png_ptr, "Invalid PLTE after IDAT");
485 png_crc_finish(png_ptr, length); 515 png_crc_finish(png_ptr, length);
486 return; 516 return;
487 } 517 }
488 518
489 else if (png_ptr->mode & PNG_HAVE_PLTE) 519 else if (png_ptr->mode & PNG_HAVE_PLTE)
490 png_error(png_ptr, "Duplicate PLTE chunk"); 520 png_error(png_ptr, "Duplicate PLTE chunk");
491 521
492 png_ptr->mode |= PNG_HAVE_PLTE; 522 png_ptr->mode |= PNG_HAVE_PLTE;
493 523
494 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) 524 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
495 { 525 {
496 png_warning(png_ptr, 526 png_warning(png_ptr,
497 "Ignoring PLTE chunk in grayscale PNG"); 527 "Ignoring PLTE chunk in grayscale PNG");
498 png_crc_finish(png_ptr, length); 528 png_crc_finish(png_ptr, length);
499 return; 529 return;
500 } 530 }
501 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 531 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
502 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) 532 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
503 { 533 {
504 png_crc_finish(png_ptr, length); 534 png_crc_finish(png_ptr, length);
505 return; 535 return;
506 } 536 }
507 #endif 537 #endif
508 538
509 if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) 539 if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
510 { 540 {
511 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) 541 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
512 { 542 {
513 png_warning(png_ptr, "Invalid palette chunk"); 543 png_warning(png_ptr, "Invalid palette chunk");
514 png_crc_finish(png_ptr, length); 544 png_crc_finish(png_ptr, length);
515 return; 545 return;
516 } 546 }
517 547
518 else 548 else
519 { 549 {
520 png_error(png_ptr, "Invalid palette chunk"); 550 png_error(png_ptr, "Invalid palette chunk");
521 } 551 }
522 } 552 }
523 553
524 num = (int)length / 3; 554 num = (int)length / 3;
525 555
526 #ifndef PNG_NO_POINTER_INDEXING 556 #ifdef PNG_POINTER_INDEXING_SUPPORTED
527 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) 557 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
528 { 558 {
529 png_byte buf[3]; 559 png_byte buf[3];
530 560
531 png_crc_read(png_ptr, buf, 3); 561 png_crc_read(png_ptr, buf, 3);
532 pal_ptr->red = buf[0]; 562 pal_ptr->red = buf[0];
533 pal_ptr->green = buf[1]; 563 pal_ptr->green = buf[1];
534 pal_ptr->blue = buf[2]; 564 pal_ptr->blue = buf[2];
535 } 565 }
536 #else 566 #else
537 for (i = 0; i < num; i++) 567 for (i = 0; i < num; i++)
538 { 568 {
539 png_byte buf[3]; 569 png_byte buf[3];
540 570
541 png_crc_read(png_ptr, buf, 3); 571 png_crc_read(png_ptr, buf, 3);
542 /* Don't depend upon png_color being any order */ 572 /* Don't depend upon png_color being any order */
543 palette[i].red = buf[0]; 573 palette[i].red = buf[0];
544 palette[i].green = buf[1]; 574 palette[i].green = buf[1];
545 palette[i].blue = buf[2]; 575 palette[i].blue = buf[2];
546 } 576 }
547 #endif 577 #endif
548 578
549 /* If we actually NEED the PLTE chunk (ie for a paletted image), we do 579 /* If we actually NEED the PLTE chunk (ie for a paletted image), we do
550 * whatever the normal CRC configuration tells us. However, if we 580 * whatever the normal CRC configuration tells us. However, if we
551 * have an RGB image, the PLTE can be considered ancillary, so 581 * have an RGB image, the PLTE can be considered ancillary, so
552 * we will act as though it is. 582 * we will act as though it is.
553 */ 583 */
554 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 584 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
555 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 585 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
556 #endif 586 #endif
557 { 587 {
558 png_crc_finish(png_ptr, 0); 588 png_crc_finish(png_ptr, 0);
559 } 589 }
560 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 590 #ifndef PNG_READ_OPT_PLTE_SUPPORTED
561 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ 591 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
562 { 592 {
563 /* If we don't want to use the data from an ancillary chunk, 593 /* If we don't want to use the data from an ancillary chunk,
564 we have two options: an error abort, or a warning and we 594 we have two options: an error abort, or a warning and we
565 ignore the data in this chunk (which should be OK, since 595 ignore the data in this chunk (which should be OK, since
566 it's considered ancillary for a RGB or RGBA image). */ 596 it's considered ancillary for a RGB or RGBA image). */
567 if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) 597 if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
568 { 598 {
569 if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) 599 if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
570 { 600 {
571 png_chunk_error(png_ptr, "CRC error"); 601 png_chunk_error(png_ptr, "CRC error");
572 } 602 }
573 else 603 else
574 { 604 {
575 png_chunk_warning(png_ptr, "CRC error"); 605 png_chunk_warning(png_ptr, "CRC error");
576 return; 606 return;
577 } 607 }
578 } 608 }
579 /* Otherwise, we (optionally) emit a warning and use the chunk. */ 609 /* Otherwise, we (optionally) emit a warning and use the chunk. */
580 else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) 610 else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
581 { 611 {
582 png_chunk_warning(png_ptr, "CRC error"); 612 png_chunk_warning(png_ptr, "CRC error");
583 } 613 }
584 } 614 }
585 #endif 615 #endif
586 616
587 png_set_PLTE(png_ptr, info_ptr, palette, num); 617 png_set_PLTE(png_ptr, info_ptr, palette, num);
588 618
589 #if defined(PNG_READ_tRNS_SUPPORTED) 619 #ifdef PNG_READ_tRNS_SUPPORTED
590 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 620 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
591 { 621 {
592 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) 622 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
593 { 623 {
594 if (png_ptr->num_trans > (png_uint_16)num) 624 if (png_ptr->num_trans > (png_uint_16)num)
595 { 625 {
596 png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); 626 png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
597 png_ptr->num_trans = (png_uint_16)num; 627 png_ptr->num_trans = (png_uint_16)num;
598 } 628 }
599 if (info_ptr->num_trans > (png_uint_16)num) 629 if (info_ptr->num_trans > (png_uint_16)num)
(...skipping 21 matching lines...) Expand all
621 651
622 if (length != 0) 652 if (length != 0)
623 { 653 {
624 png_warning(png_ptr, "Incorrect IEND chunk length"); 654 png_warning(png_ptr, "Incorrect IEND chunk length");
625 } 655 }
626 png_crc_finish(png_ptr, length); 656 png_crc_finish(png_ptr, length);
627 657
628 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ 658 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
629 } 659 }
630 660
631 #if defined(PNG_READ_gAMA_SUPPORTED) 661 #ifdef PNG_READ_gAMA_SUPPORTED
632 void /* PRIVATE */ 662 void /* PRIVATE */
633 png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 663 png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
634 { 664 {
635 png_fixed_point igamma; 665 png_fixed_point igamma;
636 #ifdef PNG_FLOATING_POINT_SUPPORTED 666 #ifdef PNG_FLOATING_POINT_SUPPORTED
637 float file_gamma; 667 float file_gamma;
638 #endif 668 #endif
639 png_byte buf[4]; 669 png_byte buf[4];
640 670
641 png_debug(1, "in png_handle_gAMA"); 671 png_debug(1, "in png_handle_gAMA");
642 672
643 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 673 if (!(png_ptr->mode & PNG_HAVE_IHDR))
644 png_error(png_ptr, "Missing IHDR before gAMA"); 674 png_error(png_ptr, "Missing IHDR before gAMA");
645 else if (png_ptr->mode & PNG_HAVE_IDAT) 675 else if (png_ptr->mode & PNG_HAVE_IDAT)
646 { 676 {
647 png_warning(png_ptr, "Invalid gAMA after IDAT"); 677 png_warning(png_ptr, "Invalid gAMA after IDAT");
648 png_crc_finish(png_ptr, length); 678 png_crc_finish(png_ptr, length);
649 return; 679 return;
650 } 680 }
651 else if (png_ptr->mode & PNG_HAVE_PLTE) 681 else if (png_ptr->mode & PNG_HAVE_PLTE)
652 /* Should be an error, but we can cope with it */ 682 /* Should be an error, but we can cope with it */
653 png_warning(png_ptr, "Out of place gAMA chunk"); 683 png_warning(png_ptr, "Out of place gAMA chunk");
654 684
655 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 685 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
656 #if defined(PNG_READ_sRGB_SUPPORTED) 686 #ifdef PNG_READ_sRGB_SUPPORTED
657 && !(info_ptr->valid & PNG_INFO_sRGB) 687 && !(info_ptr->valid & PNG_INFO_sRGB)
658 #endif 688 #endif
659 ) 689 )
660 { 690 {
661 png_warning(png_ptr, "Duplicate gAMA chunk"); 691 png_warning(png_ptr, "Duplicate gAMA chunk");
662 png_crc_finish(png_ptr, length); 692 png_crc_finish(png_ptr, length);
663 return; 693 return;
664 } 694 }
665 695
666 if (length != 4) 696 if (length != 4)
667 { 697 {
668 png_warning(png_ptr, "Incorrect gAMA chunk length"); 698 png_warning(png_ptr, "Incorrect gAMA chunk length");
669 png_crc_finish(png_ptr, length); 699 png_crc_finish(png_ptr, length);
670 return; 700 return;
671 } 701 }
672 702
673 png_crc_read(png_ptr, buf, 4); 703 png_crc_read(png_ptr, buf, 4);
674 if (png_crc_finish(png_ptr, 0)) 704 if (png_crc_finish(png_ptr, 0))
675 return; 705 return;
676 706
677 igamma = (png_fixed_point)png_get_uint_32(buf); 707 igamma = (png_fixed_point)png_get_uint_32(buf);
678 /* Check for zero gamma */ 708 /* Check for zero gamma */
679 if (igamma == 0) 709 if (igamma == 0)
680 { 710 {
681 png_warning(png_ptr, 711 png_warning(png_ptr,
682 "Ignoring gAMA chunk with gamma=0"); 712 "Ignoring gAMA chunk with gamma=0");
683 return; 713 return;
684 } 714 }
685 715
686 #if defined(PNG_READ_sRGB_SUPPORTED) 716 #ifdef PNG_READ_sRGB_SUPPORTED
687 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) 717 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
688 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) 718 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
689 { 719 {
690 png_warning(png_ptr, 720 png_warning(png_ptr,
691 "Ignoring incorrect gAMA value when sRGB is also present"); 721 "Ignoring incorrect gAMA value when sRGB is also present");
692 #ifndef PNG_NO_CONSOLE_IO 722 #ifdef PNG_CONSOLE_IO_SUPPORTED
693 fprintf(stderr, "gamma = (%d/100000)", (int)igamma); 723 fprintf(stderr, "gamma = (%d/100000)", (int)igamma);
694 #endif 724 #endif
695 return; 725 return;
696 } 726 }
697 #endif /* PNG_READ_sRGB_SUPPORTED */ 727 #endif /* PNG_READ_sRGB_SUPPORTED */
698 728
699 #ifdef PNG_FLOATING_POINT_SUPPORTED 729 #ifdef PNG_FLOATING_POINT_SUPPORTED
700 file_gamma = (float)igamma / (float)100000.0; 730 file_gamma = (float)igamma / (float)100000.0;
701 # ifdef PNG_READ_GAMMA_SUPPORTED 731 # ifdef PNG_READ_GAMMA_SUPPORTED
702 png_ptr->gamma = file_gamma; 732 png_ptr->gamma = file_gamma;
703 # endif 733 # endif
704 png_set_gAMA(png_ptr, info_ptr, file_gamma); 734 png_set_gAMA(png_ptr, info_ptr, file_gamma);
705 #endif 735 #endif
706 #ifdef PNG_FIXED_POINT_SUPPORTED 736 #ifdef PNG_FIXED_POINT_SUPPORTED
707 png_set_gAMA_fixed(png_ptr, info_ptr, igamma); 737 png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
708 #endif 738 #endif
709 } 739 }
710 #endif 740 #endif
711 741
712 #if defined(PNG_READ_sBIT_SUPPORTED) 742 #ifdef PNG_READ_sBIT_SUPPORTED
713 void /* PRIVATE */ 743 void /* PRIVATE */
714 png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 744 png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
715 { 745 {
716 png_size_t truelen; 746 png_size_t truelen;
717 png_byte buf[4]; 747 png_byte buf[4];
718 748
719 png_debug(1, "in png_handle_sBIT"); 749 png_debug(1, "in png_handle_sBIT");
720 750
721 buf[0] = buf[1] = buf[2] = buf[3] = 0; 751 buf[0] = buf[1] = buf[2] = buf[3] = 0;
722 752
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 png_ptr->sig_bit.gray = buf[0]; 798 png_ptr->sig_bit.gray = buf[0];
769 png_ptr->sig_bit.red = buf[0]; 799 png_ptr->sig_bit.red = buf[0];
770 png_ptr->sig_bit.green = buf[0]; 800 png_ptr->sig_bit.green = buf[0];
771 png_ptr->sig_bit.blue = buf[0]; 801 png_ptr->sig_bit.blue = buf[0];
772 png_ptr->sig_bit.alpha = buf[1]; 802 png_ptr->sig_bit.alpha = buf[1];
773 } 803 }
774 png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); 804 png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
775 } 805 }
776 #endif 806 #endif
777 807
778 #if defined(PNG_READ_cHRM_SUPPORTED) 808 #ifdef PNG_READ_cHRM_SUPPORTED
779 void /* PRIVATE */ 809 void /* PRIVATE */
780 png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 810 png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
781 { 811 {
782 png_byte buf[32]; 812 png_byte buf[32];
783 #ifdef PNG_FLOATING_POINT_SUPPORTED 813 #ifdef PNG_FLOATING_POINT_SUPPORTED
784 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; 814 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
785 #endif 815 #endif
786 png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, 816 png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
787 int_y_green, int_x_blue, int_y_blue; 817 int_y_green, int_x_blue, int_y_blue;
788 818
789 png_uint_32 uint_x, uint_y; 819 png_uint_32 uint_x, uint_y;
790 820
791 png_debug(1, "in png_handle_cHRM"); 821 png_debug(1, "in png_handle_cHRM");
792 822
793 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 823 if (!(png_ptr->mode & PNG_HAVE_IHDR))
794 png_error(png_ptr, "Missing IHDR before cHRM"); 824 png_error(png_ptr, "Missing IHDR before cHRM");
795 else if (png_ptr->mode & PNG_HAVE_IDAT) 825 else if (png_ptr->mode & PNG_HAVE_IDAT)
796 { 826 {
797 png_warning(png_ptr, "Invalid cHRM after IDAT"); 827 png_warning(png_ptr, "Invalid cHRM after IDAT");
798 png_crc_finish(png_ptr, length); 828 png_crc_finish(png_ptr, length);
799 return; 829 return;
800 } 830 }
801 else if (png_ptr->mode & PNG_HAVE_PLTE) 831 else if (png_ptr->mode & PNG_HAVE_PLTE)
802 /* Should be an error, but we can cope with it */ 832 /* Should be an error, but we can cope with it */
803 png_warning(png_ptr, "Missing PLTE before cHRM"); 833 png_warning(png_ptr, "Missing PLTE before cHRM");
804 834
805 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) 835 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
806 #if defined(PNG_READ_sRGB_SUPPORTED) 836 #ifdef PNG_READ_sRGB_SUPPORTED
807 && !(info_ptr->valid & PNG_INFO_sRGB) 837 && !(info_ptr->valid & PNG_INFO_sRGB)
808 #endif 838 #endif
809 ) 839 )
810 { 840 {
811 png_warning(png_ptr, "Duplicate cHRM chunk"); 841 png_warning(png_ptr, "Duplicate cHRM chunk");
812 png_crc_finish(png_ptr, length); 842 png_crc_finish(png_ptr, length);
813 return; 843 return;
814 } 844 }
815 845
816 if (length != 32) 846 if (length != 32)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 white_x = (float)int_x_white / (float)100000.0; 878 white_x = (float)int_x_white / (float)100000.0;
849 white_y = (float)int_y_white / (float)100000.0; 879 white_y = (float)int_y_white / (float)100000.0;
850 red_x = (float)int_x_red / (float)100000.0; 880 red_x = (float)int_x_red / (float)100000.0;
851 red_y = (float)int_y_red / (float)100000.0; 881 red_y = (float)int_y_red / (float)100000.0;
852 green_x = (float)int_x_green / (float)100000.0; 882 green_x = (float)int_x_green / (float)100000.0;
853 green_y = (float)int_y_green / (float)100000.0; 883 green_y = (float)int_y_green / (float)100000.0;
854 blue_x = (float)int_x_blue / (float)100000.0; 884 blue_x = (float)int_x_blue / (float)100000.0;
855 blue_y = (float)int_y_blue / (float)100000.0; 885 blue_y = (float)int_y_blue / (float)100000.0;
856 #endif 886 #endif
857 887
858 #if defined(PNG_READ_sRGB_SUPPORTED) 888 #ifdef PNG_READ_sRGB_SUPPORTED
859 if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) 889 if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
860 { 890 {
861 if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || 891 if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
862 PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) || 892 PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
863 PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) || 893 PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
864 PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) || 894 PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
865 PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) || 895 PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
866 PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) || 896 PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
867 PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) || 897 PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
868 PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000)) 898 PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
869 { 899 {
870 png_warning(png_ptr, 900 png_warning(png_ptr,
871 "Ignoring incorrect cHRM value when sRGB is also present"); 901 "Ignoring incorrect cHRM value when sRGB is also present");
872 #ifndef PNG_NO_CONSOLE_IO 902 #ifdef PNG_CONSOLE_IO_SUPPORTED
873 #ifdef PNG_FLOATING_POINT_SUPPORTED 903 #ifdef PNG_FLOATING_POINT_SUPPORTED
874 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", 904 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n",
875 white_x, white_y, red_x, red_y); 905 white_x, white_y, red_x, red_y);
876 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n", 906 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n",
877 green_x, green_y, blue_x, blue_y); 907 green_x, green_y, blue_x, blue_y);
878 #else 908 #else
879 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", 909 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
880 int_x_white, int_y_white, int_x_red, int_y_red); 910 int_x_white, int_y_white, int_x_red, int_y_red);
881 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", 911 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
882 int_x_green, int_y_green, int_x_blue, int_y_blue); 912 int_x_green, int_y_green, int_x_blue, int_y_blue);
883 #endif 913 #endif
884 #endif /* PNG_NO_CONSOLE_IO */ 914 #endif /* PNG_CONSOLE_IO_SUPPORTED */
885 } 915 }
886 return; 916 return;
887 } 917 }
888 #endif /* PNG_READ_sRGB_SUPPORTED */ 918 #endif /* PNG_READ_sRGB_SUPPORTED */
889 919
890 #ifdef PNG_FLOATING_POINT_SUPPORTED 920 #ifdef PNG_FLOATING_POINT_SUPPORTED
891 png_set_cHRM(png_ptr, info_ptr, 921 png_set_cHRM(png_ptr, info_ptr,
892 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 922 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
893 #endif 923 #endif
894 #ifdef PNG_FIXED_POINT_SUPPORTED 924 #ifdef PNG_FIXED_POINT_SUPPORTED
895 png_set_cHRM_fixed(png_ptr, info_ptr, 925 png_set_cHRM_fixed(png_ptr, info_ptr,
896 int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, 926 int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
897 int_y_green, int_x_blue, int_y_blue); 927 int_y_green, int_x_blue, int_y_blue);
898 #endif 928 #endif
899 } 929 }
900 #endif 930 #endif
901 931
902 #if defined(PNG_READ_sRGB_SUPPORTED) 932 #ifdef PNG_READ_sRGB_SUPPORTED
903 void /* PRIVATE */ 933 void /* PRIVATE */
904 png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 934 png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
905 { 935 {
906 int intent; 936 int intent;
907 png_byte buf[1]; 937 png_byte buf[1];
908 938
909 png_debug(1, "in png_handle_sRGB"); 939 png_debug(1, "in png_handle_sRGB");
910 940
911 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 941 if (!(png_ptr->mode & PNG_HAVE_IHDR))
912 png_error(png_ptr, "Missing IHDR before sRGB"); 942 png_error(png_ptr, "Missing IHDR before sRGB");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 igamma=info_ptr->int_gamma; 984 igamma=info_ptr->int_gamma;
955 #else 985 #else
956 # ifdef PNG_FLOATING_POINT_SUPPORTED 986 # ifdef PNG_FLOATING_POINT_SUPPORTED
957 igamma=(png_fixed_point)(info_ptr->gamma * 100000.); 987 igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
958 # endif 988 # endif
959 #endif 989 #endif
960 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) 990 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
961 { 991 {
962 png_warning(png_ptr, 992 png_warning(png_ptr,
963 "Ignoring incorrect gAMA value when sRGB is also present"); 993 "Ignoring incorrect gAMA value when sRGB is also present");
964 #ifndef PNG_NO_CONSOLE_IO 994 #ifdef PNG_CONSOLE_IO_SUPPORTED
965 # ifdef PNG_FIXED_POINT_SUPPORTED 995 # ifdef PNG_FIXED_POINT_SUPPORTED
966 fprintf(stderr, "incorrect gamma=(%d/100000)\n", 996 fprintf(stderr, "incorrect gamma=(%d/100000)\n",
967 (int)png_ptr->int_gamma); 997 (int)png_ptr->int_gamma);
968 # else 998 # else
969 # ifdef PNG_FLOATING_POINT_SUPPORTED 999 # ifdef PNG_FLOATING_POINT_SUPPORTED
970 fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma); 1000 fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma);
971 # endif 1001 # endif
972 # endif 1002 # endif
973 #endif 1003 #endif
974 } 1004 }
(...skipping 15 matching lines...) Expand all
990 png_warning(png_ptr, 1020 png_warning(png_ptr,
991 "Ignoring incorrect cHRM value when sRGB is also present"); 1021 "Ignoring incorrect cHRM value when sRGB is also present");
992 } 1022 }
993 #endif /* PNG_FIXED_POINT_SUPPORTED */ 1023 #endif /* PNG_FIXED_POINT_SUPPORTED */
994 #endif /* PNG_READ_cHRM_SUPPORTED */ 1024 #endif /* PNG_READ_cHRM_SUPPORTED */
995 1025
996 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); 1026 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
997 } 1027 }
998 #endif /* PNG_READ_sRGB_SUPPORTED */ 1028 #endif /* PNG_READ_sRGB_SUPPORTED */
999 1029
1000 #if defined(PNG_READ_iCCP_SUPPORTED) 1030 #ifdef PNG_READ_iCCP_SUPPORTED
1001 void /* PRIVATE */ 1031 void /* PRIVATE */
1002 png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1032 png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1003 /* Note: this does not properly handle chunks that are > 64K under DOS */ 1033 /* Note: this does not properly handle chunks that are > 64K under DOS */
1004 { 1034 {
1005 png_byte compression_type; 1035 png_byte compression_type;
1006 png_bytep pC; 1036 png_bytep pC;
1007 png_charp profile; 1037 png_charp profile;
1008 png_uint_32 skip = 0; 1038 png_uint_32 skip = 0;
1009 png_uint_32 profile_size, profile_length; 1039 png_uint_32 profile_size, profile_length;
1010 png_size_t slength, prefix_length, data_length; 1040 png_size_t slength, prefix_length, data_length;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 return; 1140 return;
1111 } 1141 }
1112 1142
1113 png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, 1143 png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata,
1114 compression_type, png_ptr->chunkdata + prefix_length, profile_length); 1144 compression_type, png_ptr->chunkdata + prefix_length, profile_length);
1115 png_free(png_ptr, png_ptr->chunkdata); 1145 png_free(png_ptr, png_ptr->chunkdata);
1116 png_ptr->chunkdata = NULL; 1146 png_ptr->chunkdata = NULL;
1117 } 1147 }
1118 #endif /* PNG_READ_iCCP_SUPPORTED */ 1148 #endif /* PNG_READ_iCCP_SUPPORTED */
1119 1149
1120 #if defined(PNG_READ_sPLT_SUPPORTED) 1150 #ifdef PNG_READ_sPLT_SUPPORTED
1121 void /* PRIVATE */ 1151 void /* PRIVATE */
1122 png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1152 png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1123 /* Note: this does not properly handle chunks that are > 64K under DOS */ 1153 /* Note: this does not properly handle chunks that are > 64K under DOS */
1124 { 1154 {
1125 png_bytep entry_start; 1155 png_bytep entry_start;
1126 png_sPLT_t new_palette; 1156 png_sPLT_t new_palette;
1127 #ifdef PNG_NO_POINTER_INDEXING 1157 #ifdef PNG_POINTER_INDEXING_SUPPORTED
1128 png_sPLT_entryp pp; 1158 png_sPLT_entryp pp;
1129 #endif 1159 #endif
1130 int data_length, entry_size, i; 1160 int data_length, entry_size, i;
1131 png_uint_32 skip = 0; 1161 png_uint_32 skip = 0;
1132 png_size_t slength; 1162 png_size_t slength;
1133 1163
1134 png_debug(1, "in png_handle_sPLT"); 1164 png_debug(1, "in png_handle_sPLT");
1135 1165
1166 #ifdef PNG_USER_LIMITS_SUPPORTED
1167
1168 if (png_ptr->user_chunk_cache_max != 0)
1169 {
1170 if (png_ptr->user_chunk_cache_max == 1)
1171 {
1172 png_crc_finish(png_ptr, length);
1173 return;
1174 }
1175 if (--png_ptr->user_chunk_cache_max == 1)
1176 {
1177 png_warning(png_ptr, "No space in chunk cache for sPLT");
1178 png_crc_finish(png_ptr, length);
1179 return;
1180 }
1181 }
1182 #endif
1136 1183
1137 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1184 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1138 png_error(png_ptr, "Missing IHDR before sPLT"); 1185 png_error(png_ptr, "Missing IHDR before sPLT");
1139 else if (png_ptr->mode & PNG_HAVE_IDAT) 1186 else if (png_ptr->mode & PNG_HAVE_IDAT)
1140 { 1187 {
1141 png_warning(png_ptr, "Invalid sPLT after IDAT"); 1188 png_warning(png_ptr, "Invalid sPLT after IDAT");
1142 png_crc_finish(png_ptr, length); 1189 png_crc_finish(png_ptr, length);
1143 return; 1190 return;
1144 } 1191 }
1145 1192
(...skipping 13 matching lines...) Expand all
1159 1206
1160 if (png_crc_finish(png_ptr, skip)) 1207 if (png_crc_finish(png_ptr, skip))
1161 { 1208 {
1162 png_free(png_ptr, png_ptr->chunkdata); 1209 png_free(png_ptr, png_ptr->chunkdata);
1163 png_ptr->chunkdata = NULL; 1210 png_ptr->chunkdata = NULL;
1164 return; 1211 return;
1165 } 1212 }
1166 1213
1167 png_ptr->chunkdata[slength] = 0x00; 1214 png_ptr->chunkdata[slength] = 0x00;
1168 1215
1169 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; entry_start++ ) 1216 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start;
1217 entry_start++)
1170 /* Empty loop to find end of name */ ; 1218 /* Empty loop to find end of name */ ;
1171 ++entry_start; 1219 ++entry_start;
1172 1220
1173 /* A sample depth should follow the separator, and we should be on it */ 1221 /* A sample depth should follow the separator, and we should be on it */
1174 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) 1222 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2)
1175 { 1223 {
1176 png_free(png_ptr, png_ptr->chunkdata); 1224 png_free(png_ptr, png_ptr->chunkdata);
1177 png_ptr->chunkdata = NULL; 1225 png_ptr->chunkdata = NULL;
1178 png_warning(png_ptr, "malformed sPLT chunk"); 1226 png_warning(png_ptr, "malformed sPLT chunk");
1179 return; 1227 return;
(...skipping 20 matching lines...) Expand all
1200 return; 1248 return;
1201 } 1249 }
1202 new_palette.entries = (png_sPLT_entryp)png_malloc_warn( 1250 new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
1203 png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); 1251 png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
1204 if (new_palette.entries == NULL) 1252 if (new_palette.entries == NULL)
1205 { 1253 {
1206 png_warning(png_ptr, "sPLT chunk requires too much memory"); 1254 png_warning(png_ptr, "sPLT chunk requires too much memory");
1207 return; 1255 return;
1208 } 1256 }
1209 1257
1210 #ifndef PNG_NO_POINTER_INDEXING 1258 #ifdef PNG_POINTER_INDEXING_SUPPORTED
1211 for (i = 0; i < new_palette.nentries; i++) 1259 for (i = 0; i < new_palette.nentries; i++)
1212 { 1260 {
1213 png_sPLT_entryp pp = new_palette.entries + i; 1261 pp = new_palette.entries + i;
1214 1262
1215 if (new_palette.depth == 8) 1263 if (new_palette.depth == 8)
1216 { 1264 {
1217 pp->red = *entry_start++; 1265 pp->red = *entry_start++;
1218 pp->green = *entry_start++; 1266 pp->green = *entry_start++;
1219 pp->blue = *entry_start++; 1267 pp->blue = *entry_start++;
1220 pp->alpha = *entry_start++; 1268 pp->alpha = *entry_start++;
1221 } 1269 }
1222 else 1270 else
1223 { 1271 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 new_palette.name = png_ptr->chunkdata; 1303 new_palette.name = png_ptr->chunkdata;
1256 1304
1257 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); 1305 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1258 1306
1259 png_free(png_ptr, png_ptr->chunkdata); 1307 png_free(png_ptr, png_ptr->chunkdata);
1260 png_ptr->chunkdata = NULL; 1308 png_ptr->chunkdata = NULL;
1261 png_free(png_ptr, new_palette.entries); 1309 png_free(png_ptr, new_palette.entries);
1262 } 1310 }
1263 #endif /* PNG_READ_sPLT_SUPPORTED */ 1311 #endif /* PNG_READ_sPLT_SUPPORTED */
1264 1312
1265 #if defined(PNG_READ_tRNS_SUPPORTED) 1313 #ifdef PNG_READ_tRNS_SUPPORTED
1266 void /* PRIVATE */ 1314 void /* PRIVATE */
1267 png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1315 png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1268 { 1316 {
1269 png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; 1317 png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
1270 1318
1271 png_debug(1, "in png_handle_tRNS"); 1319 png_debug(1, "in png_handle_tRNS");
1272 1320
1273 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1321 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1274 png_error(png_ptr, "Missing IHDR before tRNS"); 1322 png_error(png_ptr, "Missing IHDR before tRNS");
1275 else if (png_ptr->mode & PNG_HAVE_IDAT) 1323 else if (png_ptr->mode & PNG_HAVE_IDAT)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 { 1398 {
1351 png_ptr->num_trans = 0; 1399 png_ptr->num_trans = 0;
1352 return; 1400 return;
1353 } 1401 }
1354 1402
1355 png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, 1403 png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1356 &(png_ptr->trans_values)); 1404 &(png_ptr->trans_values));
1357 } 1405 }
1358 #endif 1406 #endif
1359 1407
1360 #if defined(PNG_READ_bKGD_SUPPORTED) 1408 #ifdef PNG_READ_bKGD_SUPPORTED
1361 void /* PRIVATE */ 1409 void /* PRIVATE */
1362 png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1410 png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1363 { 1411 {
1364 png_size_t truelen; 1412 png_size_t truelen;
1365 png_byte buf[6]; 1413 png_byte buf[6];
1366 1414
1367 png_debug(1, "in png_handle_bKGD"); 1415 png_debug(1, "in png_handle_bKGD");
1368 1416
1369 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1417 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1370 png_error(png_ptr, "Missing IHDR before bKGD"); 1418 png_error(png_ptr, "Missing IHDR before bKGD");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 { 1487 {
1440 png_ptr->background.red = png_get_uint_16(buf); 1488 png_ptr->background.red = png_get_uint_16(buf);
1441 png_ptr->background.green = png_get_uint_16(buf + 2); 1489 png_ptr->background.green = png_get_uint_16(buf + 2);
1442 png_ptr->background.blue = png_get_uint_16(buf + 4); 1490 png_ptr->background.blue = png_get_uint_16(buf + 4);
1443 } 1491 }
1444 1492
1445 png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background)); 1493 png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
1446 } 1494 }
1447 #endif 1495 #endif
1448 1496
1449 #if defined(PNG_READ_hIST_SUPPORTED) 1497 #ifdef PNG_READ_hIST_SUPPORTED
1450 void /* PRIVATE */ 1498 void /* PRIVATE */
1451 png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1499 png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1452 { 1500 {
1453 unsigned int num, i; 1501 unsigned int num, i;
1454 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; 1502 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
1455 1503
1456 png_debug(1, "in png_handle_hIST"); 1504 png_debug(1, "in png_handle_hIST");
1457 1505
1458 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1506 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1459 png_error(png_ptr, "Missing IHDR before hIST"); 1507 png_error(png_ptr, "Missing IHDR before hIST");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 readbuf[i] = png_get_uint_16(buf); 1541 readbuf[i] = png_get_uint_16(buf);
1494 } 1542 }
1495 1543
1496 if (png_crc_finish(png_ptr, 0)) 1544 if (png_crc_finish(png_ptr, 0))
1497 return; 1545 return;
1498 1546
1499 png_set_hIST(png_ptr, info_ptr, readbuf); 1547 png_set_hIST(png_ptr, info_ptr, readbuf);
1500 } 1548 }
1501 #endif 1549 #endif
1502 1550
1503 #if defined(PNG_READ_pHYs_SUPPORTED) 1551 #ifdef PNG_READ_pHYs_SUPPORTED
1504 void /* PRIVATE */ 1552 void /* PRIVATE */
1505 png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1553 png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1506 { 1554 {
1507 png_byte buf[9]; 1555 png_byte buf[9];
1508 png_uint_32 res_x, res_y; 1556 png_uint_32 res_x, res_y;
1509 int unit_type; 1557 int unit_type;
1510 1558
1511 png_debug(1, "in png_handle_pHYs"); 1559 png_debug(1, "in png_handle_pHYs");
1512 1560
1513 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1561 if (!(png_ptr->mode & PNG_HAVE_IHDR))
(...skipping 22 matching lines...) Expand all
1536 if (png_crc_finish(png_ptr, 0)) 1584 if (png_crc_finish(png_ptr, 0))
1537 return; 1585 return;
1538 1586
1539 res_x = png_get_uint_32(buf); 1587 res_x = png_get_uint_32(buf);
1540 res_y = png_get_uint_32(buf + 4); 1588 res_y = png_get_uint_32(buf + 4);
1541 unit_type = buf[8]; 1589 unit_type = buf[8];
1542 png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); 1590 png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
1543 } 1591 }
1544 #endif 1592 #endif
1545 1593
1546 #if defined(PNG_READ_oFFs_SUPPORTED) 1594 #ifdef PNG_READ_oFFs_SUPPORTED
1547 void /* PRIVATE */ 1595 void /* PRIVATE */
1548 png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1596 png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1549 { 1597 {
1550 png_byte buf[9]; 1598 png_byte buf[9];
1551 png_int_32 offset_x, offset_y; 1599 png_int_32 offset_x, offset_y;
1552 int unit_type; 1600 int unit_type;
1553 1601
1554 png_debug(1, "in png_handle_oFFs"); 1602 png_debug(1, "in png_handle_oFFs");
1555 1603
1556 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1604 if (!(png_ptr->mode & PNG_HAVE_IHDR))
(...skipping 22 matching lines...) Expand all
1579 if (png_crc_finish(png_ptr, 0)) 1627 if (png_crc_finish(png_ptr, 0))
1580 return; 1628 return;
1581 1629
1582 offset_x = png_get_int_32(buf); 1630 offset_x = png_get_int_32(buf);
1583 offset_y = png_get_int_32(buf + 4); 1631 offset_y = png_get_int_32(buf + 4);
1584 unit_type = buf[8]; 1632 unit_type = buf[8];
1585 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); 1633 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
1586 } 1634 }
1587 #endif 1635 #endif
1588 1636
1589 #if defined(PNG_READ_pCAL_SUPPORTED) 1637 #ifdef PNG_READ_pCAL_SUPPORTED
1590 /* Read the pCAL chunk (described in the PNG Extensions document) */ 1638 /* Read the pCAL chunk (described in the PNG Extensions document) */
1591 void /* PRIVATE */ 1639 void /* PRIVATE */
1592 png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1640 png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1593 { 1641 {
1594 png_int_32 X0, X1; 1642 png_int_32 X0, X1;
1595 png_byte type, nparams; 1643 png_byte type, nparams;
1596 png_charp buf, units, endptr; 1644 png_charp buf, units, endptr;
1597 png_charpp params; 1645 png_charpp params;
1598 png_size_t slength; 1646 png_size_t slength;
1599 int i; 1647 int i;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 1761
1714 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, 1762 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
1715 units, params); 1763 units, params);
1716 1764
1717 png_free(png_ptr, png_ptr->chunkdata); 1765 png_free(png_ptr, png_ptr->chunkdata);
1718 png_ptr->chunkdata = NULL; 1766 png_ptr->chunkdata = NULL;
1719 png_free(png_ptr, params); 1767 png_free(png_ptr, params);
1720 } 1768 }
1721 #endif 1769 #endif
1722 1770
1723 #if defined(PNG_READ_sCAL_SUPPORTED) 1771 #ifdef PNG_READ_sCAL_SUPPORTED
1724 /* Read the sCAL chunk */ 1772 /* Read the sCAL chunk */
1725 void /* PRIVATE */ 1773 void /* PRIVATE */
1726 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1774 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1727 { 1775 {
1728 png_charp ep; 1776 png_charp ep;
1729 #ifdef PNG_FLOATING_POINT_SUPPORTED 1777 #ifdef PNG_FLOATING_POINT_SUPPORTED
1730 double width, height; 1778 double width, height;
1731 png_charp vp; 1779 png_charp vp;
1732 #else 1780 #else
1733 #ifdef PNG_FIXED_POINT_SUPPORTED 1781 #ifdef PNG_FIXED_POINT_SUPPORTED
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 1904
1857 png_free(png_ptr, png_ptr->chunkdata); 1905 png_free(png_ptr, png_ptr->chunkdata);
1858 png_ptr->chunkdata = NULL; 1906 png_ptr->chunkdata = NULL;
1859 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1907 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
1860 png_free(png_ptr, swidth); 1908 png_free(png_ptr, swidth);
1861 png_free(png_ptr, sheight); 1909 png_free(png_ptr, sheight);
1862 #endif 1910 #endif
1863 } 1911 }
1864 #endif 1912 #endif
1865 1913
1866 #if defined(PNG_READ_tIME_SUPPORTED) 1914 #ifdef PNG_READ_tIME_SUPPORTED
1867 void /* PRIVATE */ 1915 void /* PRIVATE */
1868 png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1916 png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1869 { 1917 {
1870 png_byte buf[7]; 1918 png_byte buf[7];
1871 png_time mod_time; 1919 png_time mod_time;
1872 1920
1873 png_debug(1, "in png_handle_tIME"); 1921 png_debug(1, "in png_handle_tIME");
1874 1922
1875 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1923 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1876 png_error(png_ptr, "Out of place tIME chunk"); 1924 png_error(png_ptr, "Out of place tIME chunk");
(...skipping 22 matching lines...) Expand all
1899 mod_time.minute = buf[5]; 1947 mod_time.minute = buf[5];
1900 mod_time.hour = buf[4]; 1948 mod_time.hour = buf[4];
1901 mod_time.day = buf[3]; 1949 mod_time.day = buf[3];
1902 mod_time.month = buf[2]; 1950 mod_time.month = buf[2];
1903 mod_time.year = png_get_uint_16(buf); 1951 mod_time.year = png_get_uint_16(buf);
1904 1952
1905 png_set_tIME(png_ptr, info_ptr, &mod_time); 1953 png_set_tIME(png_ptr, info_ptr, &mod_time);
1906 } 1954 }
1907 #endif 1955 #endif
1908 1956
1909 #if defined(PNG_READ_tEXt_SUPPORTED) 1957 #ifdef PNG_READ_tEXt_SUPPORTED
1910 /* Note: this does not properly handle chunks that are > 64K under DOS */ 1958 /* Note: this does not properly handle chunks that are > 64K under DOS */
1911 void /* PRIVATE */ 1959 void /* PRIVATE */
1912 png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1960 png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1913 { 1961 {
1914 png_textp text_ptr; 1962 png_textp text_ptr;
1915 png_charp key; 1963 png_charp key;
1916 png_charp text; 1964 png_charp text;
1917 png_uint_32 skip = 0; 1965 png_uint_32 skip = 0;
1918 png_size_t slength; 1966 png_size_t slength;
1919 int ret; 1967 int ret;
1920 1968
1921 png_debug(1, "in png_handle_tEXt"); 1969 png_debug(1, "in png_handle_tEXt");
1922 1970
1971 #ifdef PNG_USER_LIMITS_SUPPORTED
1972 if (png_ptr->user_chunk_cache_max != 0)
1973 {
1974 if (png_ptr->user_chunk_cache_max == 1)
1975 {
1976 png_crc_finish(png_ptr, length);
1977 return;
1978 }
1979 if (--png_ptr->user_chunk_cache_max == 1)
1980 {
1981 png_warning(png_ptr, "No space in chunk cache for tEXt");
1982 png_crc_finish(png_ptr, length);
1983 return;
1984 }
1985 }
1986 #endif
1923 1987
1924 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1988 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1925 png_error(png_ptr, "Missing IHDR before tEXt"); 1989 png_error(png_ptr, "Missing IHDR before tEXt");
1926 1990
1927 if (png_ptr->mode & PNG_HAVE_IDAT) 1991 if (png_ptr->mode & PNG_HAVE_IDAT)
1928 png_ptr->mode |= PNG_AFTER_IDAT; 1992 png_ptr->mode |= PNG_AFTER_IDAT;
1929 1993
1930 #ifdef PNG_MAX_MALLOC_64K 1994 #ifdef PNG_MAX_MALLOC_64K
1931 if (length > (png_uint_32)65535L) 1995 if (length > (png_uint_32)65535L)
1932 { 1996 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 2050 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1987 2051
1988 png_free(png_ptr, png_ptr->chunkdata); 2052 png_free(png_ptr, png_ptr->chunkdata);
1989 png_ptr->chunkdata = NULL; 2053 png_ptr->chunkdata = NULL;
1990 png_free(png_ptr, text_ptr); 2054 png_free(png_ptr, text_ptr);
1991 if (ret) 2055 if (ret)
1992 png_warning(png_ptr, "Insufficient memory to process text chunk."); 2056 png_warning(png_ptr, "Insufficient memory to process text chunk.");
1993 } 2057 }
1994 #endif 2058 #endif
1995 2059
1996 #if defined(PNG_READ_zTXt_SUPPORTED) 2060 #ifdef PNG_READ_zTXt_SUPPORTED
1997 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 2061 /* Note: this does not correctly handle chunks that are > 64K under DOS */
1998 void /* PRIVATE */ 2062 void /* PRIVATE */
1999 png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 2063 png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2000 { 2064 {
2001 png_textp text_ptr; 2065 png_textp text_ptr;
2002 png_charp text; 2066 png_charp text;
2003 int comp_type; 2067 int comp_type;
2004 int ret; 2068 int ret;
2005 png_size_t slength, prefix_len, data_len; 2069 png_size_t slength, prefix_len, data_len;
2006 2070
2007 png_debug(1, "in png_handle_zTXt"); 2071 png_debug(1, "in png_handle_zTXt");
2008 2072
2073 #ifdef PNG_USER_LIMITS_SUPPORTED
2074 if (png_ptr->user_chunk_cache_max != 0)
2075 {
2076 if (png_ptr->user_chunk_cache_max == 1)
2077 {
2078 png_crc_finish(png_ptr, length);
2079 return;
2080 }
2081 if (--png_ptr->user_chunk_cache_max == 1)
2082 {
2083 png_warning(png_ptr, "No space in chunk cache for zTXt");
2084 png_crc_finish(png_ptr, length);
2085 return;
2086 }
2087 }
2088 #endif
2009 2089
2010 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 2090 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2011 png_error(png_ptr, "Missing IHDR before zTXt"); 2091 png_error(png_ptr, "Missing IHDR before zTXt");
2012 2092
2013 if (png_ptr->mode & PNG_HAVE_IDAT) 2093 if (png_ptr->mode & PNG_HAVE_IDAT)
2014 png_ptr->mode |= PNG_AFTER_IDAT; 2094 png_ptr->mode |= PNG_AFTER_IDAT;
2015 2095
2016 #ifdef PNG_MAX_MALLOC_64K 2096 #ifdef PNG_MAX_MALLOC_64K
2017 /* We will no doubt have problems with chunks even half this size, but 2097 /* We will no doubt have problems with chunks even half this size, but
2018 there is no hard and fast rule to tell us where to stop. */ 2098 there is no hard and fast rule to tell us where to stop. */
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 2170 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
2091 2171
2092 png_free(png_ptr, text_ptr); 2172 png_free(png_ptr, text_ptr);
2093 png_free(png_ptr, png_ptr->chunkdata); 2173 png_free(png_ptr, png_ptr->chunkdata);
2094 png_ptr->chunkdata = NULL; 2174 png_ptr->chunkdata = NULL;
2095 if (ret) 2175 if (ret)
2096 png_error(png_ptr, "Insufficient memory to store zTXt chunk."); 2176 png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
2097 } 2177 }
2098 #endif 2178 #endif
2099 2179
2100 #if defined(PNG_READ_iTXt_SUPPORTED) 2180 #ifdef PNG_READ_iTXt_SUPPORTED
2101 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 2181 /* Note: this does not correctly handle chunks that are > 64K under DOS */
2102 void /* PRIVATE */ 2182 void /* PRIVATE */
2103 png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 2183 png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2104 { 2184 {
2105 png_textp text_ptr; 2185 png_textp text_ptr;
2106 png_charp key, lang, text, lang_key; 2186 png_charp key, lang, text, lang_key;
2107 int comp_flag; 2187 int comp_flag;
2108 int comp_type = 0; 2188 int comp_type = 0;
2109 int ret; 2189 int ret;
2110 png_size_t slength, prefix_len, data_len; 2190 png_size_t slength, prefix_len, data_len;
2111 2191
2112 png_debug(1, "in png_handle_iTXt"); 2192 png_debug(1, "in png_handle_iTXt");
2113 2193
2194 #ifdef PNG_USER_LIMITS_SUPPORTED
2195 if (png_ptr->user_chunk_cache_max != 0)
2196 {
2197 if (png_ptr->user_chunk_cache_max == 1)
2198 {
2199 png_crc_finish(png_ptr, length);
2200 return;
2201 }
2202 if (--png_ptr->user_chunk_cache_max == 1)
2203 {
2204 png_warning(png_ptr, "No space in chunk cache for iTXt");
2205 png_crc_finish(png_ptr, length);
2206 return;
2207 }
2208 }
2209 #endif
2114 2210
2115 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 2211 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2116 png_error(png_ptr, "Missing IHDR before iTXt"); 2212 png_error(png_ptr, "Missing IHDR before iTXt");
2117 2213
2118 if (png_ptr->mode & PNG_HAVE_IDAT) 2214 if (png_ptr->mode & PNG_HAVE_IDAT)
2119 png_ptr->mode |= PNG_AFTER_IDAT; 2215 png_ptr->mode |= PNG_AFTER_IDAT;
2120 2216
2121 #ifdef PNG_MAX_MALLOC_64K 2217 #ifdef PNG_MAX_MALLOC_64K
2122 /* We will no doubt have problems with chunks even half this size, but 2218 /* We will no doubt have problems with chunks even half this size, but
2123 there is no hard and fast rule to tell us where to stop. */ 2219 there is no hard and fast rule to tell us where to stop. */
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 chunk name, CRC, or a critical chunk), the chunk is silently ignored 2328 chunk name, CRC, or a critical chunk), the chunk is silently ignored
2233 -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which 2329 -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
2234 case it will be saved away to be written out later. */ 2330 case it will be saved away to be written out later. */
2235 void /* PRIVATE */ 2331 void /* PRIVATE */
2236 png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 2332 png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2237 { 2333 {
2238 png_uint_32 skip = 0; 2334 png_uint_32 skip = 0;
2239 2335
2240 png_debug(1, "in png_handle_unknown"); 2336 png_debug(1, "in png_handle_unknown");
2241 2337
2338 #ifdef PNG_USER_LIMITS_SUPPORTED
2339 if (png_ptr->user_chunk_cache_max != 0)
2340 {
2341 if (png_ptr->user_chunk_cache_max == 1)
2342 {
2343 png_crc_finish(png_ptr, length);
2344 return;
2345 }
2346 if (--png_ptr->user_chunk_cache_max == 1)
2347 {
2348 png_warning(png_ptr, "No space in chunk cache for unknown chunk");
2349 png_crc_finish(png_ptr, length);
2350 return;
2351 }
2352 }
2353 #endif
2242 2354
2243 if (png_ptr->mode & PNG_HAVE_IDAT) 2355 if (png_ptr->mode & PNG_HAVE_IDAT)
2244 { 2356 {
2245 #ifdef PNG_USE_LOCAL_ARRAYS 2357 #ifdef PNG_USE_LOCAL_ARRAYS
2246 PNG_CONST PNG_IDAT; 2358 PNG_CONST PNG_IDAT;
2247 #endif 2359 #endif
2248 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */ 2360 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */
2249 png_ptr->mode |= PNG_AFTER_IDAT; 2361 png_ptr->mode |= PNG_AFTER_IDAT;
2250 } 2362 }
2251 2363
2252 if (!(png_ptr->chunk_name[0] & 0x20)) 2364 if (!(png_ptr->chunk_name[0] & 0x20))
2253 { 2365 {
2254 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) 2366 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2255 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2367 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
2256 PNG_HANDLE_CHUNK_ALWAYS 2368 PNG_HANDLE_CHUNK_ALWAYS
2257 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2369 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2258 && png_ptr->read_user_chunk_fn == NULL 2370 && png_ptr->read_user_chunk_fn == NULL
2259 #endif 2371 #endif
2260 ) 2372 )
2261 #endif 2373 #endif
2262 png_chunk_error(png_ptr, "unknown critical chunk"); 2374 png_chunk_error(png_ptr, "unknown critical chunk");
2263 } 2375 }
2264 2376
2265 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) 2377 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2266 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) || 2378 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
2267 (png_ptr->read_user_chunk_fn != NULL)) 2379 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2380 || (png_ptr->read_user_chunk_fn != NULL)
2381 #endif
2382 )
2268 { 2383 {
2269 #ifdef PNG_MAX_MALLOC_64K 2384 #ifdef PNG_MAX_MALLOC_64K
2270 if (length > (png_uint_32)65535L) 2385 if (length > (png_uint_32)65535L)
2271 { 2386 {
2272 png_warning(png_ptr, "unknown chunk too large to fit in memory"); 2387 png_warning(png_ptr, "unknown chunk too large to fit in memory");
2273 skip = length - (png_uint_32)65535L; 2388 skip = length - (png_uint_32)65535L;
2274 length = (png_uint_32)65535L; 2389 length = (png_uint_32)65535L;
2275 } 2390 }
2276 #endif 2391 #endif
2277 png_memcpy((png_charp)png_ptr->unknown_chunk.name, 2392 png_memcpy((png_charp)png_ptr->unknown_chunk.name,
2278 (png_charp)png_ptr->chunk_name, 2393 (png_charp)png_ptr->chunk_name,
2279 png_sizeof(png_ptr->unknown_chunk.name)); 2394 png_sizeof(png_ptr->unknown_chunk.name));
2280 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0'; 2395 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]
2396 = '\0';
2281 png_ptr->unknown_chunk.size = (png_size_t)length; 2397 png_ptr->unknown_chunk.size = (png_size_t)length;
2282 if (length == 0) 2398 if (length == 0)
2283 png_ptr->unknown_chunk.data = NULL; 2399 png_ptr->unknown_chunk.data = NULL;
2284 else 2400 else
2285 { 2401 {
2286 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); 2402 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
2287 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); 2403 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
2288 } 2404 }
2289 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2405 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2290 if (png_ptr->read_user_chunk_fn != NULL) 2406 if (png_ptr->read_user_chunk_fn != NULL)
2291 { 2407 {
2292 /* Callback to user unknown chunk handler */ 2408 /* Callback to user unknown chunk handler */
2293 int ret; 2409 int ret;
2294 ret = (*(png_ptr->read_user_chunk_fn)) 2410 ret = (*(png_ptr->read_user_chunk_fn))
2295 (png_ptr, &png_ptr->unknown_chunk); 2411 (png_ptr, &png_ptr->unknown_chunk);
2296 if (ret < 0) 2412 if (ret < 0)
2297 png_chunk_error(png_ptr, "error in user chunk"); 2413 png_chunk_error(png_ptr, "error in user chunk");
2298 if (ret == 0) 2414 if (ret == 0)
2299 { 2415 {
2300 if (!(png_ptr->chunk_name[0] & 0x20)) 2416 if (!(png_ptr->chunk_name[0] & 0x20))
2417 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2301 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2418 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
2302 PNG_HANDLE_CHUNK_ALWAYS) 2419 PNG_HANDLE_CHUNK_ALWAYS)
2420 #endif
2303 png_chunk_error(png_ptr, "unknown critical chunk"); 2421 png_chunk_error(png_ptr, "unknown critical chunk");
2304 png_set_unknown_chunks(png_ptr, info_ptr, 2422 png_set_unknown_chunks(png_ptr, info_ptr,
2305 &png_ptr->unknown_chunk, 1); 2423 &png_ptr->unknown_chunk, 1);
2306 } 2424 }
2307 } 2425 }
2308 else 2426 else
2309 #endif 2427 #endif
2310 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); 2428 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
2311 png_free(png_ptr, png_ptr->unknown_chunk.data); 2429 png_free(png_ptr, png_ptr->unknown_chunk.data);
2312 png_ptr->unknown_chunk.data = NULL; 2430 png_ptr->unknown_chunk.data = NULL;
2313 } 2431 }
2314 else 2432 else
2315 #endif 2433 #endif
2316 skip = length; 2434 skip = length;
2317 2435
2318 png_crc_finish(png_ptr, skip); 2436 png_crc_finish(png_ptr, skip);
2319 2437
2320 #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2438 #ifndef PNG_READ_USER_CHUNKS_SUPPORTED
2321 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ 2439 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
2322 #endif 2440 #endif
2323 } 2441 }
2324 2442
2325 /* This function is called to verify that a chunk name is valid. 2443 /* This function is called to verify that a chunk name is valid.
2326 This function can't have the "critical chunk check" incorporated 2444 This function can't have the "critical chunk check" incorporated
2327 into it, since in the future we will need to be able to call user 2445 into it, since in the future we will need to be able to call user
2328 functions to handle unknown critical chunks after we check that 2446 functions to handle unknown critical chunks after we check that
2329 the chunk name itself is valid. */ 2447 the chunk name itself is valid. */
2330 2448
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 case 1: 2486 case 1:
2369 { 2487 {
2370 png_bytep sp = png_ptr->row_buf + 1; 2488 png_bytep sp = png_ptr->row_buf + 1;
2371 png_bytep dp = row; 2489 png_bytep dp = row;
2372 int s_inc, s_start, s_end; 2490 int s_inc, s_start, s_end;
2373 int m = 0x80; 2491 int m = 0x80;
2374 int shift; 2492 int shift;
2375 png_uint_32 i; 2493 png_uint_32 i;
2376 png_uint_32 row_width = png_ptr->width; 2494 png_uint_32 row_width = png_ptr->width;
2377 2495
2378 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2496 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2379 if (png_ptr->transformations & PNG_PACKSWAP) 2497 if (png_ptr->transformations & PNG_PACKSWAP)
2380 { 2498 {
2381 s_start = 0; 2499 s_start = 0;
2382 s_end = 7; 2500 s_end = 7;
2383 s_inc = 1; 2501 s_inc = 1;
2384 } 2502 }
2385 else 2503 else
2386 #endif 2504 #endif
2387 { 2505 {
2388 s_start = 7; 2506 s_start = 7;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 { 2541 {
2424 png_bytep sp = png_ptr->row_buf + 1; 2542 png_bytep sp = png_ptr->row_buf + 1;
2425 png_bytep dp = row; 2543 png_bytep dp = row;
2426 int s_start, s_end, s_inc; 2544 int s_start, s_end, s_inc;
2427 int m = 0x80; 2545 int m = 0x80;
2428 int shift; 2546 int shift;
2429 png_uint_32 i; 2547 png_uint_32 i;
2430 png_uint_32 row_width = png_ptr->width; 2548 png_uint_32 row_width = png_ptr->width;
2431 int value; 2549 int value;
2432 2550
2433 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2551 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2434 if (png_ptr->transformations & PNG_PACKSWAP) 2552 if (png_ptr->transformations & PNG_PACKSWAP)
2435 { 2553 {
2436 s_start = 0; 2554 s_start = 0;
2437 s_end = 6; 2555 s_end = 6;
2438 s_inc = 2; 2556 s_inc = 2;
2439 } 2557 }
2440 else 2558 else
2441 #endif 2559 #endif
2442 { 2560 {
2443 s_start = 6; 2561 s_start = 6;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 { 2593 {
2476 png_bytep sp = png_ptr->row_buf + 1; 2594 png_bytep sp = png_ptr->row_buf + 1;
2477 png_bytep dp = row; 2595 png_bytep dp = row;
2478 int s_start, s_end, s_inc; 2596 int s_start, s_end, s_inc;
2479 int m = 0x80; 2597 int m = 0x80;
2480 int shift; 2598 int shift;
2481 png_uint_32 i; 2599 png_uint_32 i;
2482 png_uint_32 row_width = png_ptr->width; 2600 png_uint_32 row_width = png_ptr->width;
2483 int value; 2601 int value;
2484 2602
2485 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2603 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2486 if (png_ptr->transformations & PNG_PACKSWAP) 2604 if (png_ptr->transformations & PNG_PACKSWAP)
2487 { 2605 {
2488 s_start = 0; 2606 s_start = 0;
2489 s_end = 4; 2607 s_end = 4;
2490 s_inc = 4; 2608 s_inc = 4;
2491 } 2609 }
2492 else 2610 else
2493 #endif 2611 #endif
2494 { 2612 {
2495 s_start = 4; 2613 s_start = 4;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, 2676 void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
2559 png_uint_32 transformations) 2677 png_uint_32 transformations)
2560 */ 2678 */
2561 void /* PRIVATE */ 2679 void /* PRIVATE */
2562 png_do_read_interlace(png_structp png_ptr) 2680 png_do_read_interlace(png_structp png_ptr)
2563 { 2681 {
2564 png_row_infop row_info = &(png_ptr->row_info); 2682 png_row_infop row_info = &(png_ptr->row_info);
2565 png_bytep row = png_ptr->row_buf + 1; 2683 png_bytep row = png_ptr->row_buf + 1;
2566 int pass = png_ptr->pass; 2684 int pass = png_ptr->pass;
2567 png_uint_32 transformations = png_ptr->transformations; 2685 png_uint_32 transformations = png_ptr->transformations;
2568 #ifdef PNG_USE_LOCAL_ARRAYS
2569 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2686 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2570 /* Offset to next interlace block */ 2687 /* Offset to next interlace block */
2571 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2688 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2572 #endif
2573 2689
2574 png_debug(1, "in png_do_read_interlace"); 2690 png_debug(1, "in png_do_read_interlace");
2575 if (row != NULL && row_info != NULL) 2691 if (row != NULL && row_info != NULL)
2576 { 2692 {
2577 png_uint_32 final_width; 2693 png_uint_32 final_width;
2578 2694
2579 final_width = row_info->width * png_pass_inc[pass]; 2695 final_width = row_info->width * png_pass_inc[pass];
2580 2696
2581 switch (row_info->pixel_depth) 2697 switch (row_info->pixel_depth)
2582 { 2698 {
2583 case 1: 2699 case 1:
2584 { 2700 {
2585 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); 2701 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
2586 png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); 2702 png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
2587 int sshift, dshift; 2703 int sshift, dshift;
2588 int s_start, s_end, s_inc; 2704 int s_start, s_end, s_inc;
2589 int jstop = png_pass_inc[pass]; 2705 int jstop = png_pass_inc[pass];
2590 png_byte v; 2706 png_byte v;
2591 png_uint_32 i; 2707 png_uint_32 i;
2592 int j; 2708 int j;
2593 2709
2594 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2710 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2595 if (transformations & PNG_PACKSWAP) 2711 if (transformations & PNG_PACKSWAP)
2596 { 2712 {
2597 sshift = (int)((row_info->width + 7) & 0x07); 2713 sshift = (int)((row_info->width + 7) & 0x07);
2598 dshift = (int)((final_width + 7) & 0x07); 2714 dshift = (int)((final_width + 7) & 0x07);
2599 s_start = 7; 2715 s_start = 7;
2600 s_end = 0; 2716 s_end = 0;
2601 s_inc = -1; 2717 s_inc = -1;
2602 } 2718 }
2603 else 2719 else
2604 #endif 2720 #endif
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 } 2753 }
2638 case 2: 2754 case 2:
2639 { 2755 {
2640 png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); 2756 png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
2641 png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); 2757 png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
2642 int sshift, dshift; 2758 int sshift, dshift;
2643 int s_start, s_end, s_inc; 2759 int s_start, s_end, s_inc;
2644 int jstop = png_pass_inc[pass]; 2760 int jstop = png_pass_inc[pass];
2645 png_uint_32 i; 2761 png_uint_32 i;
2646 2762
2647 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2763 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2648 if (transformations & PNG_PACKSWAP) 2764 if (transformations & PNG_PACKSWAP)
2649 { 2765 {
2650 sshift = (int)(((row_info->width + 3) & 0x03) << 1); 2766 sshift = (int)(((row_info->width + 3) & 0x03) << 1);
2651 dshift = (int)(((final_width + 3) & 0x03) << 1); 2767 dshift = (int)(((final_width + 3) & 0x03) << 1);
2652 s_start = 6; 2768 s_start = 6;
2653 s_end = 0; 2769 s_end = 0;
2654 s_inc = -2; 2770 s_inc = -2;
2655 } 2771 }
2656 else 2772 else
2657 #endif 2773 #endif
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 } 2809 }
2694 case 4: 2810 case 4:
2695 { 2811 {
2696 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); 2812 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
2697 png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); 2813 png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
2698 int sshift, dshift; 2814 int sshift, dshift;
2699 int s_start, s_end, s_inc; 2815 int s_start, s_end, s_inc;
2700 png_uint_32 i; 2816 png_uint_32 i;
2701 int jstop = png_pass_inc[pass]; 2817 int jstop = png_pass_inc[pass];
2702 2818
2703 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 2819 #ifdef PNG_READ_PACKSWAP_SUPPORTED
2704 if (transformations & PNG_PACKSWAP) 2820 if (transformations & PNG_PACKSWAP)
2705 { 2821 {
2706 sshift = (int)(((row_info->width + 1) & 0x01) << 2); 2822 sshift = (int)(((row_info->width + 1) & 0x01) << 2);
2707 dshift = (int)(((final_width + 1) & 0x01) << 2); 2823 dshift = (int)(((final_width + 1) & 0x01) << 2);
2708 s_start = 4; 2824 s_start = 4;
2709 s_end = 0; 2825 s_end = 0;
2710 s_inc = -4; 2826 s_inc = -4;
2711 } 2827 }
2712 else 2828 else
2713 #endif 2829 #endif
(...skipping 28 matching lines...) Expand all
2742 sp--; 2858 sp--;
2743 } 2859 }
2744 else 2860 else
2745 sshift += s_inc; 2861 sshift += s_inc;
2746 } 2862 }
2747 break; 2863 break;
2748 } 2864 }
2749 default: 2865 default:
2750 { 2866 {
2751 png_size_t pixel_bytes = (row_info->pixel_depth >> 3); 2867 png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
2752 png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes ; 2868 png_bytep sp = row + (png_size_t)(row_info->width - 1)
2869 * pixel_bytes;
2753 png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; 2870 png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
2754 2871
2755 int jstop = png_pass_inc[pass]; 2872 int jstop = png_pass_inc[pass];
2756 png_uint_32 i; 2873 png_uint_32 i;
2757 2874
2758 for (i = 0; i < row_info->width; i++) 2875 for (i = 0; i < row_info->width; i++)
2759 { 2876 {
2760 png_byte v[8]; 2877 png_byte v[8];
2761 int j; 2878 int j;
2762 2879
2763 png_memcpy(v, sp, pixel_bytes); 2880 png_memcpy(v, sp, pixel_bytes);
2764 for (j = 0; j < jstop; j++) 2881 for (j = 0; j < jstop; j++)
2765 { 2882 {
2766 png_memcpy(dp, v, pixel_bytes); 2883 png_memcpy(dp, v, pixel_bytes);
2767 dp -= pixel_bytes; 2884 dp -= pixel_bytes;
2768 } 2885 }
2769 sp -= pixel_bytes; 2886 sp -= pixel_bytes;
2770 } 2887 }
2771 break; 2888 break;
2772 } 2889 }
2773 } 2890 }
2774 row_info->width = final_width; 2891 row_info->width = final_width;
2775 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); 2892 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
2776 } 2893 }
2777 #if !defined(PNG_READ_PACKSWAP_SUPPORTED) 2894 #ifndef PNG_READ_PACKSWAP_SUPPORTED
2778 transformations = transformations; /* Silence compiler warning */ 2895 transformations = transformations; /* Silence compiler warning */
2779 #endif 2896 #endif
2780 } 2897 }
2781 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 2898 #endif /* PNG_READ_INTERLACING_SUPPORTED */
2782 2899
2783 void /* PRIVATE */ 2900 void /* PRIVATE */
2784 png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, 2901 png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
2785 png_bytep prev_row, int filter) 2902 png_bytep prev_row, int filter)
2786 { 2903 {
2787 png_debug(1, "in png_read_filter_row"); 2904 png_debug(1, "in png_read_filter_row");
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2896 } 3013 }
2897 break; 3014 break;
2898 } 3015 }
2899 default: 3016 default:
2900 png_warning(png_ptr, "Ignoring bad adaptive filter type"); 3017 png_warning(png_ptr, "Ignoring bad adaptive filter type");
2901 *row = 0; 3018 *row = 0;
2902 break; 3019 break;
2903 } 3020 }
2904 } 3021 }
2905 3022
2906 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED 3023 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
2907 void /* PRIVATE */ 3024 void /* PRIVATE */
2908 png_read_finish_row(png_structp png_ptr) 3025 png_read_finish_row(png_structp png_ptr)
2909 { 3026 {
2910 #ifdef PNG_USE_LOCAL_ARRAYS
2911 #ifdef PNG_READ_INTERLACING_SUPPORTED 3027 #ifdef PNG_READ_INTERLACING_SUPPORTED
2912 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 3028 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2913 3029
2914 /* Start of interlace block */ 3030 /* Start of interlace block */
2915 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 3031 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2916 3032
2917 /* Offset to next interlace block */ 3033 /* Offset to next interlace block */
2918 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 3034 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2919 3035
2920 /* Start of interlace block in the y direction */ 3036 /* Start of interlace block in the y direction */
2921 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 3037 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
2922 3038
2923 /* Offset to next interlace block in the y direction */ 3039 /* Offset to next interlace block in the y direction */
2924 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 3040 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
2925 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 3041 #endif /* PNG_READ_INTERLACING_SUPPORTED */
2926 #endif
2927 3042
2928 png_debug(1, "in png_read_finish_row"); 3043 png_debug(1, "in png_read_finish_row");
2929 png_ptr->row_number++; 3044 png_ptr->row_number++;
2930 if (png_ptr->row_number < png_ptr->num_rows) 3045 if (png_ptr->row_number < png_ptr->num_rows)
2931 return; 3046 return;
2932 3047
2933 #ifdef PNG_READ_INTERLACING_SUPPORTED 3048 #ifdef PNG_READ_INTERLACING_SUPPORTED
2934 if (png_ptr->interlaced) 3049 if (png_ptr->interlaced)
2935 { 3050 {
2936 png_ptr->row_number = 0; 3051 png_ptr->row_number = 0;
2937 png_memset_check(png_ptr, png_ptr->prev_row, 0, 3052 png_memset_check(png_ptr, png_ptr->prev_row, 0,
2938 png_ptr->rowbytes + 1); 3053 png_ptr->rowbytes + 1);
2939 do 3054 do
2940 { 3055 {
2941 png_ptr->pass++; 3056 png_ptr->pass++;
2942 if (png_ptr->pass >= 7) 3057 if (png_ptr->pass >= 7)
2943 break; 3058 break;
2944 png_ptr->iwidth = (png_ptr->width + 3059 png_ptr->iwidth = (png_ptr->width +
2945 png_pass_inc[png_ptr->pass] - 1 - 3060 png_pass_inc[png_ptr->pass] - 1 -
2946 png_pass_start[png_ptr->pass]) / 3061 png_pass_start[png_ptr->pass]) /
2947 png_pass_inc[png_ptr->pass]; 3062 png_pass_inc[png_ptr->pass];
2948 3063
2949 png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
2950 png_ptr->iwidth) + 1;
2951
2952 if (!(png_ptr->transformations & PNG_INTERLACE)) 3064 if (!(png_ptr->transformations & PNG_INTERLACE))
2953 { 3065 {
2954 png_ptr->num_rows = (png_ptr->height + 3066 png_ptr->num_rows = (png_ptr->height +
2955 png_pass_yinc[png_ptr->pass] - 1 - 3067 png_pass_yinc[png_ptr->pass] - 1 -
2956 png_pass_ystart[png_ptr->pass]) / 3068 png_pass_ystart[png_ptr->pass]) /
2957 png_pass_yinc[png_ptr->pass]; 3069 png_pass_yinc[png_ptr->pass];
2958 if (!(png_ptr->num_rows)) 3070 if (!(png_ptr->num_rows))
2959 continue; 3071 continue;
2960 } 3072 }
2961 else /* if (png_ptr->transformations & PNG_INTERLACE) */ 3073 else /* if (png_ptr->transformations & PNG_INTERLACE) */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 if (png_ptr->zbuf_size > png_ptr->idat_size) 3112 if (png_ptr->zbuf_size > png_ptr->idat_size)
3001 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; 3113 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
3002 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); 3114 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
3003 png_ptr->idat_size -= png_ptr->zstream.avail_in; 3115 png_ptr->idat_size -= png_ptr->zstream.avail_in;
3004 } 3116 }
3005 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); 3117 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
3006 if (ret == Z_STREAM_END) 3118 if (ret == Z_STREAM_END)
3007 { 3119 {
3008 if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || 3120 if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
3009 png_ptr->idat_size) 3121 png_ptr->idat_size)
3010 png_warning(png_ptr, "Extra compressed data"); 3122 png_warning(png_ptr, "Extra compressed data.");
3011 png_ptr->mode |= PNG_AFTER_IDAT; 3123 png_ptr->mode |= PNG_AFTER_IDAT;
3012 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; 3124 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3013 break; 3125 break;
3014 } 3126 }
3015 if (ret != Z_OK) 3127 if (ret != Z_OK)
3016 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : 3128 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
3017 "Decompression Error"); 3129 "Decompression Error");
3018 3130
3019 if (!(png_ptr->zstream.avail_out)) 3131 if (!(png_ptr->zstream.avail_out))
3020 { 3132 {
3021 png_warning(png_ptr, "Extra compressed data."); 3133 png_warning(png_ptr, "Extra compressed data.");
3022 png_ptr->mode |= PNG_AFTER_IDAT; 3134 png_ptr->mode |= PNG_AFTER_IDAT;
3023 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; 3135 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3024 break; 3136 break;
3025 } 3137 }
3026 3138
3027 } 3139 }
3028 png_ptr->zstream.avail_out = 0; 3140 png_ptr->zstream.avail_out = 0;
3029 } 3141 }
3030 3142
3031 if (png_ptr->idat_size || png_ptr->zstream.avail_in) 3143 if (png_ptr->idat_size || png_ptr->zstream.avail_in)
3032 png_warning(png_ptr, "Extra compression data"); 3144 png_warning(png_ptr, "Extra compression data.");
3033 3145
3034 inflateReset(&png_ptr->zstream); 3146 inflateReset(&png_ptr->zstream);
3035 3147
3036 png_ptr->mode |= PNG_AFTER_IDAT; 3148 png_ptr->mode |= PNG_AFTER_IDAT;
3037 } 3149 }
3038 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ 3150 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
3039 3151
3040 void /* PRIVATE */ 3152 void /* PRIVATE */
3041 png_read_start_row(png_structp png_ptr) 3153 png_read_start_row(png_structp png_ptr)
3042 { 3154 {
3043 #ifdef PNG_USE_LOCAL_ARRAYS
3044 #ifdef PNG_READ_INTERLACING_SUPPORTED 3155 #ifdef PNG_READ_INTERLACING_SUPPORTED
3045 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 3156 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3046 3157
3047 /* Start of interlace block */ 3158 /* Start of interlace block */
3048 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 3159 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
3049 3160
3050 /* Offset to next interlace block */ 3161 /* Offset to next interlace block */
3051 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 3162 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3052 3163
3053 /* Start of interlace block in the y direction */ 3164 /* Start of interlace block in the y direction */
3054 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 3165 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
3055 3166
3056 /* Offset to next interlace block in the y direction */ 3167 /* Offset to next interlace block in the y direction */
3057 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 3168 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
3058 #endif 3169 #endif
3059 #endif
3060 3170
3061 int max_pixel_depth; 3171 int max_pixel_depth;
3062 png_size_t row_bytes; 3172 png_size_t row_bytes;
3063 3173
3064 png_debug(1, "in png_read_start_row"); 3174 png_debug(1, "in png_read_start_row");
3065 png_ptr->zstream.avail_in = 0; 3175 png_ptr->zstream.avail_in = 0;
3066 png_init_read_transformations(png_ptr); 3176 png_init_read_transformations(png_ptr);
3067 #ifdef PNG_READ_INTERLACING_SUPPORTED 3177 #ifdef PNG_READ_INTERLACING_SUPPORTED
3068 if (png_ptr->interlaced) 3178 if (png_ptr->interlaced)
3069 { 3179 {
3070 if (!(png_ptr->transformations & PNG_INTERLACE)) 3180 if (!(png_ptr->transformations & PNG_INTERLACE))
3071 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - 3181 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
3072 png_pass_ystart[0]) / png_pass_yinc[0]; 3182 png_pass_ystart[0]) / png_pass_yinc[0];
3073 else 3183 else
3074 png_ptr->num_rows = png_ptr->height; 3184 png_ptr->num_rows = png_ptr->height;
3075 3185
3076 png_ptr->iwidth = (png_ptr->width + 3186 png_ptr->iwidth = (png_ptr->width +
3077 png_pass_inc[png_ptr->pass] - 1 - 3187 png_pass_inc[png_ptr->pass] - 1 -
3078 png_pass_start[png_ptr->pass]) / 3188 png_pass_start[png_ptr->pass]) /
3079 png_pass_inc[png_ptr->pass]; 3189 png_pass_inc[png_ptr->pass];
3080
3081 png_ptr->irowbytes =
3082 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1;
3083 } 3190 }
3084 else 3191 else
3085 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 3192 #endif /* PNG_READ_INTERLACING_SUPPORTED */
3086 { 3193 {
3087 png_ptr->num_rows = png_ptr->height; 3194 png_ptr->num_rows = png_ptr->height;
3088 png_ptr->iwidth = png_ptr->width; 3195 png_ptr->iwidth = png_ptr->width;
3089 png_ptr->irowbytes = png_ptr->rowbytes + 1;
3090 } 3196 }
3091 max_pixel_depth = png_ptr->pixel_depth; 3197 max_pixel_depth = png_ptr->pixel_depth;
3092 3198
3093 #if defined(PNG_READ_PACK_SUPPORTED) 3199 #ifdef PNG_READ_PACK_SUPPORTED
3094 if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) 3200 if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
3095 max_pixel_depth = 8; 3201 max_pixel_depth = 8;
3096 #endif 3202 #endif
3097 3203
3098 #if defined(PNG_READ_EXPAND_SUPPORTED) 3204 #ifdef PNG_READ_EXPAND_SUPPORTED
3099 if (png_ptr->transformations & PNG_EXPAND) 3205 if (png_ptr->transformations & PNG_EXPAND)
3100 { 3206 {
3101 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 3207 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
3102 { 3208 {
3103 if (png_ptr->num_trans) 3209 if (png_ptr->num_trans)
3104 max_pixel_depth = 32; 3210 max_pixel_depth = 32;
3105 else 3211 else
3106 max_pixel_depth = 24; 3212 max_pixel_depth = 24;
3107 } 3213 }
3108 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) 3214 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
3109 { 3215 {
3110 if (max_pixel_depth < 8) 3216 if (max_pixel_depth < 8)
3111 max_pixel_depth = 8; 3217 max_pixel_depth = 8;
3112 if (png_ptr->num_trans) 3218 if (png_ptr->num_trans)
3113 max_pixel_depth *= 2; 3219 max_pixel_depth *= 2;
3114 } 3220 }
3115 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) 3221 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
3116 { 3222 {
3117 if (png_ptr->num_trans) 3223 if (png_ptr->num_trans)
3118 { 3224 {
3119 max_pixel_depth *= 4; 3225 max_pixel_depth *= 4;
3120 max_pixel_depth /= 3; 3226 max_pixel_depth /= 3;
3121 } 3227 }
3122 } 3228 }
3123 } 3229 }
3124 #endif 3230 #endif
3125 3231
3126 #if defined(PNG_READ_FILLER_SUPPORTED) 3232 #ifdef PNG_READ_FILLER_SUPPORTED
3127 if (png_ptr->transformations & (PNG_FILLER)) 3233 if (png_ptr->transformations & (PNG_FILLER))
3128 { 3234 {
3129 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 3235 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
3130 max_pixel_depth = 32; 3236 max_pixel_depth = 32;
3131 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) 3237 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
3132 { 3238 {
3133 if (max_pixel_depth <= 8) 3239 if (max_pixel_depth <= 8)
3134 max_pixel_depth = 16; 3240 max_pixel_depth = 16;
3135 else 3241 else
3136 max_pixel_depth = 32; 3242 max_pixel_depth = 32;
3137 } 3243 }
3138 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) 3244 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
3139 { 3245 {
3140 if (max_pixel_depth <= 32) 3246 if (max_pixel_depth <= 32)
3141 max_pixel_depth = 32; 3247 max_pixel_depth = 32;
3142 else 3248 else
3143 max_pixel_depth = 64; 3249 max_pixel_depth = 64;
3144 } 3250 }
3145 } 3251 }
3146 #endif 3252 #endif
3147 3253
3148 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 3254 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
3149 if (png_ptr->transformations & PNG_GRAY_TO_RGB) 3255 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
3150 { 3256 {
3151 if ( 3257 if (
3152 #if defined(PNG_READ_EXPAND_SUPPORTED) 3258 #ifdef PNG_READ_EXPAND_SUPPORTED
3153 (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || 3259 (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
3154 #endif 3260 #endif
3155 #if defined(PNG_READ_FILLER_SUPPORTED) 3261 #ifdef PNG_READ_FILLER_SUPPORTED
3156 (png_ptr->transformations & (PNG_FILLER)) || 3262 (png_ptr->transformations & (PNG_FILLER)) ||
3157 #endif 3263 #endif
3158 png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 3264 png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
3159 { 3265 {
3160 if (max_pixel_depth <= 16) 3266 if (max_pixel_depth <= 16)
3161 max_pixel_depth = 32; 3267 max_pixel_depth = 32;
3162 else 3268 else
3163 max_pixel_depth = 64; 3269 max_pixel_depth = 64;
3164 } 3270 }
3165 else 3271 else
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + 3306 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
3201 1 + ((max_pixel_depth + 7) >> 3); 3307 1 + ((max_pixel_depth + 7) >> 3);
3202 #ifdef PNG_MAX_MALLOC_64K 3308 #ifdef PNG_MAX_MALLOC_64K
3203 if (row_bytes > (png_uint_32)65536L) 3309 if (row_bytes > (png_uint_32)65536L)
3204 png_error(png_ptr, "This image requires a row greater than 64KB"); 3310 png_error(png_ptr, "This image requires a row greater than 64KB");
3205 #endif 3311 #endif
3206 3312
3207 if (row_bytes + 64 > png_ptr->old_big_row_buf_size) 3313 if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
3208 { 3314 {
3209 png_free(png_ptr, png_ptr->big_row_buf); 3315 png_free(png_ptr, png_ptr->big_row_buf);
3210 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);
3211 if (png_ptr->interlaced) 3316 if (png_ptr->interlaced)
3212 png_memset(png_ptr->big_row_buf, 0, row_bytes + 64); 3317 png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
3318 row_bytes + 64);
3319 else
3320 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr,
3321 row_bytes + 64);
3322 png_ptr->old_big_row_buf_size = row_bytes + 64;
3323
3324 /* Use 32 bytes of padding before and after row_buf. */
3213 png_ptr->row_buf = png_ptr->big_row_buf + 32; 3325 png_ptr->row_buf = png_ptr->big_row_buf + 32;
3214 png_ptr->old_big_row_buf_size = row_bytes + 64; 3326 png_ptr->old_big_row_buf_size = row_bytes + 64;
3215 } 3327 }
3216 3328
3217 #ifdef PNG_MAX_MALLOC_64K 3329 #ifdef PNG_MAX_MALLOC_64K
3218 if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L) 3330 if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L)
3219 png_error(png_ptr, "This image requires a row greater than 64KB"); 3331 png_error(png_ptr, "This image requires a row greater than 64KB");
3220 #endif 3332 #endif
3221 if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1)) 3333 if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1))
3222 png_error(png_ptr, "Row has too many bytes to allocate in memory."); 3334 png_error(png_ptr, "Row has too many bytes to allocate in memory.");
3223 3335
3224 if (row_bytes + 1 > png_ptr->old_prev_row_size) 3336 if (row_bytes + 1 > png_ptr->old_prev_row_size)
3225 { 3337 {
3226 png_free(png_ptr, png_ptr->prev_row); 3338 png_free(png_ptr, png_ptr->prev_row);
3227 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( 3339 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
3228 row_bytes + 1)); 3340 row_bytes + 1));
3229 png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1); 3341 png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1);
3230 png_ptr->old_prev_row_size = row_bytes + 1; 3342 png_ptr->old_prev_row_size = row_bytes + 1;
3231 } 3343 }
3232 3344
3233 png_ptr->rowbytes = row_bytes; 3345 png_ptr->rowbytes = row_bytes;
3234 3346
3235 png_debug1(3, "width = %lu,", png_ptr->width); 3347 png_debug1(3, "width = %lu,", png_ptr->width);
3236 png_debug1(3, "height = %lu,", png_ptr->height); 3348 png_debug1(3, "height = %lu,", png_ptr->height);
3237 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); 3349 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth);
3238 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); 3350 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows);
3239 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); 3351 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes);
3240 png_debug1(3, "irowbytes = %lu", png_ptr->irowbytes); 3352 png_debug1(3, "irowbytes = %lu",
3353 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
3241 3354
3242 png_ptr->flags |= PNG_FLAG_ROW_INIT; 3355 png_ptr->flags |= PNG_FLAG_ROW_INIT;
3243 } 3356 }
3244 #endif /* PNG_READ_SUPPORTED */ 3357 #endif /* PNG_READ_SUPPORTED */
OLDNEW
« no previous file with comments | « third_party/libpng/pngrtran.c ('k') | third_party/libpng/pngset.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698