Changeset 561 for trunk/src/3rdparty/libpng/pngrutil.c
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/3rdparty/libpng/pngrutil.c
r2 r561 2 2 /* pngrutil.c - utilities to read a PNG file 3 3 * 4 * Last changed in libpng 1.2.27 [April 29, 2008] 5 * For conditions of distribution and use, see copyright notice in png.h 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson 4 * Last changed in libpng 1.2.38 [July 16, 2009] 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 7 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 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 9 12 * 10 13 * This file contains routines that are only called from within … … 14 17 #define PNG_INTERNAL 15 18 #include "png.h" 16 17 19 #if defined(PNG_READ_SUPPORTED) 18 20 … … 23 25 #ifdef PNG_FLOATING_POINT_SUPPORTED 24 26 # if defined(WIN32_WCE_OLD) 25 /* strtod() function is not supported on WindowsCE */27 /* The strtod() function is not supported on WindowsCE */ 26 28 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr) 27 29 { … … 31 33 32 34 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); 33 str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));35 str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t)); 34 36 if ( NULL != str ) 35 37 { … … 50 52 png_get_uint_31(png_structp png_ptr, png_bytep buf) 51 53 { 54 #ifdef PNG_READ_BIG_ENDIAN_SUPPORTED 52 55 png_uint_32 i = png_get_uint_32(buf); 56 #else 57 /* Avoid an extra function call by inlining the result. */ 58 png_uint_32 i = ((png_uint_32)(*buf) << 24) + 59 ((png_uint_32)(*(buf + 1)) << 16) + 60 ((png_uint_32)(*(buf + 2)) << 8) + 61 (png_uint_32)(*(buf + 3)); 62 #endif 53 63 if (i > PNG_UINT_31_MAX) 54 64 png_error(png_ptr, "PNG unsigned integer out of range."); … … 70 80 /* Grab a signed 32-bit integer from a buffer in big-endian format. The 71 81 * data is stored in the PNG file in two's complement format, and it is 72 * assumed that the machine format for signed integers is the same. */ 82 * assumed that the machine format for signed integers is the same. 83 */ 73 84 png_int_32 PNGAPI 74 85 png_get_int_32(png_bytep buf) … … 93 104 #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ 94 105 106 /* Read the chunk header (length + type name). 107 * Put the type name into png_ptr->chunk_name, and return the length. 108 */ 109 png_uint_32 /* PRIVATE */ 110 png_read_chunk_header(png_structp png_ptr) 111 { 112 png_byte buf[8]; 113 png_uint_32 length; 114 115 /* Read the length and the chunk name */ 116 png_read_data(png_ptr, buf, 8); 117 length = png_get_uint_31(png_ptr, buf); 118 119 /* Put the chunk name into png_ptr->chunk_name */ 120 png_memcpy(png_ptr->chunk_name, buf + 4, 4); 121 122 png_debug2(0, "Reading %s chunk, length = %lu", 123 png_ptr->chunk_name, length); 124 125 /* Reset the crc and run it over the chunk name */ 126 png_reset_crc(png_ptr); 127 png_calculate_crc(png_ptr, png_ptr->chunk_name, 4); 128 129 /* Check to see if chunk name is valid */ 130 png_check_chunk_name(png_ptr, png_ptr->chunk_name); 131 132 return length; 133 } 134 95 135 /* Read data, and (optionally) run it through the CRC. */ 96 136 void /* PRIVATE */ 97 137 png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) 98 138 { 99 if(png_ptr == NULL) return; 139 if (png_ptr == NULL) 140 return; 100 141 png_read_data(png_ptr, buf, length); 101 142 png_calculate_crc(png_ptr, buf, length); … … 103 144 104 145 /* Optionally skip data and then check the CRC. Depending on whether we 105 are reading a ancillary or critical chunk, and how the program has set 106 things up, we may calculate the CRC on the data and print a message. 107 Returns '1' if there was a CRC error, '0' otherwise. */ 146 * are reading a ancillary or critical chunk, and how the program has set 147 * things up, we may calculate the CRC on the data and print a message. 148 * Returns '1' if there was a CRC error, '0' otherwise. 149 */ 108 150 int /* PRIVATE */ 109 151 png_crc_finish(png_structp png_ptr, png_uint_32 skip) … … 124 166 { 125 167 if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ 126 168 !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || 127 169 (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ 128 170 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) … … 141 183 142 184 /* Compare the CRC stored in the PNG file with that calculated by libpng from 143 the data it has read thus far. */ 185 * the data it has read thus far. 186 */ 144 187 int /* PRIVATE */ 145 188 png_crc_error(png_structp png_ptr) … … 181 224 * trailing part (the malloc area passed in is freed). 182 225 */ 183 png_charp/* PRIVATE */226 void /* PRIVATE */ 184 227 png_decompress_chunk(png_structp png_ptr, int comp_type, 185 png_ charp chunkdata, png_size_t chunklength,228 png_size_t chunklength, 186 229 png_size_t prefix_size, png_size_t *newlength) 187 230 { … … 193 236 { 194 237 int ret = Z_OK; 195 png_ptr->zstream.next_in = (png_bytep)( chunkdata + prefix_size);238 png_ptr->zstream.next_in = (png_bytep)(png_ptr->chunkdata + prefix_size); 196 239 png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size); 197 240 png_ptr->zstream.next_out = png_ptr->zbuf; … … 219 262 if (text == NULL) 220 263 { 221 png_free(png_ptr,chunkdata); 222 png_error(png_ptr,"Not enough memory to decompress chunk"); 264 png_free(png_ptr, png_ptr->chunkdata); 265 png_ptr->chunkdata = NULL; 266 png_error(png_ptr, "Not enough memory to decompress chunk"); 223 267 } 224 png_memcpy(text, chunkdata, prefix_size);268 png_memcpy(text, png_ptr->chunkdata, prefix_size); 225 269 } 226 270 … … 228 272 229 273 /* Copy what we can of the error message into the text chunk */ 230 text_size = (png_size_t)(chunklength - (text - chunkdata) - 1); 231 text_size = png_sizeof(msg) > text_size ? text_size : 232 png_sizeof(msg); 274 text_size = (png_size_t)(chunklength - 275 (text - png_ptr->chunkdata) - 1); 276 if (text_size > png_sizeof(msg)) 277 text_size = png_sizeof(msg); 233 278 png_memcpy(text + prefix_size, msg, text_size); 234 279 break; … … 242 287 text = (png_charp)png_malloc_warn(png_ptr, text_size + 1); 243 288 if (text == NULL) 244 { 245 png_free(png_ptr,chunkdata); 246 png_error(png_ptr,"Not enough memory to decompress chunk."); 247 } 289 { 290 png_free(png_ptr, png_ptr->chunkdata); 291 png_ptr->chunkdata = NULL; 292 png_error(png_ptr, 293 "Not enough memory to decompress chunk."); 294 } 248 295 png_memcpy(text + prefix_size, png_ptr->zbuf, 249 296 text_size - prefix_size); 250 png_memcpy(text, chunkdata, prefix_size);297 png_memcpy(text, png_ptr->chunkdata, prefix_size); 251 298 *(text + text_size) = 0x00; 252 299 } … … 262 309 { 263 310 png_free(png_ptr, tmp); 264 png_free(png_ptr, chunkdata); 265 png_error(png_ptr,"Not enough memory to decompress chunk.."); 311 png_free(png_ptr, png_ptr->chunkdata); 312 png_ptr->chunkdata = NULL; 313 png_error(png_ptr, 314 "Not enough memory to decompress chunk.."); 266 315 } 267 316 png_memcpy(text, tmp, text_size); … … 290 339 "Buffer error in compressed datastream in %s chunk", 291 340 png_ptr->chunk_name); 341 292 342 else if (ret == Z_DATA_ERROR) 293 343 png_snprintf(umsg, 52, 294 344 "Data error in compressed datastream in %s chunk", 295 345 png_ptr->chunk_name); 346 296 347 else 297 348 png_snprintf(umsg, 52, 298 349 "Incomplete compressed datastream in %s chunk", 299 350 png_ptr->chunk_name); 351 300 352 png_warning(png_ptr, umsg); 301 353 #else … … 303 355 "Incomplete compressed datastream in chunk other than IDAT"); 304 356 #endif 305 text_size =prefix_size;357 text_size = prefix_size; 306 358 if (text == NULL) 307 359 { … … 309 361 if (text == NULL) 310 362 { 311 png_free(png_ptr, chunkdata); 312 png_error(png_ptr,"Not enough memory for text."); 363 png_free(png_ptr, png_ptr->chunkdata); 364 png_ptr->chunkdata = NULL; 365 png_error(png_ptr, "Not enough memory for text."); 313 366 } 314 png_memcpy(text, chunkdata, prefix_size);367 png_memcpy(text, png_ptr->chunkdata, prefix_size); 315 368 } 316 369 *(text + text_size) = 0x00; … … 320 373 png_ptr->zstream.avail_in = 0; 321 374 322 png_free(png_ptr, chunkdata);323 chunkdata = text;375 png_free(png_ptr, png_ptr->chunkdata); 376 png_ptr->chunkdata = text; 324 377 *newlength=text_size; 325 378 } … … 329 382 char umsg[50]; 330 383 331 png_snprintf(umsg, 50, 332 "Unknown zTXt compression type %d", comp_type); 384 png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type); 333 385 png_warning(png_ptr, umsg); 334 386 #else … … 336 388 #endif 337 389 338 *(chunkdata + prefix_size) = 0x00; 339 *newlength=prefix_size; 340 } 341 342 return chunkdata; 343 } 344 #endif 345 346 /* read and check the IDHR chunk */ 390 *(png_ptr->chunkdata + prefix_size) = 0x00; 391 *newlength = prefix_size; 392 } 393 } 394 #endif 395 396 /* Read and check the IDHR chunk */ 347 397 void /* PRIVATE */ 348 398 png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 353 403 int interlace_type; 354 404 355 png_debug(1, "in png_handle_IHDR \n");405 png_debug(1, "in png_handle_IHDR"); 356 406 357 407 if (png_ptr->mode & PNG_HAVE_IHDR) 358 408 png_error(png_ptr, "Out of place IHDR"); 359 409 360 /* check the length */410 /* Check the length */ 361 411 if (length != 13) 362 412 png_error(png_ptr, "Invalid IHDR chunk"); … … 375 425 interlace_type = buf[12]; 376 426 377 /* set internal variables */427 /* Set internal variables */ 378 428 png_ptr->width = width; 379 429 png_ptr->height = height; … … 386 436 png_ptr->compression_type = (png_byte)compression_type; 387 437 388 /* find number of channels */438 /* Find number of channels */ 389 439 switch (png_ptr->color_type) 390 440 { … … 393 443 png_ptr->channels = 1; 394 444 break; 445 395 446 case PNG_COLOR_TYPE_RGB: 396 447 png_ptr->channels = 3; 397 448 break; 449 398 450 case PNG_COLOR_TYPE_GRAY_ALPHA: 399 451 png_ptr->channels = 2; 400 452 break; 453 401 454 case PNG_COLOR_TYPE_RGB_ALPHA: 402 455 png_ptr->channels = 4; … … 404 457 } 405 458 406 /* set up other useful info */459 /* Set up other useful info */ 407 460 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * 408 461 png_ptr->channels); 409 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);410 png_debug1(3, "bit_depth = %d\n", png_ptr->bit_depth);411 png_debug1(3, "channels = %d\n", png_ptr->channels);412 png_debug1(3, "rowbytes = %lu\n", png_ptr->rowbytes);462 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); 463 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); 464 png_debug1(3, "channels = %d", png_ptr->channels); 465 png_debug1(3, "rowbytes = %lu", png_ptr->rowbytes); 413 466 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 414 467 color_type, interlace_type, compression_type, filter_type); 415 468 } 416 469 417 /* read and check the palette */470 /* Read and check the palette */ 418 471 void /* PRIVATE */ 419 472 png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) … … 425 478 #endif 426 479 427 png_debug(1, "in png_handle_PLTE \n");480 png_debug(1, "in png_handle_PLTE"); 428 481 429 482 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 430 483 png_error(png_ptr, "Missing IHDR before PLTE"); 484 431 485 else if (png_ptr->mode & PNG_HAVE_IDAT) 432 486 { … … 435 489 return; 436 490 } 491 437 492 else if (png_ptr->mode & PNG_HAVE_PLTE) 438 493 png_error(png_ptr, "Duplicate PLTE chunk"); … … 463 518 return; 464 519 } 520 465 521 else 466 522 { … … 487 543 488 544 png_crc_read(png_ptr, buf, 3); 489 /* don't depend upon png_color being any order */545 /* Don't depend upon png_color being any order */ 490 546 palette[i].red = buf[0]; 491 547 palette[i].green = buf[1]; … … 495 551 496 552 /* If we actually NEED the PLTE chunk (ie for a paletted image), we do 497 whatever the normal CRC configuration tells us. However, if we 498 have an RGB image, the PLTE can be considered ancillary, so 499 we will act as though it is. */ 553 * whatever the normal CRC configuration tells us. However, if we 554 * have an RGB image, the PLTE can be considered ancillary, so 555 * we will act as though it is. 556 */ 500 557 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 501 558 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) … … 557 614 png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 558 615 { 559 png_debug(1, "in png_handle_IEND \n");616 png_debug(1, "in png_handle_IEND"); 560 617 561 618 if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) … … 572 629 png_crc_finish(png_ptr, length); 573 630 574 info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */631 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ 575 632 } 576 633 … … 585 642 png_byte buf[4]; 586 643 587 png_debug(1, "in png_handle_gAMA \n");644 png_debug(1, "in png_handle_gAMA"); 588 645 589 646 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 622 679 623 680 igamma = (png_fixed_point)png_get_uint_32(buf); 624 /* check for zero gamma */681 /* Check for zero gamma */ 625 682 if (igamma == 0) 626 683 { … … 637 694 "Ignoring incorrect gAMA value when sRGB is also present"); 638 695 #ifndef PNG_NO_CONSOLE_IO 639 fprintf(stderr, "gamma = (%d/100000) \n", (int)igamma);696 fprintf(stderr, "gamma = (%d/100000)", (int)igamma); 640 697 #endif 641 698 return; … … 663 720 png_byte buf[4]; 664 721 665 png_debug(1, "in png_handle_sBIT \n");722 png_debug(1, "in png_handle_sBIT"); 666 723 667 724 buf[0] = buf[1] = buf[2] = buf[3] = 0; … … 726 783 png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 727 784 { 728 png_byte buf[ 4];785 png_byte buf[32]; 729 786 #ifdef PNG_FLOATING_POINT_SUPPORTED 730 787 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; … … 735 792 png_uint_32 uint_x, uint_y; 736 793 737 png_debug(1, "in png_handle_cHRM \n");794 png_debug(1, "in png_handle_cHRM"); 738 795 739 796 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 767 824 } 768 825 769 png_crc_read(png_ptr, buf, 4); 826 png_crc_read(png_ptr, buf, 32); 827 if (png_crc_finish(png_ptr, 0)) 828 return; 829 770 830 uint_x = png_get_uint_32(buf); 771 772 png_crc_read(png_ptr, buf, 4); 773 uint_y = png_get_uint_32(buf); 774 775 if (uint_x > 80000L || uint_y > 80000L || 776 uint_x + uint_y > 100000L) 777 { 778 png_warning(png_ptr, "Invalid cHRM white point"); 779 png_crc_finish(png_ptr, 24); 780 return; 781 } 831 uint_y = png_get_uint_32(buf + 4); 782 832 int_x_white = (png_fixed_point)uint_x; 783 833 int_y_white = (png_fixed_point)uint_y; 784 834 785 png_crc_read(png_ptr, buf, 4); 786 uint_x = png_get_uint_32(buf); 787 788 png_crc_read(png_ptr, buf, 4); 789 uint_y = png_get_uint_32(buf); 790 791 if (uint_x + uint_y > 100000L) 792 { 793 png_warning(png_ptr, "Invalid cHRM red point"); 794 png_crc_finish(png_ptr, 16); 795 return; 796 } 835 uint_x = png_get_uint_32(buf + 8); 836 uint_y = png_get_uint_32(buf + 12); 797 837 int_x_red = (png_fixed_point)uint_x; 798 838 int_y_red = (png_fixed_point)uint_y; 799 839 800 png_crc_read(png_ptr, buf, 4); 801 uint_x = png_get_uint_32(buf); 802 803 png_crc_read(png_ptr, buf, 4); 804 uint_y = png_get_uint_32(buf); 805 806 if (uint_x + uint_y > 100000L) 807 { 808 png_warning(png_ptr, "Invalid cHRM green point"); 809 png_crc_finish(png_ptr, 8); 810 return; 811 } 840 uint_x = png_get_uint_32(buf + 16); 841 uint_y = png_get_uint_32(buf + 20); 812 842 int_x_green = (png_fixed_point)uint_x; 813 843 int_y_green = (png_fixed_point)uint_y; 814 844 815 png_crc_read(png_ptr, buf, 4); 816 uint_x = png_get_uint_32(buf); 817 818 png_crc_read(png_ptr, buf, 4); 819 uint_y = png_get_uint_32(buf); 820 821 if (uint_x + uint_y > 100000L) 822 { 823 png_warning(png_ptr, "Invalid cHRM blue point"); 824 png_crc_finish(png_ptr, 0); 825 return; 826 } 845 uint_x = png_get_uint_32(buf + 24); 846 uint_y = png_get_uint_32(buf + 28); 827 847 int_x_blue = (png_fixed_point)uint_x; 828 848 int_y_blue = (png_fixed_point)uint_y; … … 855 875 #ifndef PNG_NO_CONSOLE_IO 856 876 #ifdef PNG_FLOATING_POINT_SUPPORTED 857 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n",877 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", 858 878 white_x, white_y, red_x, red_y); 859 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n",879 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n", 860 880 green_x, green_y, blue_x, blue_y); 861 881 #else 862 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",882 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", 863 883 int_x_white, int_y_white, int_x_red, int_y_red); 864 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n",884 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", 865 885 int_x_green, int_y_green, int_x_blue, int_y_blue); 866 886 #endif 867 887 #endif /* PNG_NO_CONSOLE_IO */ 868 888 } 869 png_crc_finish(png_ptr, 0);870 889 return; 871 890 } … … 881 900 int_y_green, int_x_blue, int_y_blue); 882 901 #endif 883 if (png_crc_finish(png_ptr, 0))884 return;885 902 } 886 903 #endif … … 893 910 png_byte buf[1]; 894 911 895 png_debug(1, "in png_handle_sRGB \n");912 png_debug(1, "in png_handle_sRGB"); 896 913 897 914 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 926 943 927 944 intent = buf[0]; 928 /* check for bad intent */945 /* Check for bad intent */ 929 946 if (intent >= PNG_sRGB_INTENT_LAST) 930 947 { … … 950 967 #ifndef PNG_NO_CONSOLE_IO 951 968 # ifdef PNG_FIXED_POINT_SUPPORTED 952 fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma); 969 fprintf(stderr, "incorrect gamma=(%d/100000)\n", 970 (int)png_ptr->int_gamma); 953 971 # else 954 972 # ifdef PNG_FLOATING_POINT_SUPPORTED 955 fprintf(stderr, "incorrect gamma=%f\n",png_ptr->gamma);973 fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma); 956 974 # endif 957 975 # endif … … 988 1006 /* Note: this does not properly handle chunks that are > 64K under DOS */ 989 1007 { 990 png_charp chunkdata;991 1008 png_byte compression_type; 992 1009 png_bytep pC; … … 996 1013 png_size_t slength, prefix_length, data_length; 997 1014 998 png_debug(1, "in png_handle_iCCP \n");1015 png_debug(1, "in png_handle_iCCP"); 999 1016 1000 1017 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1026 1043 #endif 1027 1044 1028 chunkdata = (png_charp)png_malloc(png_ptr, length + 1); 1045 png_free(png_ptr, png_ptr->chunkdata); 1046 png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); 1029 1047 slength = (png_size_t)length; 1030 png_crc_read(png_ptr, (png_bytep) chunkdata, slength);1048 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1031 1049 1032 1050 if (png_crc_finish(png_ptr, skip)) 1033 1051 { 1034 png_free(png_ptr, chunkdata); 1035 return; 1036 } 1037 1038 chunkdata[slength] = 0x00; 1039 1040 for (profile = chunkdata; *profile; profile++) 1041 /* empty loop to find end of name */ ; 1052 png_free(png_ptr, png_ptr->chunkdata); 1053 png_ptr->chunkdata = NULL; 1054 return; 1055 } 1056 1057 png_ptr->chunkdata[slength] = 0x00; 1058 1059 for (profile = png_ptr->chunkdata; *profile; profile++) 1060 /* Empty loop to find end of name */ ; 1042 1061 1043 1062 ++profile; 1044 1063 1045 /* there should be at least one zero (the compression type byte) 1046 following the separator, and we should be on it */ 1047 if ( profile >= chunkdata + slength - 1) 1048 { 1049 png_free(png_ptr, chunkdata); 1064 /* There should be at least one zero (the compression type byte) 1065 * following the separator, and we should be on it 1066 */ 1067 if ( profile >= png_ptr->chunkdata + slength - 1) 1068 { 1069 png_free(png_ptr, png_ptr->chunkdata); 1070 png_ptr->chunkdata = NULL; 1050 1071 png_warning(png_ptr, "Malformed iCCP chunk"); 1051 1072 return; 1052 1073 } 1053 1074 1054 /* compression_type should always be zero */1075 /* Compression_type should always be zero */ 1055 1076 compression_type = *profile++; 1056 1077 if (compression_type) 1057 1078 { 1058 1079 png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); 1059 compression_type =0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.81080 compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 1060 1081 wrote nonzero) */ 1061 1082 } 1062 1083 1063 prefix_length = profile - chunkdata;1064 chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,1065 1084 prefix_length = profile - png_ptr->chunkdata; 1085 png_decompress_chunk(png_ptr, compression_type, 1086 slength, prefix_length, &data_length); 1066 1087 1067 1088 profile_length = data_length - prefix_length; … … 1069 1090 if ( prefix_length > data_length || profile_length < 4) 1070 1091 { 1071 png_free(png_ptr, chunkdata); 1092 png_free(png_ptr, png_ptr->chunkdata); 1093 png_ptr->chunkdata = NULL; 1072 1094 png_warning(png_ptr, "Profile size field missing from iCCP chunk"); 1073 1095 return; … … 1075 1097 1076 1098 /* Check the profile_size recorded in the first 32 bits of the ICC profile */ 1077 pC = (png_bytep)( chunkdata+prefix_length);1078 profile_size = ((*(pC ))<<24) |1079 ((*(pC +1))<<16) |1080 ((*(pC +2))<< 8) |1081 ((*(pC +3)) );1082 1083 if (profile_size < profile_length)1099 pC = (png_bytep)(png_ptr->chunkdata + prefix_length); 1100 profile_size = ((*(pC ))<<24) | 1101 ((*(pC + 1))<<16) | 1102 ((*(pC + 2))<< 8) | 1103 ((*(pC + 3)) ); 1104 1105 if (profile_size < profile_length) 1084 1106 profile_length = profile_size; 1085 1107 1086 if(profile_size > profile_length) 1087 { 1088 png_free(png_ptr, chunkdata); 1108 if (profile_size > profile_length) 1109 { 1110 png_free(png_ptr, png_ptr->chunkdata); 1111 png_ptr->chunkdata = NULL; 1089 1112 png_warning(png_ptr, "Ignoring truncated iCCP profile."); 1090 1113 return; 1091 1114 } 1092 1115 1093 png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type, 1094 chunkdata + prefix_length, profile_length); 1095 png_free(png_ptr, chunkdata); 1116 png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, 1117 compression_type, png_ptr->chunkdata + prefix_length, profile_length); 1118 png_free(png_ptr, png_ptr->chunkdata); 1119 png_ptr->chunkdata = NULL; 1096 1120 } 1097 1121 #endif /* PNG_READ_iCCP_SUPPORTED */ … … 1102 1126 /* Note: this does not properly handle chunks that are > 64K under DOS */ 1103 1127 { 1104 png_bytep chunkdata;1105 1128 png_bytep entry_start; 1106 1129 png_sPLT_t new_palette; … … 1112 1135 png_size_t slength; 1113 1136 1114 png_debug(1, "in png_handle_sPLT\n"); 1137 png_debug(1, "in png_handle_sPLT"); 1138 1115 1139 1116 1140 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1132 1156 #endif 1133 1157 1134 chunkdata = (png_bytep)png_malloc(png_ptr, length + 1); 1158 png_free(png_ptr, png_ptr->chunkdata); 1159 png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); 1135 1160 slength = (png_size_t)length; 1136 png_crc_read(png_ptr, (png_bytep) chunkdata, slength);1161 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1137 1162 1138 1163 if (png_crc_finish(png_ptr, skip)) 1139 1164 { 1140 png_free(png_ptr, chunkdata); 1141 return; 1142 } 1143 1144 chunkdata[slength] = 0x00; 1145 1146 for (entry_start = chunkdata; *entry_start; entry_start++) 1147 /* empty loop to find end of name */ ; 1165 png_free(png_ptr, png_ptr->chunkdata); 1166 png_ptr->chunkdata = NULL; 1167 return; 1168 } 1169 1170 png_ptr->chunkdata[slength] = 0x00; 1171 1172 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; entry_start++) 1173 /* Empty loop to find end of name */ ; 1148 1174 ++entry_start; 1149 1175 1150 /* a sample depth should follow the separator, and we should be on it */ 1151 if (entry_start > chunkdata + slength - 2) 1152 { 1153 png_free(png_ptr, chunkdata); 1176 /* A sample depth should follow the separator, and we should be on it */ 1177 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) 1178 { 1179 png_free(png_ptr, png_ptr->chunkdata); 1180 png_ptr->chunkdata = NULL; 1154 1181 png_warning(png_ptr, "malformed sPLT chunk"); 1155 1182 return; … … 1158 1185 new_palette.depth = *entry_start++; 1159 1186 entry_size = (new_palette.depth == 8 ? 6 : 10); 1160 data_length = (slength - (entry_start - chunkdata));1161 1162 /* integrity-check the data length */1187 data_length = (slength - (entry_start - (png_bytep)png_ptr->chunkdata)); 1188 1189 /* Integrity-check the data length */ 1163 1190 if (data_length % entry_size) 1164 1191 { 1165 png_free(png_ptr, chunkdata); 1192 png_free(png_ptr, png_ptr->chunkdata); 1193 png_ptr->chunkdata = NULL; 1166 1194 png_warning(png_ptr, "sPLT chunk has bad length"); 1167 1195 return; … … 1169 1197 1170 1198 new_palette.nentries = (png_int_32) ( data_length / entry_size); 1171 if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /1172 png_sizeof(png_sPLT_entry)))1199 if ((png_uint_32) new_palette.nentries > 1200 (png_uint_32) (PNG_SIZE_MAX / png_sizeof(png_sPLT_entry))) 1173 1201 { 1174 1202 png_warning(png_ptr, "sPLT chunk too long"); … … 1227 1255 #endif 1228 1256 1229 /* discard all chunk data except the name and stash that */1230 new_palette.name = (png_charp)chunkdata;1257 /* Discard all chunk data except the name and stash that */ 1258 new_palette.name = png_ptr->chunkdata; 1231 1259 1232 1260 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); 1233 1261 1234 png_free(png_ptr, chunkdata); 1262 png_free(png_ptr, png_ptr->chunkdata); 1263 png_ptr->chunkdata = NULL; 1235 1264 png_free(png_ptr, new_palette.entries); 1236 1265 } … … 1243 1272 png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; 1244 1273 1245 png_debug(1, "in png_handle_tRNS \n");1274 png_debug(1, "in png_handle_tRNS"); 1246 1275 1247 1276 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1339 1368 png_byte buf[6]; 1340 1369 1341 png_debug(1, "in png_handle_bKGD \n");1370 png_debug(1, "in png_handle_bKGD"); 1342 1371 1343 1372 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1390 1419 if (info_ptr && info_ptr->num_palette) 1391 1420 { 1392 if (buf[0] >info_ptr->num_palette)1421 if (buf[0] >= info_ptr->num_palette) 1393 1422 { 1394 1423 png_warning(png_ptr, "Incorrect bKGD chunk index value"); … … 1428 1457 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; 1429 1458 1430 png_debug(1, "in png_handle_hIST \n");1459 png_debug(1, "in png_handle_hIST"); 1431 1460 1432 1461 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1483 1512 int unit_type; 1484 1513 1485 png_debug(1, "in png_handle_pHYs \n");1514 png_debug(1, "in png_handle_pHYs"); 1486 1515 1487 1516 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1526 1555 int unit_type; 1527 1556 1528 png_debug(1, "in png_handle_oFFs \n");1557 png_debug(1, "in png_handle_oFFs"); 1529 1558 1530 1559 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1562 1591 1563 1592 #if defined(PNG_READ_pCAL_SUPPORTED) 1564 /* read the pCAL chunk (described in the PNG Extensions document) */1593 /* Read the pCAL chunk (described in the PNG Extensions document) */ 1565 1594 void /* PRIVATE */ 1566 1595 png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1567 1596 { 1568 png_charp purpose;1569 1597 png_int_32 X0, X1; 1570 1598 png_byte type, nparams; … … 1574 1602 int i; 1575 1603 1576 png_debug(1, "in png_handle_pCAL \n");1604 png_debug(1, "in png_handle_pCAL"); 1577 1605 1578 1606 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1591 1619 } 1592 1620 1593 png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes) \n",1621 png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)", 1594 1622 length + 1); 1595 purpose = (png_charp)png_malloc_warn(png_ptr, length + 1); 1596 if (purpose == NULL) 1623 png_free(png_ptr, png_ptr->chunkdata); 1624 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 1625 if (png_ptr->chunkdata == NULL) 1597 1626 { 1598 1627 png_warning(png_ptr, "No memory for pCAL purpose."); … … 1600 1629 } 1601 1630 slength = (png_size_t)length; 1602 png_crc_read(png_ptr, (png_bytep)p urpose, slength);1631 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1603 1632 1604 1633 if (png_crc_finish(png_ptr, 0)) 1605 1634 { 1606 png_free(png_ptr, purpose); 1607 return; 1608 } 1609 1610 purpose[slength] = 0x00; /* null terminate the last string */ 1611 1612 png_debug(3, "Finding end of pCAL purpose string\n"); 1613 for (buf = purpose; *buf; buf++) 1614 /* empty loop */ ; 1615 1616 endptr = purpose + slength; 1635 png_free(png_ptr, png_ptr->chunkdata); 1636 png_ptr->chunkdata = NULL; 1637 return; 1638 } 1639 1640 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ 1641 1642 png_debug(3, "Finding end of pCAL purpose string"); 1643 for (buf = png_ptr->chunkdata; *buf; buf++) 1644 /* Empty loop */ ; 1645 1646 endptr = png_ptr->chunkdata + slength; 1617 1647 1618 1648 /* We need to have at least 12 bytes after the purpose string … … 1621 1651 { 1622 1652 png_warning(png_ptr, "Invalid pCAL data"); 1623 png_free(png_ptr, purpose); 1624 return; 1625 } 1626 1627 png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n"); 1653 png_free(png_ptr, png_ptr->chunkdata); 1654 png_ptr->chunkdata = NULL; 1655 return; 1656 } 1657 1658 png_debug(3, "Reading pCAL X0, X1, type, nparams, and units"); 1628 1659 X0 = png_get_int_32((png_bytep)buf+1); 1629 1660 X1 = png_get_int_32((png_bytep)buf+5); … … 1632 1663 units = buf + 11; 1633 1664 1634 png_debug(3, "Checking pCAL equation type and number of parameters \n");1665 png_debug(3, "Checking pCAL equation type and number of parameters"); 1635 1666 /* Check that we have the right number of parameters for known 1636 1667 equation types. */ … … 1641 1672 { 1642 1673 png_warning(png_ptr, "Invalid pCAL parameters for equation type"); 1643 png_free(png_ptr, purpose); 1674 png_free(png_ptr, png_ptr->chunkdata); 1675 png_ptr->chunkdata = NULL; 1644 1676 return; 1645 1677 } … … 1652 1684 /* Empty loop to move past the units string. */ ; 1653 1685 1654 png_debug(3, "Allocating pCAL parameters array \n");1655 params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams1656 *png_sizeof(png_charp))) ;1686 png_debug(3, "Allocating pCAL parameters array"); 1687 params = (png_charpp)png_malloc_warn(png_ptr, 1688 (png_uint_32)(nparams * png_sizeof(png_charp))) ; 1657 1689 if (params == NULL) 1658 1690 { 1659 png_free(png_ptr, purpose); 1691 png_free(png_ptr, png_ptr->chunkdata); 1692 png_ptr->chunkdata = NULL; 1660 1693 png_warning(png_ptr, "No memory for pCAL params."); 1661 1694 return; … … 1667 1700 buf++; /* Skip the null string terminator from previous parameter. */ 1668 1701 1669 png_debug1(3, "Reading pCAL parameter %d \n", i);1702 png_debug1(3, "Reading pCAL parameter %d", i); 1670 1703 for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++) 1671 1704 /* Empty loop to move past each parameter string */ ; … … 1675 1708 { 1676 1709 png_warning(png_ptr, "Invalid pCAL data"); 1677 png_free(png_ptr, purpose); 1710 png_free(png_ptr, png_ptr->chunkdata); 1711 png_ptr->chunkdata = NULL; 1678 1712 png_free(png_ptr, params); 1679 1713 return; … … 1681 1715 } 1682 1716 1683 png_set_pCAL(png_ptr, info_ptr, p urpose, X0, X1, type, nparams,1717 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, 1684 1718 units, params); 1685 1719 1686 png_free(png_ptr, purpose); 1720 png_free(png_ptr, png_ptr->chunkdata); 1721 png_ptr->chunkdata = NULL; 1687 1722 png_free(png_ptr, params); 1688 1723 } … … 1690 1725 1691 1726 #if defined(PNG_READ_sCAL_SUPPORTED) 1692 /* read the sCAL chunk */1727 /* Read the sCAL chunk */ 1693 1728 void /* PRIVATE */ 1694 1729 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1695 1730 { 1696 png_charp buffer,ep;1731 png_charp ep; 1697 1732 #ifdef PNG_FLOATING_POINT_SUPPORTED 1698 1733 double width, height; … … 1705 1740 png_size_t slength; 1706 1741 1707 png_debug(1, "in png_handle_sCAL \n");1742 png_debug(1, "in png_handle_sCAL"); 1708 1743 1709 1744 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1722 1757 } 1723 1758 1724 png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes) \n",1759 png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)", 1725 1760 length + 1); 1726 buffer= (png_charp)png_malloc_warn(png_ptr, length + 1);1727 if ( buffer== NULL)1728 1729 1730 1731 1761 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 1762 if (png_ptr->chunkdata == NULL) 1763 { 1764 png_warning(png_ptr, "Out of memory while processing sCAL chunk"); 1765 return; 1766 } 1732 1767 slength = (png_size_t)length; 1733 png_crc_read(png_ptr, (png_bytep) buffer, slength);1768 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1734 1769 1735 1770 if (png_crc_finish(png_ptr, 0)) 1736 1771 { 1737 png_free(png_ptr, buffer); 1738 return; 1739 } 1740 1741 buffer[slength] = 0x00; /* null terminate the last string */ 1742 1743 ep = buffer + 1; /* skip unit byte */ 1772 png_free(png_ptr, png_ptr->chunkdata); 1773 png_ptr->chunkdata = NULL; 1774 return; 1775 } 1776 1777 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ 1778 1779 ep = png_ptr->chunkdata + 1; /* Skip unit byte */ 1744 1780 1745 1781 #ifdef PNG_FLOATING_POINT_SUPPORTED … … 1747 1783 if (*vp) 1748 1784 { 1749 1750 1785 png_warning(png_ptr, "malformed width string in sCAL chunk"); 1786 return; 1751 1787 } 1752 1788 #else … … 1754 1790 swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); 1755 1791 if (swidth == NULL) 1756 1757 1758 1759 1792 { 1793 png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); 1794 return; 1795 } 1760 1796 png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); 1761 1797 #endif 1762 1798 #endif 1763 1799 1764 for (ep = buffer; *ep; ep++)1765 /* empty loop */ ;1800 for (ep = png_ptr->chunkdata; *ep; ep++) 1801 /* Empty loop */ ; 1766 1802 ep++; 1767 1803 1768 if ( buffer+ slength < ep)1769 { 1770 1804 if (png_ptr->chunkdata + slength < ep) 1805 { 1806 png_warning(png_ptr, "Truncated sCAL chunk"); 1771 1807 #if defined(PNG_FIXED_POINT_SUPPORTED) && \ 1772 1808 !defined(PNG_FLOATING_POINT_SUPPORTED) 1773 png_free(png_ptr, swidth); 1774 #endif 1775 png_free(png_ptr, buffer); 1776 return; 1809 png_free(png_ptr, swidth); 1810 #endif 1811 png_free(png_ptr, png_ptr->chunkdata); 1812 png_ptr->chunkdata = NULL; 1813 return; 1777 1814 } 1778 1815 … … 1781 1818 if (*vp) 1782 1819 { 1783 1784 1820 png_warning(png_ptr, "malformed height string in sCAL chunk"); 1821 return; 1785 1822 } 1786 1823 #else … … 1788 1825 sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); 1789 1826 if (sheight == NULL) 1790 1791 1792 1793 1827 { 1828 png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); 1829 return; 1830 } 1794 1831 png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); 1795 1832 #endif 1796 1833 #endif 1797 1834 1798 if ( buffer+ slength < ep1835 if (png_ptr->chunkdata + slength < ep 1799 1836 #ifdef PNG_FLOATING_POINT_SUPPORTED 1800 1837 || width <= 0. || height <= 0. … … 1803 1840 { 1804 1841 png_warning(png_ptr, "Invalid sCAL data"); 1805 png_free(png_ptr, buffer); 1842 png_free(png_ptr, png_ptr->chunkdata); 1843 png_ptr->chunkdata = NULL; 1806 1844 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1807 1845 png_free(png_ptr, swidth); … … 1813 1851 1814 1852 #ifdef PNG_FLOATING_POINT_SUPPORTED 1815 png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);1853 png_set_sCAL(png_ptr, info_ptr, png_ptr->chunkdata[0], width, height); 1816 1854 #else 1817 1855 #ifdef PNG_FIXED_POINT_SUPPORTED 1818 png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight); 1819 #endif 1820 #endif 1821 1822 png_free(png_ptr, buffer); 1856 png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], swidth, sheight); 1857 #endif 1858 #endif 1859 1860 png_free(png_ptr, png_ptr->chunkdata); 1861 png_ptr->chunkdata = NULL; 1823 1862 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) 1824 1863 png_free(png_ptr, swidth); … … 1835 1874 png_time mod_time; 1836 1875 1837 png_debug(1, "in png_handle_tIME \n");1876 png_debug(1, "in png_handle_tIME"); 1838 1877 1839 1878 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1883 1922 int ret; 1884 1923 1885 png_debug(1, "in png_handle_tEXt\n"); 1924 png_debug(1, "in png_handle_tEXt"); 1925 1886 1926 1887 1927 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 1900 1940 #endif 1901 1941 1902 key = (png_charp)png_malloc_warn(png_ptr, length + 1); 1903 if (key == NULL) 1942 png_free(png_ptr, png_ptr->chunkdata); 1943 1944 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 1945 if (png_ptr->chunkdata == NULL) 1904 1946 { 1905 1947 png_warning(png_ptr, "No memory to process text chunk."); … … 1907 1949 } 1908 1950 slength = (png_size_t)length; 1909 png_crc_read(png_ptr, (png_bytep) key, slength);1951 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1910 1952 1911 1953 if (png_crc_finish(png_ptr, skip)) 1912 1954 { 1913 png_free(png_ptr, key); 1914 return; 1915 } 1955 png_free(png_ptr, png_ptr->chunkdata); 1956 png_ptr->chunkdata = NULL; 1957 return; 1958 } 1959 1960 key = png_ptr->chunkdata; 1916 1961 1917 1962 key[slength] = 0x00; 1918 1963 1919 1964 for (text = key; *text; text++) 1920 /* empty loop to find end of key */ ;1965 /* Empty loop to find end of key */ ; 1921 1966 1922 1967 if (text != key + slength) … … 1928 1973 { 1929 1974 png_warning(png_ptr, "Not enough memory to process text chunk."); 1930 png_free(png_ptr, key); 1975 png_free(png_ptr, png_ptr->chunkdata); 1976 png_ptr->chunkdata = NULL; 1931 1977 return; 1932 1978 } … … 1941 1987 text_ptr->text_length = png_strlen(text); 1942 1988 1943 ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 1944 1945 png_free(png_ptr, key); 1989 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 1990 1991 png_free(png_ptr, png_ptr->chunkdata); 1992 png_ptr->chunkdata = NULL; 1946 1993 png_free(png_ptr, text_ptr); 1947 1994 if (ret) … … 1951 1998 1952 1999 #if defined(PNG_READ_zTXt_SUPPORTED) 1953 /* note: this does not correctly handle chunks that are > 64K under DOS */2000 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 1954 2001 void /* PRIVATE */ 1955 2002 png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1956 2003 { 1957 2004 png_textp text_ptr; 1958 png_charp chunkdata;1959 2005 png_charp text; 1960 2006 int comp_type; … … 1962 2008 png_size_t slength, prefix_len, data_len; 1963 2009 1964 png_debug(1, "in png_handle_zTXt\n"); 2010 png_debug(1, "in png_handle_zTXt"); 2011 2012 1965 2013 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 1966 2014 png_error(png_ptr, "Missing IHDR before zTXt"); … … 1974 2022 if (length > (png_uint_32)65535L) 1975 2023 { 1976 png_warning(png_ptr, "zTXt chunk too large to fit in memory");2024 png_warning(png_ptr, "zTXt chunk too large to fit in memory"); 1977 2025 png_crc_finish(png_ptr, length); 1978 2026 return; … … 1980 2028 #endif 1981 2029 1982 chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 1983 if (chunkdata == NULL) 1984 { 1985 png_warning(png_ptr,"Out of memory processing zTXt chunk."); 2030 png_free(png_ptr, png_ptr->chunkdata); 2031 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 2032 if (png_ptr->chunkdata == NULL) 2033 { 2034 png_warning(png_ptr, "Out of memory processing zTXt chunk."); 1986 2035 return; 1987 2036 } 1988 2037 slength = (png_size_t)length; 1989 png_crc_read(png_ptr, (png_bytep) chunkdata, slength);2038 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1990 2039 if (png_crc_finish(png_ptr, 0)) 1991 2040 { 1992 png_free(png_ptr, chunkdata); 1993 return; 1994 } 1995 1996 chunkdata[slength] = 0x00; 1997 1998 for (text = chunkdata; *text; text++) 1999 /* empty loop */ ; 2041 png_free(png_ptr, png_ptr->chunkdata); 2042 png_ptr->chunkdata = NULL; 2043 return; 2044 } 2045 2046 png_ptr->chunkdata[slength] = 0x00; 2047 2048 for (text = png_ptr->chunkdata; *text; text++) 2049 /* Empty loop */ ; 2000 2050 2001 2051 /* zTXt must have some text after the chunkdataword */ 2002 if (text >= chunkdata + slength - 2)2052 if (text >= png_ptr->chunkdata + slength - 2) 2003 2053 { 2004 2054 png_warning(png_ptr, "Truncated zTXt chunk"); 2005 png_free(png_ptr, chunkdata); 2055 png_free(png_ptr, png_ptr->chunkdata); 2056 png_ptr->chunkdata = NULL; 2006 2057 return; 2007 2058 } … … 2014 2065 comp_type = PNG_TEXT_COMPRESSION_zTXt; 2015 2066 } 2016 text++; /* skip the compression_method byte */2017 } 2018 prefix_len = text - chunkdata;2019 2020 chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,2021 2067 text++; /* Skip the compression_method byte */ 2068 } 2069 prefix_len = text - png_ptr->chunkdata; 2070 2071 png_decompress_chunk(png_ptr, comp_type, 2072 (png_size_t)length, prefix_len, &data_len); 2022 2073 2023 2074 text_ptr = (png_textp)png_malloc_warn(png_ptr, 2024 (png_uint_32)png_sizeof(png_text));2075 (png_uint_32)png_sizeof(png_text)); 2025 2076 if (text_ptr == NULL) 2026 2077 { 2027 png_warning(png_ptr,"Not enough memory to process zTXt chunk."); 2028 png_free(png_ptr, chunkdata); 2078 png_warning(png_ptr, "Not enough memory to process zTXt chunk."); 2079 png_free(png_ptr, png_ptr->chunkdata); 2080 png_ptr->chunkdata = NULL; 2029 2081 return; 2030 2082 } 2031 2083 text_ptr->compression = comp_type; 2032 text_ptr->key = chunkdata;2084 text_ptr->key = png_ptr->chunkdata; 2033 2085 #ifdef PNG_iTXt_SUPPORTED 2034 2086 text_ptr->lang = NULL; … … 2036 2088 text_ptr->itxt_length = 0; 2037 2089 #endif 2038 text_ptr->text = chunkdata + prefix_len;2090 text_ptr->text = png_ptr->chunkdata + prefix_len; 2039 2091 text_ptr->text_length = data_len; 2040 2092 2041 ret =png_set_text_2(png_ptr, info_ptr, text_ptr, 1);2093 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 2042 2094 2043 2095 png_free(png_ptr, text_ptr); 2044 png_free(png_ptr, chunkdata); 2096 png_free(png_ptr, png_ptr->chunkdata); 2097 png_ptr->chunkdata = NULL; 2045 2098 if (ret) 2046 2099 png_error(png_ptr, "Insufficient memory to store zTXt chunk."); … … 2049 2102 2050 2103 #if defined(PNG_READ_iTXt_SUPPORTED) 2051 /* note: this does not correctly handle chunks that are > 64K under DOS */2104 /* Note: this does not correctly handle chunks that are > 64K under DOS */ 2052 2105 void /* PRIVATE */ 2053 2106 png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 2054 2107 { 2055 2108 png_textp text_ptr; 2056 png_charp chunkdata;2057 2109 png_charp key, lang, text, lang_key; 2058 2110 int comp_flag; … … 2061 2113 png_size_t slength, prefix_len, data_len; 2062 2114 2063 png_debug(1, "in png_handle_iTXt\n"); 2115 png_debug(1, "in png_handle_iTXt"); 2116 2064 2117 2065 2118 if (!(png_ptr->mode & PNG_HAVE_IHDR)) … … 2074 2127 if (length > (png_uint_32)65535L) 2075 2128 { 2076 png_warning(png_ptr, "iTXt chunk too large to fit in memory");2129 png_warning(png_ptr, "iTXt chunk too large to fit in memory"); 2077 2130 png_crc_finish(png_ptr, length); 2078 2131 return; … … 2080 2133 #endif 2081 2134 2082 chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 2083 if (chunkdata == NULL) 2135 png_free(png_ptr, png_ptr->chunkdata); 2136 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); 2137 if (png_ptr->chunkdata == NULL) 2084 2138 { 2085 2139 png_warning(png_ptr, "No memory to process iTXt chunk."); … … 2087 2141 } 2088 2142 slength = (png_size_t)length; 2089 png_crc_read(png_ptr, (png_bytep) chunkdata, slength);2143 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 2090 2144 if (png_crc_finish(png_ptr, 0)) 2091 2145 { 2092 png_free(png_ptr, chunkdata); 2093 return; 2094 } 2095 2096 chunkdata[slength] = 0x00; 2097 2098 for (lang = chunkdata; *lang; lang++) 2099 /* empty loop */ ; 2100 lang++; /* skip NUL separator */ 2146 png_free(png_ptr, png_ptr->chunkdata); 2147 png_ptr->chunkdata = NULL; 2148 return; 2149 } 2150 2151 png_ptr->chunkdata[slength] = 0x00; 2152 2153 for (lang = png_ptr->chunkdata; *lang; lang++) 2154 /* Empty loop */ ; 2155 lang++; /* Skip NUL separator */ 2101 2156 2102 2157 /* iTXt must have a language tag (possibly empty), two compression bytes, 2103 translated keyword (possibly empty), and possibly some text after the 2104 keyword */ 2105 2106 if (lang >= chunkdata + slength - 3) 2158 * translated keyword (possibly empty), and possibly some text after the 2159 * keyword 2160 */ 2161 2162 if (lang >= png_ptr->chunkdata + slength - 3) 2107 2163 { 2108 2164 png_warning(png_ptr, "Truncated iTXt chunk"); 2109 png_free(png_ptr, chunkdata); 2165 png_free(png_ptr, png_ptr->chunkdata); 2166 png_ptr->chunkdata = NULL; 2110 2167 return; 2111 2168 } … … 2117 2174 2118 2175 for (lang_key = lang; *lang_key; lang_key++) 2119 /* empty loop */ ;2120 lang_key++; /* skip NUL separator */2121 2122 if (lang_key >= chunkdata + slength)2176 /* Empty loop */ ; 2177 lang_key++; /* Skip NUL separator */ 2178 2179 if (lang_key >= png_ptr->chunkdata + slength) 2123 2180 { 2124 2181 png_warning(png_ptr, "Truncated iTXt chunk"); 2125 png_free(png_ptr, chunkdata); 2182 png_free(png_ptr, png_ptr->chunkdata); 2183 png_ptr->chunkdata = NULL; 2126 2184 return; 2127 2185 } 2128 2186 2129 2187 for (text = lang_key; *text; text++) 2130 /* empty loop */ ;2131 text++; /* skip NUL separator */2132 if (text >= chunkdata + slength)2188 /* Empty loop */ ; 2189 text++; /* Skip NUL separator */ 2190 if (text >= png_ptr->chunkdata + slength) 2133 2191 { 2134 2192 png_warning(png_ptr, "Malformed iTXt chunk"); 2135 png_free(png_ptr, chunkdata); 2136 return; 2137 } 2138 2139 prefix_len = text - chunkdata; 2140 2141 key=chunkdata; 2193 png_free(png_ptr, png_ptr->chunkdata); 2194 png_ptr->chunkdata = NULL; 2195 return; 2196 } 2197 2198 prefix_len = text - png_ptr->chunkdata; 2199 2200 key=png_ptr->chunkdata; 2142 2201 if (comp_flag) 2143 chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,2144 2202 png_decompress_chunk(png_ptr, comp_type, 2203 (size_t)length, prefix_len, &data_len); 2145 2204 else 2146 data_len =png_strlen(chunkdata + prefix_len);2205 data_len = png_strlen(png_ptr->chunkdata + prefix_len); 2147 2206 text_ptr = (png_textp)png_malloc_warn(png_ptr, 2148 2207 (png_uint_32)png_sizeof(png_text)); 2149 2208 if (text_ptr == NULL) 2150 2209 { 2151 png_warning(png_ptr,"Not enough memory to process iTXt chunk."); 2152 png_free(png_ptr, chunkdata); 2210 png_warning(png_ptr, "Not enough memory to process iTXt chunk."); 2211 png_free(png_ptr, png_ptr->chunkdata); 2212 png_ptr->chunkdata = NULL; 2153 2213 return; 2154 2214 } 2155 2215 text_ptr->compression = (int)comp_flag + 1; 2156 text_ptr->lang_key = chunkdata+(lang_key-key);2157 text_ptr->lang = chunkdata+(lang-key);2216 text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key); 2217 text_ptr->lang = png_ptr->chunkdata + (lang - key); 2158 2218 text_ptr->itxt_length = data_len; 2159 2219 text_ptr->text_length = 0; 2160 text_ptr->key = chunkdata;2161 text_ptr->text = chunkdata + prefix_len;2162 2163 ret =png_set_text_2(png_ptr, info_ptr, text_ptr, 1);2220 text_ptr->key = png_ptr->chunkdata; 2221 text_ptr->text = png_ptr->chunkdata + prefix_len; 2222 2223 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); 2164 2224 2165 2225 png_free(png_ptr, text_ptr); 2166 png_free(png_ptr, chunkdata); 2226 png_free(png_ptr, png_ptr->chunkdata); 2227 png_ptr->chunkdata = NULL; 2167 2228 if (ret) 2168 2229 png_error(png_ptr, "Insufficient memory to store iTXt chunk."); … … 2180 2241 png_uint_32 skip = 0; 2181 2242 2182 png_debug(1, "in png_handle_unknown\n"); 2243 png_debug(1, "in png_handle_unknown"); 2244 2183 2245 2184 2246 if (png_ptr->mode & PNG_HAVE_IDAT) … … 2187 2249 PNG_CONST PNG_IDAT; 2188 2250 #endif 2189 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */2251 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */ 2190 2252 png_ptr->mode |= PNG_AFTER_IDAT; 2191 2253 } 2192 2254 2193 png_check_chunk_name(png_ptr, png_ptr->chunk_name);2194 2195 2255 if (!(png_ptr->chunk_name[0] & 0x20)) 2196 2256 { 2197 #if defined(PNG_ READ_UNKNOWN_CHUNKS_SUPPORTED)2198 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=2257 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) 2258 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2199 2259 PNG_HANDLE_CHUNK_ALWAYS 2200 2260 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) … … 2207 2267 2208 2268 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) 2209 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) || 2210 (png_ptr->read_user_chunk_fn != NULL)) 2269 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) 2270 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2271 || (png_ptr->read_user_chunk_fn != NULL) 2272 #endif 2273 ) 2211 2274 { 2212 2275 #ifdef PNG_MAX_MALLOC_64K … … 2219 2282 #endif 2220 2283 png_memcpy((png_charp)png_ptr->unknown_chunk.name, 2221 (png_charp)png_ptr->chunk_name, 2284 (png_charp)png_ptr->chunk_name, 2222 2285 png_sizeof(png_ptr->unknown_chunk.name)); 2223 2286 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0'; … … 2231 2294 } 2232 2295 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2233 if (png_ptr->read_user_chunk_fn != NULL)2296 if (png_ptr->read_user_chunk_fn != NULL) 2234 2297 { 2235 /* callback to user unknown chunk handler */2298 /* Callback to user unknown chunk handler */ 2236 2299 int ret; 2237 2300 ret = (*(png_ptr->read_user_chunk_fn)) … … 2242 2305 { 2243 2306 if (!(png_ptr->chunk_name[0] & 0x20)) 2244 if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2307 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) 2308 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2245 2309 PNG_HANDLE_CHUNK_ALWAYS) 2310 #endif 2246 2311 png_chunk_error(png_ptr, "unknown critical chunk"); 2247 2312 png_set_unknown_chunks(png_ptr, info_ptr, … … 2262 2327 2263 2328 #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2264 info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */2329 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ 2265 2330 #endif 2266 2331 } … … 2277 2342 png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name) 2278 2343 { 2279 png_debug(1, "in png_check_chunk_name \n");2344 png_debug(1, "in png_check_chunk_name"); 2280 2345 if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) || 2281 2346 isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3])) … … 2299 2364 png_combine_row(png_structp png_ptr, png_bytep row, int mask) 2300 2365 { 2301 png_debug(1, "in png_combine_row\n");2366 png_debug(1, "in png_combine_row"); 2302 2367 if (mask == 0xff) 2303 2368 { … … 2510 2575 png_uint_32 transformations = png_ptr->transformations; 2511 2576 #ifdef PNG_USE_LOCAL_ARRAYS 2512 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */2513 /* offset to next interlace block */2577 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2578 /* Offset to next interlace block */ 2514 2579 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2515 2580 #endif 2516 2581 2517 png_debug(1, "in png_do_read_interlace\n");2582 png_debug(1, "in png_do_read_interlace"); 2518 2583 if (row != NULL && row_info != NULL) 2519 2584 { … … 2716 2781 } 2717 2782 row_info->width = final_width; 2718 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);2783 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); 2719 2784 } 2720 2785 #if !defined(PNG_READ_PACKSWAP_SUPPORTED) 2721 transformations = transformations; /* silence compiler warning */2786 transformations = transformations; /* Silence compiler warning */ 2722 2787 #endif 2723 2788 } … … 2728 2793 png_bytep prev_row, int filter) 2729 2794 { 2730 png_debug(1, "in png_read_filter_row \n");2731 png_debug2(2, "row = %lu, filter = %d\n", png_ptr->row_number, filter);2795 png_debug(1, "in png_read_filter_row"); 2796 png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter); 2732 2797 switch (filter) 2733 2798 { … … 2803 2868 } 2804 2869 2805 for (i = 0; i < istop; i++) /* use leftover rp,pp */2870 for (i = 0; i < istop; i++) /* Use leftover rp,pp */ 2806 2871 { 2807 2872 int a, b, c, pa, pb, pc, p; … … 2833 2898 */ 2834 2899 2835 p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;2900 p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; 2836 2901 2837 2902 *rp = (png_byte)(((int)(*rp) + p) & 0xff); … … 2842 2907 default: 2843 2908 png_warning(png_ptr, "Ignoring bad adaptive filter type"); 2844 *row =0;2909 *row = 0; 2845 2910 break; 2846 2911 } 2847 2912 } 2848 2913 2914 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED 2849 2915 void /* PRIVATE */ 2850 2916 png_read_finish_row(png_structp png_ptr) … … 2852 2918 #ifdef PNG_USE_LOCAL_ARRAYS 2853 2919 #ifdef PNG_READ_INTERLACING_SUPPORTED 2854 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */2855 2856 /* start of interlace block */2920 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2921 2922 /* Start of interlace block */ 2857 2923 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 2858 2924 2859 /* offset to next interlace block */2925 /* Offset to next interlace block */ 2860 2926 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2861 2927 2862 /* start of interlace block in the y direction */2928 /* Start of interlace block in the y direction */ 2863 2929 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 2864 2930 2865 /* offset to next interlace block in the y direction */2931 /* Offset to next interlace block in the y direction */ 2866 2932 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 2867 2933 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 2868 2934 #endif 2869 2935 2870 png_debug(1, "in png_read_finish_row \n");2936 png_debug(1, "in png_read_finish_row"); 2871 2937 png_ptr->row_number++; 2872 2938 if (png_ptr->row_number < png_ptr->num_rows) … … 2920 2986 png_ptr->zstream.next_out = (Byte *)&extra; 2921 2987 png_ptr->zstream.avail_out = (uInt)1; 2922 for (;;)2988 for (;;) 2923 2989 { 2924 2990 if (!(png_ptr->zstream.avail_in)) … … 2978 3044 png_ptr->mode |= PNG_AFTER_IDAT; 2979 3045 } 3046 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ 2980 3047 2981 3048 void /* PRIVATE */ … … 2984 3051 #ifdef PNG_USE_LOCAL_ARRAYS 2985 3052 #ifdef PNG_READ_INTERLACING_SUPPORTED 2986 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */2987 2988 /* start of interlace block */3053 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 3054 3055 /* Start of interlace block */ 2989 3056 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 2990 3057 2991 /* offset to next interlace block */3058 /* Offset to next interlace block */ 2992 3059 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2993 3060 2994 /* start of interlace block in the y direction */3061 /* Start of interlace block in the y direction */ 2995 3062 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 2996 3063 2997 /* offset to next interlace block in the y direction */3064 /* Offset to next interlace block in the y direction */ 2998 3065 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 2999 3066 #endif … … 3001 3068 3002 3069 int max_pixel_depth; 3003 png_ uint_32row_bytes;3004 3005 png_debug(1, "in png_read_start_row \n");3070 png_size_t row_bytes; 3071 3072 png_debug(1, "in png_read_start_row"); 3006 3073 png_ptr->zstream.avail_in = 0; 3007 3074 png_init_read_transformations(png_ptr); … … 3020 3087 png_pass_inc[png_ptr->pass]; 3021 3088 3022 row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1; 3023 3024 png_ptr->irowbytes = (png_size_t)row_bytes; 3025 if((png_uint_32)png_ptr->irowbytes != row_bytes) 3026 png_error(png_ptr, "Rowbytes overflow in png_read_start_row"); 3089 png_ptr->irowbytes = 3090 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1; 3027 3091 } 3028 3092 else … … 3126 3190 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ 3127 3191 defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) 3128 if (png_ptr->transformations & PNG_USER_TRANSFORM)3192 if (png_ptr->transformations & PNG_USER_TRANSFORM) 3129 3193 { 3130 int user_pixel_depth =png_ptr->user_transform_depth*3194 int user_pixel_depth = png_ptr->user_transform_depth* 3131 3195 png_ptr->user_transform_channels; 3132 if (user_pixel_depth > max_pixel_depth)3196 if (user_pixel_depth > max_pixel_depth) 3133 3197 max_pixel_depth=user_pixel_depth; 3134 3198 } 3135 3199 #endif 3136 3200 3137 /* align the width on the next larger 8 pixels. Mainly used 3138 for interlacing */ 3201 /* Align the width on the next larger 8 pixels. Mainly used 3202 * for interlacing 3203 */ 3139 3204 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); 3140 /* calculate the maximum bytes needed, adding a byte and a pixel 3141 for safety's sake */ 3142 row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) + 3205 /* Calculate the maximum bytes needed, adding a byte and a pixel 3206 * for safety's sake 3207 */ 3208 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + 3143 3209 1 + ((max_pixel_depth + 7) >> 3); 3144 3210 #ifdef PNG_MAX_MALLOC_64K … … 3147 3213 #endif 3148 3214 3149 if(row_bytes + 64 > png_ptr->old_big_row_buf_size) 3150 { 3151 png_free(png_ptr,png_ptr->big_row_buf); 3152 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64); 3153 png_ptr->row_buf = png_ptr->big_row_buf+32; 3154 png_ptr->old_big_row_buf_size = row_bytes+64; 3215 if (row_bytes + 64 > png_ptr->old_big_row_buf_size) 3216 { 3217 png_free(png_ptr, png_ptr->big_row_buf); 3218 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64); 3219 if (png_ptr->interlaced) 3220 png_memset(png_ptr->big_row_buf, 0, row_bytes + 64); 3221 png_ptr->row_buf = png_ptr->big_row_buf + 32; 3222 png_ptr->old_big_row_buf_size = row_bytes + 64; 3155 3223 } 3156 3224 3157 3225 #ifdef PNG_MAX_MALLOC_64K 3158 if ((png_uint_32) png_ptr->rowbytes + 1 > (png_uint_32)65536L)3226 if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L) 3159 3227 png_error(png_ptr, "This image requires a row greater than 64KB"); 3160 3228 #endif 3161 if ((png_uint_32) png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))3229 if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1)) 3162 3230 png_error(png_ptr, "Row has too many bytes to allocate in memory."); 3163 3231 3164 if(png_ptr->rowbytes+1 > png_ptr->old_prev_row_size) 3165 { 3166 png_free(png_ptr,png_ptr->prev_row); 3167 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( 3168 png_ptr->rowbytes + 1)); 3169 png_ptr->old_prev_row_size = png_ptr->rowbytes+1; 3170 } 3171 3172 png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); 3173 3174 png_debug1(3, "width = %lu,\n", png_ptr->width); 3175 png_debug1(3, "height = %lu,\n", png_ptr->height); 3176 png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth); 3177 png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows); 3178 png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes); 3179 png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes); 3232 if (row_bytes + 1 > png_ptr->old_prev_row_size) 3233 { 3234 png_free(png_ptr, png_ptr->prev_row); 3235 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( 3236 row_bytes + 1)); 3237 png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1); 3238 png_ptr->old_prev_row_size = row_bytes + 1; 3239 } 3240 3241 png_ptr->rowbytes = row_bytes; 3242 3243 png_debug1(3, "width = %lu,", png_ptr->width); 3244 png_debug1(3, "height = %lu,", png_ptr->height); 3245 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); 3246 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); 3247 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); 3248 png_debug1(3, "irowbytes = %lu", png_ptr->irowbytes); 3180 3249 3181 3250 png_ptr->flags |= PNG_FLAG_ROW_INIT;
Note:
See TracChangeset
for help on using the changeset viewer.