comparison src/share/native/sun/awt/libpng/pngread.c @ 13266:2be5b7a7bf0e

8208353: Upgrade JDK 8u to libpng 1.6.35 Reviewed-by: serb, jdv
author prr
date Wed, 01 Aug 2018 11:16:50 -0700
parents 9fd2a2019a5b
children 5d57817931e1
comparison
equal deleted inserted replaced
7:b5449fe25894 8:a1ce1716e520
27 * This file is available under and governed by the GNU General Public 27 * This file is available under and governed by the GNU General Public
28 * License version 2 only, as published by the Free Software Foundation. 28 * License version 2 only, as published by the Free Software Foundation.
29 * However, the following notice accompanied the original version of this 29 * However, the following notice accompanied the original version of this
30 * file and, per its terms, should not be removed: 30 * file and, per its terms, should not be removed:
31 * 31 *
32 * Last changed in libpng 1.6.26 [October 20, 2016] 32 * Last changed in libpng 1.6.35 [July 15, 2018]
33 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson 33 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
36 * 36 *
37 * This code is released under the libpng license. 37 * This code is released under the libpng license.
38 * For conditions of distribution and use, see the disclaimer 38 * For conditions of distribution and use, see the disclaimer
201 #ifdef PNG_READ_cHRM_SUPPORTED 201 #ifdef PNG_READ_cHRM_SUPPORTED
202 else if (chunk_name == png_cHRM) 202 else if (chunk_name == png_cHRM)
203 png_handle_cHRM(png_ptr, info_ptr, length); 203 png_handle_cHRM(png_ptr, info_ptr, length);
204 #endif 204 #endif
205 205
206 #ifdef PNG_READ_eXIf_SUPPORTED
207 else if (chunk_name == png_eXIf)
208 png_handle_eXIf(png_ptr, info_ptr, length);
209 #endif
210
206 #ifdef PNG_READ_gAMA_SUPPORTED 211 #ifdef PNG_READ_gAMA_SUPPORTED
207 else if (chunk_name == png_gAMA) 212 else if (chunk_name == png_gAMA)
208 png_handle_gAMA(png_ptr, info_ptr, length); 213 png_handle_gAMA(png_ptr, info_ptr, length);
209 #endif 214 #endif
210 215
560 565
561 if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) 566 if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
562 png_error(png_ptr, "Invalid attempt to read row data"); 567 png_error(png_ptr, "Invalid attempt to read row data");
563 568
564 /* Fill the row with IDAT data: */ 569 /* Fill the row with IDAT data: */
570 png_ptr->row_buf[0]=255; /* to force error if no data was found */
565 png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1); 571 png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1);
566 572
567 if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) 573 if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
568 { 574 {
569 if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) 575 if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
868 #ifdef PNG_READ_cHRM_SUPPORTED 874 #ifdef PNG_READ_cHRM_SUPPORTED
869 else if (chunk_name == png_cHRM) 875 else if (chunk_name == png_cHRM)
870 png_handle_cHRM(png_ptr, info_ptr, length); 876 png_handle_cHRM(png_ptr, info_ptr, length);
871 #endif 877 #endif
872 878
879 #ifdef PNG_READ_eXIf_SUPPORTED
880 else if (chunk_name == png_eXIf)
881 png_handle_eXIf(png_ptr, info_ptr, length);
882 #endif
883
873 #ifdef PNG_READ_gAMA_SUPPORTED 884 #ifdef PNG_READ_gAMA_SUPPORTED
874 else if (chunk_name == png_gAMA) 885 else if (chunk_name == png_gAMA)
875 png_handle_gAMA(png_ptr, info_ptr, length); 886 png_handle_gAMA(png_ptr, info_ptr, length);
876 #endif 887 #endif
877 888
1547 return 0; 1558 return 0;
1548 } 1559 }
1549 #endif /* STDIO */ 1560 #endif /* STDIO */
1550 1561
1551 static void PNGCBAPI 1562 static void PNGCBAPI
1552 png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) 1563 png_image_memory_read(png_structp png_ptr, png_bytep out, size_t need)
1553 { 1564 {
1554 if (png_ptr != NULL) 1565 if (png_ptr != NULL)
1555 { 1566 {
1556 png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr); 1567 png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr);
1557 if (image != NULL) 1568 if (image != NULL)
1558 { 1569 {
1559 png_controlp cp = image->opaque; 1570 png_controlp cp = image->opaque;
1560 if (cp != NULL) 1571 if (cp != NULL)
1561 { 1572 {
1562 png_const_bytep memory = cp->memory; 1573 png_const_bytep memory = cp->memory;
1563 png_size_t size = cp->size; 1574 size_t size = cp->size;
1564 1575
1565 if (memory != NULL && size >= need) 1576 if (memory != NULL && size >= need)
1566 { 1577 {
1567 memcpy(out, memory, need); 1578 memcpy(out, memory, need);
1568 cp->memory = memory + need; 1579 cp->memory = memory + need;
1577 png_error(png_ptr, "invalid memory read"); 1588 png_error(png_ptr, "invalid memory read");
1578 } 1589 }
1579 } 1590 }
1580 1591
1581 int PNGAPI png_image_begin_read_from_memory(png_imagep image, 1592 int PNGAPI png_image_begin_read_from_memory(png_imagep image,
1582 png_const_voidp memory, png_size_t size) 1593 png_const_voidp memory, size_t size)
1583 { 1594 {
1584 if (image != NULL && image->version == PNG_IMAGE_VERSION) 1595 if (image != NULL && image->version == PNG_IMAGE_VERSION)
1585 { 1596 {
1586 if (memory != NULL && size > 0) 1597 if (memory != NULL && size > 0)
1587 { 1598 {
1909 */ 1920 */
1910 switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) 1921 switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))
1911 { 1922 {
1912 case 4: 1923 case 4:
1913 entry[afirst ? 0 : 3] = (png_uint_16)alpha; 1924 entry[afirst ? 0 : 3] = (png_uint_16)alpha;
1914 /* FALL THROUGH */ 1925 /* FALLTHROUGH */
1915 1926
1916 case 3: 1927 case 3:
1917 if (alpha < 65535) 1928 if (alpha < 65535)
1918 { 1929 {
1919 if (alpha > 0) 1930 if (alpha > 0)
1931 entry[afirst + bgr] = (png_uint_16)red; 1942 entry[afirst + bgr] = (png_uint_16)red;
1932 break; 1943 break;
1933 1944
1934 case 2: 1945 case 2:
1935 entry[1 ^ afirst] = (png_uint_16)alpha; 1946 entry[1 ^ afirst] = (png_uint_16)alpha;
1936 /* FALL THROUGH */ 1947 /* FALLTHROUGH */
1937 1948
1938 case 1: 1949 case 1:
1939 if (alpha < 65535) 1950 if (alpha < 65535)
1940 { 1951 {
1941 if (alpha > 0) 1952 if (alpha > 0)
1960 1971
1961 switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) 1972 switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))
1962 { 1973 {
1963 case 4: 1974 case 4:
1964 entry[afirst ? 0 : 3] = (png_byte)alpha; 1975 entry[afirst ? 0 : 3] = (png_byte)alpha;
1976 /* FALLTHROUGH */
1965 case 3: 1977 case 3:
1966 entry[afirst + (2 ^ bgr)] = (png_byte)blue; 1978 entry[afirst + (2 ^ bgr)] = (png_byte)blue;
1967 entry[afirst + 1] = (png_byte)green; 1979 entry[afirst + 1] = (png_byte)green;
1968 entry[afirst + bgr] = (png_byte)red; 1980 entry[afirst + bgr] = (png_byte)red;
1969 break; 1981 break;
1970 1982
1971 case 2: 1983 case 2:
1972 entry[1 ^ afirst] = (png_byte)alpha; 1984 entry[1 ^ afirst] = (png_byte)alpha;
1985 /* FALLTHROUGH */
1973 case 1: 1986 case 1:
1974 entry[afirst] = (png_byte)green; 1987 entry[afirst] = (png_byte)green;
1975 break; 1988 break;
1976 1989
1977 default: 1990 default:
2887 switch (data_encoding) 2900 switch (data_encoding)
2888 { 2901 {
2889 case P_sRGB: 2902 case P_sRGB:
2890 /* Change to 8-bit sRGB */ 2903 /* Change to 8-bit sRGB */
2891 png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB); 2904 png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
2892 /* FALL THROUGH */ 2905 /* FALLTHROUGH */
2893 2906
2894 case P_FILE: 2907 case P_FILE:
2895 if (png_ptr->bit_depth > 8) 2908 if (png_ptr->bit_depth > 8)
2896 png_set_scale_16(png_ptr); 2909 png_set_scale_16(png_ptr);
2897 break; 2910 break;
3205 info_ptr->bit_depth == 8 && 3218 info_ptr->bit_depth == 8 &&
3206 png_ptr->screen_gamma == PNG_GAMMA_sRGB && 3219 png_ptr->screen_gamma == PNG_GAMMA_sRGB &&
3207 image->colormap_entries == 244 /* 216 + 1 + 27 */) 3220 image->colormap_entries == 244 /* 216 + 1 + 27 */)
3208 break; 3221 break;
3209 3222
3210 /* goto bad_output; */ 3223 goto bad_output;
3211 /* FALL THROUGH */
3212 3224
3213 default: 3225 default:
3214 bad_output: 3226 bad_output:
3215 png_error(png_ptr, "bad color-map processing (internal error)"); 3227 png_error(png_ptr, "bad color-map processing (internal error)");
3216 } 3228 }
3774 { 3786 {
3775 mode = PNG_ALPHA_PNG; 3787 mode = PNG_ALPHA_PNG;
3776 output_gamma = PNG_DEFAULT_sRGB; 3788 output_gamma = PNG_DEFAULT_sRGB;
3777 } 3789 }
3778 3790
3791 if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0)
3792 {
3793 mode = PNG_ALPHA_OPTIMIZED;
3794 change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
3795 }
3796
3779 /* If 'do_local_background' is set check for the presence of gamma 3797 /* If 'do_local_background' is set check for the presence of gamma
3780 * correction; this is part of the work-round for the libpng bug 3798 * correction; this is part of the work-round for the libpng bug
3781 * described above. 3799 * described above.
3782 * 3800 *
3783 * TODO: fix libpng and remove this. 3801 * TODO: fix libpng and remove this.
3998 } 4016 }
3999 } 4017 }
4000 4018
4001 else if (do_local_compose != 0) /* internal error */ 4019 else if (do_local_compose != 0) /* internal error */
4002 png_error(png_ptr, "png_image_read: alpha channel lost"); 4020 png_error(png_ptr, "png_image_read: alpha channel lost");
4021
4022 if ((format & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) {
4023 info_format |= PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
4024 }
4003 4025
4004 if (info_ptr->bit_depth == 16) 4026 if (info_ptr->bit_depth == 16)
4005 info_format |= PNG_FORMAT_FLAG_LINEAR; 4027 info_format |= PNG_FORMAT_FLAG_LINEAR;
4006 4028
4007 #ifdef PNG_FORMAT_BGR_SUPPORTED 4029 #ifdef PNG_FORMAT_BGR_SUPPORTED
4154 * number of *bytes* that the application is saying are available 4176 * number of *bytes* that the application is saying are available
4155 * does actually fit into a 32-bit number. 4177 * does actually fit into a 32-bit number.
4156 * 4178 *
4157 * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE 4179 * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE
4158 * will be changed to use png_alloc_size_t; bigger images can be 4180 * will be changed to use png_alloc_size_t; bigger images can be
4159 * accomodated on 64-bit systems. 4181 * accommodated on 64-bit systems.
4160 */ 4182 */
4161 if (image->height <= 4183 if (image->height <=
4162 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check) 4184 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check)
4163 { 4185 {
4164 if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 || 4186 if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 ||