|
@@ -1,8 +1,8 @@
|
|
|
|
|
|
/* pngrutil.c - utilities to read a PNG file
|
|
|
*
|
|
|
- * Last changed in libpng 1.6.25 [September 1, 2016]
|
|
|
- * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
|
|
+ * Last changed in libpng 1.6.32 [August 24, 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.)
|
|
|
*
|
|
@@ -86,7 +86,7 @@ png_get_int_32)(png_const_bytep buf)
|
|
|
{
|
|
|
png_uint_32 uval = png_get_uint_32(buf);
|
|
|
if ((uval & 0x80000000) == 0) /* non-negative */
|
|
|
- return uval;
|
|
|
+ return (png_int_32)uval;
|
|
|
|
|
|
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
|
|
|
if ((uval & 0x80000000) == 0) /* no overflow */
|
|
@@ -181,6 +181,9 @@ png_read_chunk_header(png_structrp png_ptr)
|
|
|
/* Check to see if chunk name is valid. */
|
|
|
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
|
|
|
|
|
+ /* Check for too-large chunk length */
|
|
|
+ png_check_chunk_length(png_ptr, length);
|
|
|
+
|
|
|
#ifdef PNG_IO_STATE_SUPPORTED
|
|
|
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
|
|
|
#endif
|
|
@@ -370,11 +373,10 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|
|
*/
|
|
|
{
|
|
|
int ret; /* zlib return code */
|
|
|
-#if PNG_ZLIB_VERNUM >= 0x1240
|
|
|
+#if ZLIB_VERNUM >= 0x1240
|
|
|
+ int window_bits = 0;
|
|
|
|
|
|
# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
|
|
|
- int window_bits;
|
|
|
-
|
|
|
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
|
|
|
PNG_OPTION_ON)
|
|
|
{
|
|
@@ -384,13 +386,11 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|
|
|
|
|
else
|
|
|
{
|
|
|
- window_bits = 0;
|
|
|
png_ptr->zstream_start = 1;
|
|
|
}
|
|
|
-# else
|
|
|
-# define window_bits 0
|
|
|
# endif
|
|
|
-#endif
|
|
|
+
|
|
|
+#endif /* ZLIB_VERNUM >= 0x1240 */
|
|
|
|
|
|
/* Set this for safety, just in case the previous owner left pointers to
|
|
|
* memory allocations.
|
|
@@ -402,25 +402,32 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|
|
|
|
|
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
|
|
|
{
|
|
|
-#if PNG_ZLIB_VERNUM < 0x1240
|
|
|
- ret = inflateReset(&png_ptr->zstream);
|
|
|
-#else
|
|
|
+#if ZLIB_VERNUM >= 0x1240
|
|
|
ret = inflateReset2(&png_ptr->zstream, window_bits);
|
|
|
+#else
|
|
|
+ ret = inflateReset(&png_ptr->zstream);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
else
|
|
|
{
|
|
|
-#if PNG_ZLIB_VERNUM < 0x1240
|
|
|
- ret = inflateInit(&png_ptr->zstream);
|
|
|
-#else
|
|
|
+#if ZLIB_VERNUM >= 0x1240
|
|
|
ret = inflateInit2(&png_ptr->zstream, window_bits);
|
|
|
+#else
|
|
|
+ ret = inflateInit(&png_ptr->zstream);
|
|
|
#endif
|
|
|
|
|
|
if (ret == Z_OK)
|
|
|
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
|
|
|
}
|
|
|
|
|
|
+#if ZLIB_VERNUM >= 0x1290 && \
|
|
|
+ defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
|
|
|
+ if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
|
|
|
+ /* Turn off validation of the ADLER32 checksum in IDAT chunks */
|
|
|
+ ret = inflateValidate(&png_ptr->zstream, 0);
|
|
|
+#endif
|
|
|
+
|
|
|
if (ret == Z_OK)
|
|
|
png_ptr->zowner = owner;
|
|
|
|
|
@@ -435,7 +442,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-#if PNG_ZLIB_VERNUM >= 0x1240
|
|
|
+#if ZLIB_VERNUM >= 0x1240
|
|
|
/* Handle the start of the inflate stream if we called inflateInit2(strm,0);
|
|
|
* in this case some zlib versions skip validation of the CINFO field and, in
|
|
|
* certain circumstances, libpng may end up displaying an invalid image, in
|
|
@@ -713,7 +720,7 @@ png_decompress_chunk(png_structrp png_ptr,
|
|
|
* the extra space may otherwise be used as a Trojan Horse.
|
|
|
*/
|
|
|
if (ret == Z_STREAM_END &&
|
|
|
- chunklength - prefix_size != lzsize)
|
|
|
+ chunklength - prefix_size != lzsize)
|
|
|
png_chunk_benign_error(png_ptr, "extra compressed data");
|
|
|
}
|
|
|
|
|
@@ -823,7 +830,7 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
|
|
|
return Z_STREAM_ERROR;
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
+#endif /* READ_iCCP */
|
|
|
|
|
|
/* Read and check the IDHR chunk */
|
|
|
|
|
@@ -1011,7 +1018,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
|
|
#endif
|
|
|
{
|
|
|
- png_crc_finish(png_ptr, (int) length - num * 3);
|
|
|
+ png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3));
|
|
|
}
|
|
|
|
|
|
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
|
|
@@ -1373,11 +1380,13 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
* chunk is just ignored, so does not invalidate the color space. An
|
|
|
* alternative is to set the 'invalid' flags at the start of this routine
|
|
|
* and only clear them in they were not set before and all the tests pass.
|
|
|
- * The minimum 'deflate' stream is assumed to be just the 2 byte header and
|
|
|
- * 4 byte checksum. The keyword must be at least one character and there is
|
|
|
- * a terminator (0) byte and the compression method.
|
|
|
*/
|
|
|
- if (length < 9)
|
|
|
+
|
|
|
+ /* The keyword must be at least one character and there is a
|
|
|
+ * terminator (0) byte and the compression method byte, and the
|
|
|
+ * 'zlib' datastream is at least 11 bytes.
|
|
|
+ */
|
|
|
+ if (length < 14)
|
|
|
{
|
|
|
png_crc_finish(png_ptr, length);
|
|
|
png_chunk_benign_error(png_ptr, "too short");
|
|
@@ -1409,6 +1418,16 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
png_crc_read(png_ptr, (png_bytep)keyword, read_length);
|
|
|
length -= read_length;
|
|
|
|
|
|
+ /* The minimum 'zlib' stream is assumed to be just the 2 byte header,
|
|
|
+ * 5 bytes minimum 'deflate' stream, and the 4 byte checksum.
|
|
|
+ */
|
|
|
+ if (length < 11)
|
|
|
+ {
|
|
|
+ png_crc_finish(png_ptr, length);
|
|
|
+ png_chunk_benign_error(png_ptr, "too short");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
keyword_length = 0;
|
|
|
while (keyword_length < 80 && keyword_length < read_length &&
|
|
|
keyword[keyword_length] != 0)
|
|
@@ -1427,7 +1446,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
|
|
|
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
|
|
|
{
|
|
|
- Byte profile_header[132];
|
|
|
+ Byte profile_header[132]={0};
|
|
|
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
|
|
|
png_alloc_size_t size = (sizeof profile_header);
|
|
|
|
|
@@ -1717,13 +1736,13 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
data_length = length - (png_uint_32)(entry_start - buffer);
|
|
|
|
|
|
/* Integrity-check the data length */
|
|
|
- if ((data_length % entry_size) != 0)
|
|
|
+ if ((data_length % (unsigned int)entry_size) != 0)
|
|
|
{
|
|
|
png_warning(png_ptr, "sPLT chunk has bad length");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- dl = (png_int_32)(data_length / entry_size);
|
|
|
+ dl = (png_uint_32)(data_length / (unsigned int)entry_size);
|
|
|
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
|
|
|
|
|
|
if (dl > max_dl)
|
|
@@ -1732,10 +1751,10 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- new_palette.nentries = (png_int_32)(data_length / entry_size);
|
|
|
+ new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);
|
|
|
|
|
|
- new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
|
|
|
- png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));
|
|
|
+ new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
|
|
|
+ (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));
|
|
|
|
|
|
if (new_palette.entries == NULL)
|
|
|
{
|
|
@@ -2005,6 +2024,69 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+#ifdef PNG_READ_eXIf_SUPPORTED
|
|
|
+void /* PRIVATE */
|
|
|
+png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ png_debug(1, "in png_handle_eXIf");
|
|
|
+
|
|
|
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
|
|
+ png_chunk_error(png_ptr, "missing IHDR");
|
|
|
+
|
|
|
+ if (length < 2)
|
|
|
+ {
|
|
|
+ png_crc_finish(png_ptr, length);
|
|
|
+ png_chunk_benign_error(png_ptr, "too short");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0)
|
|
|
+ {
|
|
|
+ png_crc_finish(png_ptr, length);
|
|
|
+ png_chunk_benign_error(png_ptr, "duplicate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ info_ptr->free_me |= PNG_FREE_EXIF;
|
|
|
+
|
|
|
+ info_ptr->eXIf_buf = png_voidcast(png_bytep,
|
|
|
+ png_malloc_warn(png_ptr, length));
|
|
|
+
|
|
|
+ if (info_ptr->eXIf_buf == NULL)
|
|
|
+ {
|
|
|
+ png_crc_finish(png_ptr, length);
|
|
|
+ png_chunk_benign_error(png_ptr, "out of memory");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ png_byte buf[1];
|
|
|
+ png_crc_read(png_ptr, buf, 1);
|
|
|
+ info_ptr->eXIf_buf[i] = buf[0];
|
|
|
+ if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
|
|
|
+ && info_ptr->eXIf_buf[0] != buf[0])
|
|
|
+ {
|
|
|
+ png_crc_finish(png_ptr, length);
|
|
|
+ png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
|
|
|
+ png_free(png_ptr, info_ptr->eXIf_buf);
|
|
|
+ info_ptr->eXIf_buf = NULL;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (png_crc_finish(png_ptr, 0) != 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
|
|
|
+
|
|
|
+ png_free(png_ptr, info_ptr->eXIf_buf);
|
|
|
+ info_ptr->eXIf_buf = NULL;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
#ifdef PNG_READ_hIST_SUPPORTED
|
|
|
void /* PRIVATE */
|
|
|
png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
@@ -2533,6 +2615,9 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
|
|
png_ptr->mode |= PNG_AFTER_IDAT;
|
|
|
|
|
|
+ /* Note, "length" is sufficient here; we won't be adding
|
|
|
+ * a null terminator later.
|
|
|
+ */
|
|
|
buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
|
|
|
|
|
|
if (buffer == NULL)
|
|
@@ -2579,23 +2664,28 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
|
|
{
|
|
|
png_text text;
|
|
|
|
|
|
- /* It worked; png_ptr->read_buffer now looks like a tEXt chunk except
|
|
|
- * for the extra compression type byte and the fact that it isn't
|
|
|
- * necessarily '\0' terminated.
|
|
|
- */
|
|
|
- buffer = png_ptr->read_buffer;
|
|
|
- buffer[uncompressed_length+(keyword_length+2)] = 0;
|
|
|
-
|
|
|
- text.compression = PNG_TEXT_COMPRESSION_zTXt;
|
|
|
- text.key = (png_charp)buffer;
|
|
|
- text.text = (png_charp)(buffer + keyword_length+2);
|
|
|
- text.text_length = uncompressed_length;
|
|
|
- text.itxt_length = 0;
|
|
|
- text.lang = NULL;
|
|
|
- text.lang_key = NULL;
|
|
|
-
|
|
|
- if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
|
|
|
- errmsg = "insufficient memory";
|
|
|
+ if (png_ptr->read_buffer == NULL)
|
|
|
+ errmsg="Read failure in png_handle_zTXt";
|
|
|
+ else
|
|
|
+ {
|
|
|
+ /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
|
|
|
+ * except for the extra compression type byte and the fact that
|
|
|
+ * it isn't necessarily '\0' terminated.
|
|
|
+ */
|
|
|
+ buffer = png_ptr->read_buffer;
|
|
|
+ buffer[uncompressed_length+(keyword_length+2)] = 0;
|
|
|
+
|
|
|
+ text.compression = PNG_TEXT_COMPRESSION_zTXt;
|
|
|
+ text.key = (png_charp)buffer;
|
|
|
+ text.text = (png_charp)(buffer + keyword_length+2);
|
|
|
+ text.text_length = uncompressed_length;
|
|
|
+ text.itxt_length = 0;
|
|
|
+ text.lang = NULL;
|
|
|
+ text.lang_key = NULL;
|
|
|
+
|
|
|
+ if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
|
|
|
+ errmsg = "insufficient memory";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
else
|
|
@@ -2971,7 +3061,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|
|
case 2:
|
|
|
png_ptr->user_chunk_cache_max = 1;
|
|
|
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
|
|
- /* FALL THROUGH */
|
|
|
+ /* FALLTHROUGH */
|
|
|
case 1:
|
|
|
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical
|
|
|
* chunk being skipped, now there will be a hard error below.
|
|
@@ -2980,7 +3070,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|
|
|
|
|
default: /* not at limit */
|
|
|
--(png_ptr->user_chunk_cache_max);
|
|
|
- /* FALL THROUGH */
|
|
|
+ /* FALLTHROUGH */
|
|
|
case 0: /* no limit */
|
|
|
# endif /* USER_LIMITS */
|
|
|
/* Here when the limit isn't reached or when limits are compiled
|
|
@@ -3031,20 +3121,58 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
|
|
*/
|
|
|
|
|
|
void /* PRIVATE */
|
|
|
-png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name)
|
|
|
+png_check_chunk_name(png_const_structrp png_ptr, const png_uint_32 chunk_name)
|
|
|
{
|
|
|
int i;
|
|
|
+ png_uint_32 cn=chunk_name;
|
|
|
|
|
|
png_debug(1, "in png_check_chunk_name");
|
|
|
|
|
|
for (i=1; i<=4; ++i)
|
|
|
{
|
|
|
- int c = chunk_name & 0xff;
|
|
|
+ int c = cn & 0xff;
|
|
|
|
|
|
if (c < 65 || c > 122 || (c > 90 && c < 97))
|
|
|
png_chunk_error(png_ptr, "invalid chunk type");
|
|
|
|
|
|
- chunk_name >>= 8;
|
|
|
+ cn >>= 8;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void /* PRIVATE */
|
|
|
+png_check_chunk_length(png_const_structrp png_ptr, const png_uint_32 length)
|
|
|
+{
|
|
|
+ png_alloc_size_t limit = PNG_UINT_31_MAX;
|
|
|
+
|
|
|
+ if (png_ptr->chunk_name != png_IDAT)
|
|
|
+ {
|
|
|
+# ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
|
|
+ if (png_ptr->user_chunk_malloc_max > 0 &&
|
|
|
+ png_ptr->user_chunk_malloc_max < limit)
|
|
|
+ limit = png_ptr->user_chunk_malloc_max;
|
|
|
+# elif PNG_USER_CHUNK_MALLOC_MAX > 0
|
|
|
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)
|
|
|
+ limit = PNG_USER_CHUNK_MALLOC_MAX;
|
|
|
+# endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ size_t row_factor =
|
|
|
+ (png_ptr->width * png_ptr->channels * (png_ptr->bit_depth > 8? 2: 1)
|
|
|
+ + 1 + (png_ptr->interlaced? 6: 0));
|
|
|
+ if (png_ptr->height > PNG_UINT_32_MAX/row_factor)
|
|
|
+ limit=PNG_UINT_31_MAX;
|
|
|
+ else
|
|
|
+ limit = png_ptr->height * row_factor;
|
|
|
+ limit += 6 + 5*(limit/32566+1); /* zlib+deflate overhead */
|
|
|
+ limit=limit < PNG_UINT_31_MAX? limit : PNG_UINT_31_MAX;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (length > limit)
|
|
|
+ {
|
|
|
+ png_debug2(0," length = %lu, limit = %lu",
|
|
|
+ (unsigned long)length,(unsigned long)limit);
|
|
|
+ png_chunk_error(png_ptr, "chunk data is too large");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3099,7 +3227,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|
|
# ifdef PNG_READ_PACKSWAP_SUPPORTED
|
|
|
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
|
|
/* little-endian byte */
|
|
|
- end_mask = 0xff << end_mask;
|
|
|
+ end_mask = (unsigned int)(0xff << end_mask);
|
|
|
|
|
|
else /* big-endian byte */
|
|
|
# endif
|
|
@@ -3373,7 +3501,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|
|
*/
|
|
|
do
|
|
|
{
|
|
|
- dp[0] = sp[0], dp[1] = sp[1];
|
|
|
+ dp[0] = sp[0]; dp[1] = sp[1];
|
|
|
|
|
|
if (row_width <= bytes_to_jump)
|
|
|
return;
|
|
@@ -3394,7 +3522,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
|
|
*/
|
|
|
for (;;)
|
|
|
{
|
|
|
- dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
|
|
|
+ dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
|
|
|
|
|
|
if (row_width <= bytes_to_jump)
|
|
|
return;
|
|
@@ -3545,7 +3673,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
{
|
|
|
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
|
/* Offset to next interlace block */
|
|
|
- static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
|
+ static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
|
|
|
|
png_debug(1, "in png_do_read_interlace");
|
|
|
if (row != NULL && row_info != NULL)
|
|
@@ -3560,9 +3688,10 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
{
|
|
|
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
|
|
|
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
|
|
|
- int sshift, dshift;
|
|
|
- int s_start, s_end, s_inc;
|
|
|
- int jstop = png_pass_inc[pass];
|
|
|
+ unsigned int sshift, dshift;
|
|
|
+ unsigned int s_start, s_end;
|
|
|
+ int s_inc;
|
|
|
+ int jstop = (int)png_pass_inc[pass];
|
|
|
png_byte v;
|
|
|
png_uint_32 i;
|
|
|
int j;
|
|
@@ -3570,8 +3699,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
|
|
if ((transformations & PNG_PACKSWAP) != 0)
|
|
|
{
|
|
|
- sshift = (int)((row_info->width + 7) & 0x07);
|
|
|
- dshift = (int)((final_width + 7) & 0x07);
|
|
|
+ sshift = ((row_info->width + 7) & 0x07);
|
|
|
+ dshift = ((final_width + 7) & 0x07);
|
|
|
s_start = 7;
|
|
|
s_end = 0;
|
|
|
s_inc = -1;
|
|
@@ -3580,8 +3709,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
else
|
|
|
#endif
|
|
|
{
|
|
|
- sshift = 7 - (int)((row_info->width + 7) & 0x07);
|
|
|
- dshift = 7 - (int)((final_width + 7) & 0x07);
|
|
|
+ sshift = 7 - ((row_info->width + 7) & 0x07);
|
|
|
+ dshift = 7 - ((final_width + 7) & 0x07);
|
|
|
s_start = 0;
|
|
|
s_end = 7;
|
|
|
s_inc = 1;
|
|
@@ -3593,7 +3722,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
for (j = 0; j < jstop; j++)
|
|
|
{
|
|
|
unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
|
|
|
- tmp |= v << dshift;
|
|
|
+ tmp |= (unsigned int)(v << dshift);
|
|
|
*dp = (png_byte)(tmp & 0xff);
|
|
|
|
|
|
if (dshift == s_end)
|
|
@@ -3603,7 +3732,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- dshift += s_inc;
|
|
|
+ dshift = (unsigned int)((int)dshift + s_inc);
|
|
|
}
|
|
|
|
|
|
if (sshift == s_end)
|
|
@@ -3613,7 +3742,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- sshift += s_inc;
|
|
|
+ sshift = (unsigned int)((int)sshift + s_inc);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -3622,16 +3751,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
{
|
|
|
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
|
|
|
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
|
|
|
- int sshift, dshift;
|
|
|
- int s_start, s_end, s_inc;
|
|
|
- int jstop = png_pass_inc[pass];
|
|
|
+ unsigned int sshift, dshift;
|
|
|
+ unsigned int s_start, s_end;
|
|
|
+ int s_inc;
|
|
|
+ int jstop = (int)png_pass_inc[pass];
|
|
|
png_uint_32 i;
|
|
|
|
|
|
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
|
|
if ((transformations & PNG_PACKSWAP) != 0)
|
|
|
{
|
|
|
- sshift = (int)(((row_info->width + 3) & 0x03) << 1);
|
|
|
- dshift = (int)(((final_width + 3) & 0x03) << 1);
|
|
|
+ sshift = (((row_info->width + 3) & 0x03) << 1);
|
|
|
+ dshift = (((final_width + 3) & 0x03) << 1);
|
|
|
s_start = 6;
|
|
|
s_end = 0;
|
|
|
s_inc = -2;
|
|
@@ -3640,8 +3770,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
else
|
|
|
#endif
|
|
|
{
|
|
|
- sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
|
|
|
- dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
|
|
|
+ sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);
|
|
|
+ dshift = ((3 - ((final_width + 3) & 0x03)) << 1);
|
|
|
s_start = 0;
|
|
|
s_end = 6;
|
|
|
s_inc = 2;
|
|
@@ -3656,7 +3786,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
for (j = 0; j < jstop; j++)
|
|
|
{
|
|
|
unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
|
|
|
- tmp |= v << dshift;
|
|
|
+ tmp |= (unsigned int)(v << dshift);
|
|
|
*dp = (png_byte)(tmp & 0xff);
|
|
|
|
|
|
if (dshift == s_end)
|
|
@@ -3666,7 +3796,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- dshift += s_inc;
|
|
|
+ dshift = (unsigned int)((int)dshift + s_inc);
|
|
|
}
|
|
|
|
|
|
if (sshift == s_end)
|
|
@@ -3676,7 +3806,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- sshift += s_inc;
|
|
|
+ sshift = (unsigned int)((int)sshift + s_inc);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -3685,16 +3815,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
{
|
|
|
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
|
|
|
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
|
|
|
- int sshift, dshift;
|
|
|
- int s_start, s_end, s_inc;
|
|
|
+ unsigned int sshift, dshift;
|
|
|
+ unsigned int s_start, s_end;
|
|
|
+ int s_inc;
|
|
|
png_uint_32 i;
|
|
|
- int jstop = png_pass_inc[pass];
|
|
|
+ int jstop = (int)png_pass_inc[pass];
|
|
|
|
|
|
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
|
|
if ((transformations & PNG_PACKSWAP) != 0)
|
|
|
{
|
|
|
- sshift = (int)(((row_info->width + 1) & 0x01) << 2);
|
|
|
- dshift = (int)(((final_width + 1) & 0x01) << 2);
|
|
|
+ sshift = (((row_info->width + 1) & 0x01) << 2);
|
|
|
+ dshift = (((final_width + 1) & 0x01) << 2);
|
|
|
s_start = 4;
|
|
|
s_end = 0;
|
|
|
s_inc = -4;
|
|
@@ -3703,8 +3834,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
else
|
|
|
#endif
|
|
|
{
|
|
|
- sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
|
|
|
- dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
|
|
|
+ sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);
|
|
|
+ dshift = ((1 - ((final_width + 1) & 0x01)) << 2);
|
|
|
s_start = 0;
|
|
|
s_end = 4;
|
|
|
s_inc = 4;
|
|
@@ -3718,7 +3849,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
for (j = 0; j < jstop; j++)
|
|
|
{
|
|
|
unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
|
|
|
- tmp |= v << dshift;
|
|
|
+ tmp |= (unsigned int)(v << dshift);
|
|
|
*dp = (png_byte)(tmp & 0xff);
|
|
|
|
|
|
if (dshift == s_end)
|
|
@@ -3728,7 +3859,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- dshift += s_inc;
|
|
|
+ dshift = (unsigned int)((int)dshift + s_inc);
|
|
|
}
|
|
|
|
|
|
if (sshift == s_end)
|
|
@@ -3738,7 +3869,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
}
|
|
|
|
|
|
else
|
|
|
- sshift += s_inc;
|
|
|
+ sshift = (unsigned int)((int)sshift + s_inc);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -3752,7 +3883,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
|
|
|
|
|
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
|
|
|
|
|
- int jstop = png_pass_inc[pass];
|
|
|
+ int jstop = (int)png_pass_inc[pass];
|
|
|
png_uint_32 i;
|
|
|
|
|
|
for (i = 0; i < row_info->width; i++)
|
|
@@ -3880,7 +4011,10 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
|
|
|
/* Find the best predictor, the least of pa, pb, pc favoring the earlier
|
|
|
* ones in the case of a tie.
|
|
|
*/
|
|
|
- if (pb < pa) pa = pb, a = b;
|
|
|
+ if (pb < pa)
|
|
|
+ {
|
|
|
+ pa = pb; a = b;
|
|
|
+ }
|
|
|
if (pc < pa) a = c;
|
|
|
|
|
|
/* Calculate the current pixel in a, and move the previous row pixel to c
|
|
@@ -3896,7 +4030,7 @@ static void
|
|
|
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
|
|
png_const_bytep prev_row)
|
|
|
{
|
|
|
- int bpp = (row_info->pixel_depth + 7) >> 3;
|
|
|
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
|
|
|
png_bytep rp_end = row + bpp;
|
|
|
|
|
|
/* Process the first pixel in the row completely (this is the same as 'up'
|
|
@@ -3909,7 +4043,7 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
|
|
}
|
|
|
|
|
|
/* Remainder */
|
|
|
- rp_end += row_info->rowbytes - bpp;
|
|
|
+ rp_end = rp_end + (row_info->rowbytes - bpp);
|
|
|
|
|
|
while (row < rp_end)
|
|
|
{
|
|
@@ -3932,7 +4066,10 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
|
|
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
|
|
#endif
|
|
|
|
|
|
- if (pb < pa) pa = pb, a = b;
|
|
|
+ if (pb < pa)
|
|
|
+ {
|
|
|
+ pa = pb; a = b;
|
|
|
+ }
|
|
|
if (pc < pa) a = c;
|
|
|
|
|
|
a += *row;
|
|
@@ -4254,7 +4391,7 @@ png_read_start_row(png_structrp png_ptr)
|
|
|
/* Offset to next interlace block in the y direction */
|
|
|
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
|
|
|
|
|
- int max_pixel_depth;
|
|
|
+ unsigned int max_pixel_depth;
|
|
|
png_size_t row_bytes;
|
|
|
|
|
|
png_debug(1, "in png_read_start_row");
|
|
@@ -4283,7 +4420,7 @@ png_read_start_row(png_structrp png_ptr)
|
|
|
png_ptr->iwidth = png_ptr->width;
|
|
|
}
|
|
|
|
|
|
- max_pixel_depth = png_ptr->pixel_depth;
|
|
|
+ max_pixel_depth = (unsigned int)png_ptr->pixel_depth;
|
|
|
|
|
|
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
|
|
|
* calculations to calculate the final pixel depth, then
|
|
@@ -4418,7 +4555,7 @@ png_read_start_row(png_structrp png_ptr)
|
|
|
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|
|
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
|
|
{
|
|
|
- int user_pixel_depth = png_ptr->user_transform_depth *
|
|
|
+ unsigned int user_pixel_depth = png_ptr->user_transform_depth *
|
|
|
png_ptr->user_transform_channels;
|
|
|
|
|
|
if (user_pixel_depth > max_pixel_depth)
|
|
@@ -4440,7 +4577,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|
|
* for safety's sake
|
|
|
*/
|
|
|
row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
|
|
|
- 1 + ((max_pixel_depth + 7) >> 3);
|
|
|
+ 1 + ((max_pixel_depth + 7) >> 3U);
|
|
|
|
|
|
#ifdef PNG_MAX_MALLOC_64K
|
|
|
if (row_bytes > (png_uint_32)65536L)
|
|
@@ -4509,7 +4646,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
|
|
* does not, so free the read buffer now regardless; the sequential reader
|
|
|
* reallocates it on demand.
|
|
|
*/
|
|
|
- if (png_ptr->read_buffer != 0)
|
|
|
+ if (png_ptr->read_buffer != NULL)
|
|
|
{
|
|
|
png_bytep buffer = png_ptr->read_buffer;
|
|
|
|