< prev index next >

src/java.desktop/share/native/libsplashscreen/libpng/png.c

Print this page

        

*** 27,38 **** * This file is available under and governed by the GNU General Public * License version 2 only, as published by the Free Software Foundation. * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * ! * Last changed in libpng 1.6.19 [November 12, 2015] ! * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer --- 27,38 ---- * This file is available under and governed by the GNU General Public * License version 2 only, as published by the Free Software Foundation. * However, the following notice accompanied the original version of this * file and, per its terms, should not be removed: * ! * Last changed in libpng 1.6.28 [January 5, 2017] ! * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer
*** 40,50 **** */ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ ! typedef png_libpng_version_1_6_23 Your_png_h_is_not_version_1_6_23; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another * stream we can set num_bytes = 8 so that libpng will not attempt to read * or write any of the magic bytes before it starts on the IHDR. --- 40,50 ---- */ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ ! typedef png_libpng_version_1_6_28 Your_png_h_is_not_version_1_6_28; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another * stream we can set num_bytes = 8 so that libpng will not attempt to read * or write any of the magic bytes before it starts on the IHDR.
*** 484,494 **** if (png_ptr == NULL || info_ptr == NULL) return; #ifdef PNG_TEXT_SUPPORTED /* Free text item num or (if num == -1) all text items */ ! if (info_ptr->text != 0 && ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->text[num].key); --- 484,494 ---- if (png_ptr == NULL || info_ptr == NULL) return; #ifdef PNG_TEXT_SUPPORTED /* Free text item num or (if num == -1) all text items */ ! if (info_ptr->text != NULL && ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->text[num].key);
*** 503,512 **** --- 503,513 ---- png_free(png_ptr, info_ptr->text[i].key); png_free(png_ptr, info_ptr->text); info_ptr->text = NULL; info_ptr->num_text = 0; + info_ptr->max_text = 0; } } #endif #ifdef PNG_tRNS_SUPPORTED
*** 567,577 **** } #endif #ifdef PNG_sPLT_SUPPORTED /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ ! if (info_ptr->splt_palettes != 0 && ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->splt_palettes[num].name); --- 568,578 ---- } #endif #ifdef PNG_sPLT_SUPPORTED /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ ! if (info_ptr->splt_palettes != NULL && ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->splt_palettes[num].name);
*** 597,607 **** } } #endif #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED ! if (info_ptr->unknown_chunks != 0 && ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->unknown_chunks[num].data); --- 598,608 ---- } } #endif #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED ! if (info_ptr->unknown_chunks != NULL && ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0) { if (num != -1) { png_free(png_ptr, info_ptr->unknown_chunks[num].data);
*** 643,653 **** #ifdef PNG_INFO_IMAGE_SUPPORTED /* Free any image bits attached to the info structure */ if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0) { ! if (info_ptr->row_pointers != 0) { png_uint_32 row; for (row = 0; row < info_ptr->height; row++) png_free(png_ptr, info_ptr->row_pointers[row]); --- 644,654 ---- #ifdef PNG_INFO_IMAGE_SUPPORTED /* Free any image bits attached to the info structure */ if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0) { ! if (info_ptr->row_pointers != NULL) { png_uint_32 row; for (row = 0; row < info_ptr->height; row++) png_free(png_ptr, info_ptr->row_pointers[row]);
*** 710,720 **** * correspnding to the 2's complement representation. */ void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i) { ! png_save_uint_32(buf, i); } # endif # ifdef PNG_TIME_RFC1123_SUPPORTED /* Convert the supplied time into an RFC 1123 string suitable for use in --- 711,721 ---- * correspnding to the 2's complement representation. */ void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i) { ! png_save_uint_32(buf, (png_uint_32)i); } # endif # ifdef PNG_TIME_RFC1123_SUPPORTED /* Convert the supplied time into an RFC 1123 string suitable for use in
*** 801,819 **** #ifdef PNG_STRING_COPYRIGHT return PNG_STRING_COPYRIGHT #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ ! "libpng version 1.6.23 - June 9, 2016" PNG_STRING_NEWLINE \ ! "Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \ PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else ! return "libpng version 1.6.23 - June 9, 2016\ ! Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; # endif #endif } --- 802,820 ---- #ifdef PNG_STRING_COPYRIGHT return PNG_STRING_COPYRIGHT #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ ! "libpng version 1.6.28 - January 5, 2017" PNG_STRING_NEWLINE \ ! "Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson" \ PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else ! return "libpng version 1.6.28 - January 5, 2017\ ! Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; # endif #endif }
*** 1957,1977 **** * (63189.8112, 65536, 54060.6464) */ static const png_byte D50_nCIEXYZ[12] = { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d }; ! int /* PRIVATE */ ! png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length) { if (profile_length < 132) return png_icc_profile_error(png_ptr, colorspace, name, profile_length, "too short"); return 1; } int /* PRIVATE */ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length, png_const_bytep profile/* first 132 bytes only */, int color_type) { --- 1958,2012 ---- * (63189.8112, 65536, 54060.6464) */ static const png_byte D50_nCIEXYZ[12] = { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d }; ! static int /* bool */ ! icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length) { if (profile_length < 132) return png_icc_profile_error(png_ptr, colorspace, name, profile_length, "too short"); return 1; } + #ifdef PNG_READ_iCCP_SUPPORTED + int /* PRIVATE */ + png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length) + { + if (!icc_check_length(png_ptr, colorspace, name, profile_length)) + return 0; + + /* This needs to be here because the 'normal' check is in + * png_decompress_chunk, yet this happens after the attempt to + * png_malloc_base the required data. We only need this on read; on write + * the caller supplies the profile buffer so libpng doesn't allocate it. See + * the call to icc_check_length below (the write case). + */ + # ifdef PNG_SET_USER_LIMITS_SUPPORTED + else if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds application limits"); + # elif PNG_USER_CHUNK_MALLOC_MAX > 0 + else if (PNG_USER_CHUNK_MALLOC_MAX < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds libpng limits"); + # else /* !SET_USER_LIMITS */ + /* This will get compiled out on all 32-bit and better systems. */ + else if (PNG_SIZE_MAX < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds system limits"); + # endif /* !SET_USER_LIMITS */ + + return 1; + } + #endif /* READ_iCCP */ + int /* PRIVATE */ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length, png_const_bytep profile/* first 132 bytes only */, int color_type) {
*** 2380,2421 **** } } return 0; /* no match */ } - #endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */ void /* PRIVATE */ png_icc_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_bytep profile, uLong adler) { /* Is this profile one of the known ICC sRGB profiles? If it is, just set * the sRGB information. */ - #if PNG_sRGB_PROFILE_CHECKS >= 0 if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0) - #endif (void)png_colorspace_set_sRGB(png_ptr, colorspace, (int)/*already checked*/png_get_uint_32(profile+64)); } #endif /* sRGB */ int /* PRIVATE */ png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length, png_const_bytep profile, int color_type) { if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) return 0; ! if (png_icc_check_length(png_ptr, colorspace, name, profile_length) != 0 && png_icc_check_header(png_ptr, colorspace, name, profile_length, profile, color_type) != 0 && png_icc_check_tag_table(png_ptr, colorspace, name, profile_length, profile) != 0) { ! # ifdef PNG_sRGB_SUPPORTED /* If no sRGB support, don't try storing sRGB information */ png_icc_set_sRGB(png_ptr, colorspace, profile, 0); # endif return 1; } --- 2415,2454 ---- } } return 0; /* no match */ } void /* PRIVATE */ png_icc_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_bytep profile, uLong adler) { /* Is this profile one of the known ICC sRGB profiles? If it is, just set * the sRGB information. */ if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0) (void)png_colorspace_set_sRGB(png_ptr, colorspace, (int)/*already checked*/png_get_uint_32(profile+64)); } + #endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */ #endif /* sRGB */ int /* PRIVATE */ png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length, png_const_bytep profile, int color_type) { if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) return 0; ! if (icc_check_length(png_ptr, colorspace, name, profile_length) != 0 && png_icc_check_header(png_ptr, colorspace, name, profile_length, profile, color_type) != 0 && png_icc_check_tag_table(png_ptr, colorspace, name, profile_length, profile) != 0) { ! # if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0 /* If no sRGB support, don't try storing sRGB information */ png_icc_set_sRGB(png_ptr, colorspace, profile, 0); # endif return 1; }
*** 2523,2533 **** { png_warning(png_ptr, "Invalid image width in IHDR"); error = 1; } ! if (png_gt(((width + 7) & (~7)), ((PNG_SIZE_MAX - 48 /* big_row_buf hack */ - 1) /* filter byte */ / 8) /* 8-byte RGBA pixels */ - 1)) /* extra max_pixel_depth pad */ --- 2556,2566 ---- { png_warning(png_ptr, "Invalid image width in IHDR"); error = 1; } ! if (png_gt(((width + 7) & (~7U)), ((PNG_SIZE_MAX - 48 /* big_row_buf hack */ - 1) /* filter byte */ / 8) /* 8-byte RGBA pixels */ - 1)) /* extra max_pixel_depth pad */
*** 2934,2944 **** /* Allow up to two leading zeros - this will not lengthen * the number compared to using E-n. */ if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ { ! czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */ exp_b10 = 0; /* Dot added below before first output. */ } else czero = 0; /* No zeros to add */ --- 2967,2977 ---- /* Allow up to two leading zeros - this will not lengthen * the number compared to using E-n. */ if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ { ! czero = (unsigned int)(-exp_b10); /* PLUS 2 digits: TOTAL 3 */ exp_b10 = 0; /* Dot added below before first output. */ } else czero = 0; /* No zeros to add */
*** 3112,3126 **** unsigned int uexp_b10; if (exp_b10 < 0) { *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ ! uexp_b10 = -exp_b10; } else ! uexp_b10 = exp_b10; cdigits = 0; while (uexp_b10 > 0) { --- 3145,3159 ---- unsigned int uexp_b10; if (exp_b10 < 0) { *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ ! uexp_b10 = (unsigned int)(-exp_b10); } else ! uexp_b10 = (unsigned int)exp_b10; cdigits = 0; while (uexp_b10 > 0) {
*** 3178,3190 **** { png_uint_32 num; /* Avoid overflow here on the minimum integer. */ if (fp < 0) ! *ascii++ = 45, num = -fp; else ! num = fp; if (num <= 0x80000000) /* else overflowed */ { unsigned int ndigits = 0, first = 16 /* flag value */; char digits[10]; --- 3211,3223 ---- { png_uint_32 num; /* Avoid overflow here on the minimum integer. */ if (fp < 0) ! *ascii++ = 45, num = (png_uint_32)(-fp); else ! num = (png_uint_32)fp; if (num <= 0x80000000) /* else overflowed */ { unsigned int ndigits = 0, first = 16 /* flag value */; char digits[10];
*** 4118,4141 **** { png_debug(1, "in png_build_gamma_table"); /* Remove any existing table; this copes with multiple calls to * png_read_update_info. The warning is because building the gamma tables ! * multiple times is a performance hit - it's harmless but the ability to call ! * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible ! * to warn if the app introduces such a hit. */ if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) { png_warning(png_ptr, "gamma table being rebuilt"); png_destroy_gamma_table(png_ptr); } if (bit_depth <= 8) { png_build_8bit_table(png_ptr, &png_ptr->gamma_table, ! png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) --- 4151,4175 ---- { png_debug(1, "in png_build_gamma_table"); /* Remove any existing table; this copes with multiple calls to * png_read_update_info. The warning is because building the gamma tables ! * multiple times is a performance hit - it's harmless but the ability to ! * call png_read_update_info() multiple times is new in 1.5.6 so it seems ! * sensible to warn if the app introduces such a hit. */ if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) { png_warning(png_ptr, "gamma table being rebuilt"); png_destroy_gamma_table(png_ptr); } if (bit_depth <= 8) { png_build_8bit_table(png_ptr, &png_ptr->gamma_table, ! png_ptr->screen_gamma > 0 ? ! png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
*** 4143,4153 **** { png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, png_reciprocal(png_ptr->colorspace.gamma)); png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, ! png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); } #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ } #ifdef PNG_16BIT_SUPPORTED --- 4177,4188 ---- { png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, png_reciprocal(png_ptr->colorspace.gamma)); png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, ! png_ptr->screen_gamma > 0 ? ! png_reciprocal(png_ptr->screen_gamma) : png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); } #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ } #ifdef PNG_16BIT_SUPPORTED
*** 4174,4185 **** * * Where 'iv' is the input color value and 'ov' is the output value - * pow(iv, gamma). * * Thus the gamma table consists of up to 256 256-entry tables. The table ! * is selected by the (8-gamma_shift) most significant of the low 8 bits of ! * the color value then indexed by the upper 8 bits: * * table[low bits][high 8 bits] * * So the table 'n' corresponds to all those 'iv' of: * --- 4209,4220 ---- * * Where 'iv' is the input color value and 'ov' is the output value - * pow(iv, gamma). * * Thus the gamma table consists of up to 256 256-entry tables. The table ! * is selected by the (8-gamma_shift) most significant of the low 8 bits ! * of the color value then indexed by the upper 8 bits: * * table[low bits][high 8 bits] * * So the table 'n' corresponds to all those 'iv' of: *
*** 4208,4219 **** png_ptr->gamma_shift = shift; /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now * PNG_COMPOSE). This effectively smashed the background calculation for ! * 16-bit output because the 8-bit table assumes the result will be reduced ! * to 8 bits. */ if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1); --- 4243,4254 ---- png_ptr->gamma_shift = shift; /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now * PNG_COMPOSE). This effectively smashed the background calculation for ! * 16-bit output because the 8-bit table assumes the result will be ! * reduced to 8 bits. */ if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1);
*** 4251,4265 **** png_set_option(png_structrp png_ptr, int option, int onoff) { if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT && (option & 1) == 0) { ! int mask = 3 << option; ! int setting = (2 + (onoff != 0)) << option; ! int current = png_ptr->options; ! png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff); return (current & mask) >> option; } return PNG_OPTION_INVALID; --- 4286,4300 ---- png_set_option(png_structrp png_ptr, int option, int onoff) { if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT && (option & 1) == 0) { ! png_uint_32 mask = 3 << option; ! png_uint_32 setting = (2 + (onoff != 0)) << option; ! png_uint_32 current = png_ptr->options; ! png_ptr->options = (png_uint_32)(((current & ~mask) | setting) & 0xff); return (current & mask) >> option; } return PNG_OPTION_INVALID;
< prev index next >