< prev index next >

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

Print this page

        

*** 27,37 **** * 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.23 [June 9, 2016] * Copyright (c) 1998-2002,2004,2006-2016 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. --- 27,37 ---- * 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.26 [October 20, 2016] * Copyright (c) 1998-2002,2004,2006-2016 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.
*** 385,397 **** else return; for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) { ! png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); ! png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); ! png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); png_uint_32 red = (s0 + s1 + 65536) & 0xffff; png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; *(rp ) = (png_byte)((red >> 8) & 0xff); *(rp + 1) = (png_byte)(red & 0xff); *(rp + 4) = (png_byte)((blue >> 8) & 0xff); --- 385,397 ---- else return; for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) { ! png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1); ! png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3); ! png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5); png_uint_32 red = (s0 + s1 + 65536) & 0xffff; png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; *(rp ) = (png_byte)((red >> 8) & 0xff); *(rp + 1) = (png_byte)(red & 0xff); *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
*** 1056,1067 **** #ifdef PNG_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_INFO_IMAGE_SUPPORTED void PNGAPI png_read_png(png_structrp png_ptr, png_inforp info_ptr, ! int transforms, ! voidp params) { if (png_ptr == NULL || info_ptr == NULL) return; /* png_read_info() gives us all of the information from the --- 1056,1066 ---- #ifdef PNG_SEQUENTIAL_READ_SUPPORTED #ifdef PNG_INFO_IMAGE_SUPPORTED void PNGAPI png_read_png(png_structrp png_ptr, png_inforp info_ptr, ! int transforms, voidp params) { if (png_ptr == NULL || info_ptr == NULL) return; /* png_read_info() gives us all of the information from the
*** 1420,1430 **** --- 1419,1431 ---- { png_imagep image = png_voidcast(png_imagep, argument); png_structrp png_ptr = image->opaque->png_ptr; png_inforp info_ptr = image->opaque->info_ptr; + #ifdef PNG_BENIGN_ERRORS_SUPPORTED png_set_benign_errors(png_ptr, 1/*warn*/); + #endif png_read_info(png_ptr, info_ptr); /* Do this the fast way; just read directly out of png_struct. */ image->width = png_ptr->width; image->height = png_ptr->height;
*** 1458,1468 **** case PNG_COLOR_TYPE_GRAY: cmap_entries = 1U << png_ptr->bit_depth; break; case PNG_COLOR_TYPE_PALETTE: ! cmap_entries = png_ptr->num_palette; break; default: cmap_entries = 256; break; --- 1459,1469 ---- case PNG_COLOR_TYPE_GRAY: cmap_entries = 1U << png_ptr->bit_depth; break; case PNG_COLOR_TYPE_PALETTE: ! cmap_entries = (png_uint_32)png_ptr->num_palette; break; default: cmap_entries = 256; break;
*** 1993,2014 **** unsigned int i; for (i=0; i<256; ++i) png_create_colormap_entry(display, i, i, i, i, 255, P_FILE); ! return i; } static int make_gray_colormap(png_image_read_control *display) { unsigned int i; for (i=0; i<256; ++i) png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB); ! return i; } #define PNG_GRAY_COLORMAP_ENTRIES 256 static int make_ga_colormap(png_image_read_control *display) --- 1994,2015 ---- unsigned int i; for (i=0; i<256; ++i) png_create_colormap_entry(display, i, i, i, i, 255, P_FILE); ! return (int)i; } static int make_gray_colormap(png_image_read_control *display) { unsigned int i; for (i=0; i<256; ++i) png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB); ! return (int)i; } #define PNG_GRAY_COLORMAP_ENTRIES 256 static int make_ga_colormap(png_image_read_control *display)
*** 2058,2068 **** for (g=0; g<6; ++g) png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51, P_sRGB); } ! return i; } #define PNG_GA_COLORMAP_ENTRIES 256 static int --- 2059,2069 ---- for (g=0; g<6; ++g) png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51, P_sRGB); } ! return (int)i; } #define PNG_GA_COLORMAP_ENTRIES 256 static int
*** 2083,2093 **** png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255, P_sRGB); } } ! return i; } #define PNG_RGB_COLORMAP_ENTRIES 216 /* Return a palette index to the above palette given three 8-bit sRGB values. */ --- 2084,2094 ---- png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255, P_sRGB); } } ! return (int)i; } #define PNG_RGB_COLORMAP_ENTRIES 216 /* Return a palette index to the above palette given three 8-bit sRGB values. */
*** 2131,2141 **** if (output_encoding == P_LINEAR) /* compose on black */ back_b = back_g = back_r = 0; else if (display->background == NULL /* no way to remove it */) png_error(png_ptr, ! "a background color must be supplied to remove alpha/transparency"); /* Get a copy of the background color (this avoids repeating the checks * below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the * output format. */ --- 2132,2142 ---- if (output_encoding == P_LINEAR) /* compose on black */ back_b = back_g = back_r = 0; else if (display->background == NULL /* no way to remove it */) png_error(png_ptr, ! "background color must be supplied to remove alpha/transparency"); /* Get a copy of the background color (this avoids repeating the checks * below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the * output format. */
*** 2276,2286 **** data_encoding = P_sRGB; if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray[16] color-map: too few entries"); ! cmap_entries = make_gray_colormap(display); if (png_ptr->num_trans > 0) { unsigned int back_alpha; --- 2277,2287 ---- data_encoding = P_sRGB; if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray[16] color-map: too few entries"); ! cmap_entries = (unsigned int)make_gray_colormap(display); if (png_ptr->num_trans > 0) { unsigned int back_alpha;
*** 2374,2384 **** if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) { if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray+alpha color-map: too few entries"); ! cmap_entries = make_ga_colormap(display); background_index = PNG_CMAP_GA_BACKGROUND; output_processing = PNG_CMAP_GA; } --- 2375,2385 ---- if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) { if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray+alpha color-map: too few entries"); ! cmap_entries = (unsigned int)make_ga_colormap(display); background_index = PNG_CMAP_GA_BACKGROUND; output_processing = PNG_CMAP_GA; }
*** 2408,2418 **** png_uint_32 gray = back_g; if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray-alpha color-map: too few entries"); ! cmap_entries = make_gray_colormap(display); if (output_encoding == P_LINEAR) { gray = PNG_sRGB_FROM_LINEAR(gray * 255); --- 2409,2419 ---- png_uint_32 gray = back_g; if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "gray-alpha color-map: too few entries"); ! cmap_entries = (unsigned int)make_gray_colormap(display); if (output_encoding == P_LINEAR) { gray = PNG_sRGB_FROM_LINEAR(gray * 255);
*** 2456,2467 **** * background color. */ background_index = i; png_create_colormap_entry(display, i++, back_r, back_g, back_b, #ifdef __COVERITY__ ! /* Coverity claims that output_encoding cannot be 2 (P_LINEAR) ! * here. */ 255U, #else output_encoding == P_LINEAR ? 65535U : 255U, #endif output_encoding); --- 2457,2468 ---- * background color. */ background_index = i; png_create_colormap_entry(display, i++, back_r, back_g, back_b, #ifdef __COVERITY__ ! /* Coverity claims that output_encoding ! * cannot be 2 (P_LINEAR) here. */ 255U, #else output_encoding == P_LINEAR ? 65535U : 255U, #endif output_encoding);
*** 2547,2557 **** expand_tRNS = 1; if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "rgb[ga] color-map: too few entries"); ! cmap_entries = make_ga_colormap(display); background_index = PNG_CMAP_GA_BACKGROUND; output_processing = PNG_CMAP_GA; } else --- 2548,2558 ---- expand_tRNS = 1; if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "rgb[ga] color-map: too few entries"); ! cmap_entries = (unsigned int)make_ga_colormap(display); background_index = PNG_CMAP_GA_BACKGROUND; output_processing = PNG_CMAP_GA; } else
*** 2573,2588 **** */ if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || png_ptr->num_trans > 0) && png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0) { ! cmap_entries = make_gray_file_colormap(display); data_encoding = P_FILE; } else ! cmap_entries = make_gray_colormap(display); /* But if the input has alpha or transparency it must be removed */ if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || png_ptr->num_trans > 0) --- 2574,2589 ---- */ if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || png_ptr->num_trans > 0) && png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0) { ! cmap_entries = (unsigned int)make_gray_file_colormap(display); data_encoding = P_FILE; } else ! cmap_entries = (unsigned int)make_gray_colormap(display); /* But if the input has alpha or transparency it must be removed */ if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || png_ptr->num_trans > 0)
*** 2666,2676 **** png_uint_32 r; if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) png_error(png_ptr, "rgb+alpha color-map: too few entries"); ! cmap_entries = make_rgb_colormap(display); /* Add a transparent entry. */ png_create_colormap_entry(display, cmap_entries, 255, 255, 255, 0, P_sRGB); --- 2667,2677 ---- png_uint_32 r; if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) png_error(png_ptr, "rgb+alpha color-map: too few entries"); ! cmap_entries = (unsigned int)make_rgb_colormap(display); /* Add a transparent entry. */ png_create_colormap_entry(display, cmap_entries, 255, 255, 255, 0, P_sRGB);
*** 2715,2725 **** png_uint_32 r, g, b; /* sRGB background */ if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) png_error(png_ptr, "rgb-alpha color-map: too few entries"); ! cmap_entries = make_rgb_colormap(display); png_create_colormap_entry(display, cmap_entries, back_r, back_g, back_b, 0/*unused*/, output_encoding); if (output_encoding == P_LINEAR) --- 2716,2726 ---- png_uint_32 r, g, b; /* sRGB background */ if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) png_error(png_ptr, "rgb-alpha color-map: too few entries"); ! cmap_entries = (unsigned int)make_rgb_colormap(display); png_create_colormap_entry(display, cmap_entries, back_r, back_g, back_b, 0/*unused*/, output_encoding); if (output_encoding == P_LINEAR)
*** 2800,2810 **** * pixels to the 6x6x6 color-map. */ if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "rgb color-map: too few entries"); ! cmap_entries = make_rgb_colormap(display); output_processing = PNG_CMAP_RGB; } } break; --- 2801,2811 ---- * pixels to the 6x6x6 color-map. */ if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries) png_error(png_ptr, "rgb color-map: too few entries"); ! cmap_entries = (unsigned int)make_rgb_colormap(display); output_processing = PNG_CMAP_RGB; } } break;
*** 2824,2838 **** if (trans == NULL) num_trans = 0; output_processing = PNG_CMAP_NONE; data_encoding = P_FILE; /* Don't change from color-map indices */ ! cmap_entries = png_ptr->num_palette; if (cmap_entries > 256) cmap_entries = 256; ! if (cmap_entries > image->colormap_entries) png_error(png_ptr, "palette color-map: too few entries"); for (i=0; i < cmap_entries; ++i) { if (do_background != 0 && i < num_trans && trans[i] < 255) --- 2825,2839 ---- if (trans == NULL) num_trans = 0; output_processing = PNG_CMAP_NONE; data_encoding = P_FILE; /* Don't change from color-map indices */ ! cmap_entries = (unsigned int)png_ptr->num_palette; if (cmap_entries > 256) cmap_entries = 256; ! if (cmap_entries > (unsigned int)image->colormap_entries) png_error(png_ptr, "palette color-map: too few entries"); for (i=0; i < cmap_entries; ++i) { if (do_background != 0 && i < num_trans && trans[i] < 255)
*** 2845,2860 **** { /* Must compose the PNG file color in the color-map entry * on the sRGB color in 'back'. */ png_create_colormap_entry(display, i, ! png_colormap_compose(display, colormap[i].red, P_FILE, ! trans[i], back_r, output_encoding), ! png_colormap_compose(display, colormap[i].green, P_FILE, ! trans[i], back_g, output_encoding), ! png_colormap_compose(display, colormap[i].blue, P_FILE, ! trans[i], back_b, output_encoding), output_encoding == P_LINEAR ? trans[i] * 257U : trans[i], output_encoding); } } --- 2846,2861 ---- { /* Must compose the PNG file color in the color-map entry * on the sRGB color in 'back'. */ png_create_colormap_entry(display, i, ! png_colormap_compose(display, colormap[i].red, ! P_FILE, trans[i], back_r, output_encoding), ! png_colormap_compose(display, colormap[i].green, ! P_FILE, trans[i], back_g, output_encoding), ! png_colormap_compose(display, colormap[i].blue, ! P_FILE, trans[i], back_b, output_encoding), output_encoding == P_LINEAR ? trans[i] * 257U : trans[i], output_encoding); } }
*** 2940,2950 **** bad_background: png_error(png_ptr, "bad background index (internal error)"); } ! display->colormap_processing = output_processing; return 1/*ok*/; } /* The final part of the color-map read called from png_image_finish_read. */ --- 2941,2951 ---- bad_background: png_error(png_ptr, "bad background index (internal error)"); } ! display->colormap_processing = (int)output_processing; return 1/*ok*/; } /* The final part of the color-map read called from png_image_finish_read. */
*** 3249,3266 **** return result; } else { ! png_alloc_size_t row_bytes = display->row_bytes; while (--passes >= 0) { png_uint_32 y = image->height; png_bytep row = png_voidcast(png_bytep, display->first_row); ! while (y-- > 0) { png_read_row(png_ptr, row, NULL); row += row_bytes; } } --- 3250,3267 ---- return result; } else { ! png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes; while (--passes >= 0) { png_uint_32 y = image->height; png_bytep row = png_voidcast(png_bytep, display->first_row); ! for (; y > 0; --y) { png_read_row(png_ptr, row, NULL); row += row_bytes; } }
*** 3459,3470 **** png_bytep first_row = png_voidcast(png_bytep, display->first_row); ptrdiff_t step_row = display->row_bytes; for (pass = 0; pass < passes; ++pass) { ! png_bytep row = png_voidcast(png_bytep, ! display->first_row); unsigned int startx, stepx, stepy; png_uint_32 y; if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) { --- 3460,3470 ---- png_bytep first_row = png_voidcast(png_bytep, display->first_row); ptrdiff_t step_row = display->row_bytes; for (pass = 0; pass < passes; ++pass) { ! png_bytep row = png_voidcast(png_bytep, display->first_row); unsigned int startx, stepx, stepy; png_uint_32 y; if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) {
*** 3585,3596 **** display->first_row); /* The division by two is safe because the caller passed in a * stride which was multiplied by 2 (below) to get row_bytes. */ ptrdiff_t step_row = display->row_bytes / 2; ! int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0; ! unsigned int outchannels = 1+preserve_alpha; int swap_alpha = 0; # ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED if (preserve_alpha != 0 && (image->format & PNG_FORMAT_FLAG_AFIRST) != 0) --- 3585,3597 ---- display->first_row); /* The division by two is safe because the caller passed in a * stride which was multiplied by 2 (below) to get row_bytes. */ ptrdiff_t step_row = display->row_bytes / 2; ! unsigned int preserve_alpha = (image->format & ! PNG_FORMAT_FLAG_ALPHA) != 0; ! unsigned int outchannels = 1U+preserve_alpha; int swap_alpha = 0; # ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED if (preserve_alpha != 0 && (image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
*** 4083,4100 **** return result; } else { ! png_alloc_size_t row_bytes = display->row_bytes; while (--passes >= 0) { png_uint_32 y = image->height; png_bytep row = png_voidcast(png_bytep, display->first_row); ! while (y-- > 0) { png_read_row(png_ptr, row, NULL); row += row_bytes; } } --- 4084,4101 ---- return result; } else { ! png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes; while (--passes >= 0) { png_uint_32 y = image->height; png_bytep row = png_voidcast(png_bytep, display->first_row); ! for (; y > 0; --y) { png_read_row(png_ptr, row, NULL); row += row_bytes; } }
*** 4113,4143 **** * original PNG format because it may not occur in the output PNG format * and libpng deals with the issues of reading the original. */ const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format); ! if (image->width <= 0x7FFFFFFFU/channels) /* no overflow */ { png_uint_32 check; const png_uint_32 png_row_stride = image->width * channels; if (row_stride == 0) row_stride = (png_int_32)/*SAFE*/png_row_stride; if (row_stride < 0) ! check = -row_stride; else ! check = row_stride; if (image->opaque != NULL && buffer != NULL && check >= png_row_stride) { /* Now check for overflow of the image buffer calculation; this * limits the whole image size to 32 bits for API compatibility with * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro. */ ! if (image->height <= 0xFFFFFFFF/png_row_stride) { if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 || (image->colormap_entries > 0 && colormap != NULL)) { int result; --- 4114,4167 ---- * original PNG format because it may not occur in the output PNG format * and libpng deals with the issues of reading the original. */ const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format); ! /* The following checks just the 'row_stride' calculation to ensure it ! * fits in a signed 32-bit value. Because channels/components can be ! * either 1 or 2 bytes in size the length of a row can still overflow 32 ! * bits; this is just to verify that the 'row_stride' argument can be ! * represented. ! */ ! if (image->width <= 0x7fffffffU/channels) /* no overflow */ { png_uint_32 check; const png_uint_32 png_row_stride = image->width * channels; if (row_stride == 0) row_stride = (png_int_32)/*SAFE*/png_row_stride; if (row_stride < 0) ! check = (png_uint_32)(-row_stride); else ! check = (png_uint_32)row_stride; + /* This verifies 'check', the absolute value of the actual stride + * passed in and detects overflow in the application calculation (i.e. + * if the app did actually pass in a non-zero 'row_stride'. + */ if (image->opaque != NULL && buffer != NULL && check >= png_row_stride) { /* Now check for overflow of the image buffer calculation; this * limits the whole image size to 32 bits for API compatibility with * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro. + * + * The PNG_IMAGE_BUFFER_SIZE macro is: + * + * (PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)*height*(row_stride)) + * + * And the component size is always 1 or 2, so make sure that the + * number of *bytes* that the application is saying are available + * does actually fit into a 32-bit number. + * + * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE + * will be changed to use png_alloc_size_t; bigger images can be + * accomodated on 64-bit systems. */ ! if (image->height <= ! 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check) { if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 || (image->colormap_entries > 0 && colormap != NULL)) { int result;
*** 4153,4163 **** /* Choose the correct 'end' routine; for the color-map case * all the setup has already been done. */ if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0) ! result = png_safe_execute(image, png_image_read_colormap, &display) && png_safe_execute(image, png_image_read_colormapped, &display); else --- 4177,4188 ---- /* Choose the correct 'end' routine; for the color-map case * all the setup has already been done. */ if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0) ! result = ! png_safe_execute(image, png_image_read_colormap, &display) && png_safe_execute(image, png_image_read_colormapped, &display); else
< prev index next >