\r
/* pngrutil.c - utilities to read a PNG file\r
*\r
- * Last changed in libpng 1.6.20 [December 3, 2014]\r
- * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson\r
- * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\r
- * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\r
+ * Copyright (c) 2018 Cosmin Truta\r
+ * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson\r
+ * Copyright (c) 1996-1997 Andreas Dilger\r
+ * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\r
*\r
* This code is released under the libpng license.\r
* For conditions of distribution and use, see the disclaimer\r
{\r
png_uint_32 uval = png_get_uint_32(buf);\r
if ((uval & 0x80000000) == 0) /* non-negative */\r
- return uval;\r
+ return (png_int_32)uval;\r
\r
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */\r
if ((uval & 0x80000000) == 0) /* no overflow */\r
- return -(png_int_32)uval;\r
+ return -(png_int_32)uval;\r
/* The following has to be safe; this function only gets called on PNG data\r
* and if we get here that data is invalid. 0 is the most safe value and\r
* if not then an attacker would surely just generate a PNG with 0 instead.\r
png_uint_16 (PNGAPI\r
png_get_uint_16)(png_const_bytep buf)\r
{\r
- /* ANSI-C requires an int value to accomodate at least 16 bits so this\r
+ /* ANSI-C requires an int value to accommodate at least 16 bits so this\r
* works and allows the compiler not to worry about possible narrowing\r
* on 32-bit systems. (Pre-ANSI systems did not make integers smaller\r
* than 16 bits either.)\r
void /* PRIVATE */\r
png_read_sig(png_structrp png_ptr, png_inforp info_ptr)\r
{\r
- png_size_t num_checked, num_to_check;\r
+ size_t num_checked, num_to_check;\r
\r
/* Exit if the user application does not expect a signature. */\r
if (png_ptr->sig_bytes >= 8)\r
/* Check to see if chunk name is valid. */\r
png_check_chunk_name(png_ptr, png_ptr->chunk_name);\r
\r
+ /* Check for too-large chunk length */\r
+ png_check_chunk_length(png_ptr, length);\r
+\r
#ifdef PNG_IO_STATE_SUPPORTED\r
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;\r
#endif\r
\r
if (buffer != NULL)\r
{\r
+ memset(buffer, 0, new_size); /* just in case */\r
png_ptr->read_buffer = buffer;\r
png_ptr->read_buffer_size = new_size;\r
}\r
*/\r
{\r
int ret; /* zlib return code */\r
-#if PNG_ZLIB_VERNUM >= 0x1240\r
+#if ZLIB_VERNUM >= 0x1240\r
+ int window_bits = 0;\r
\r
# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)\r
- int window_bits;\r
-\r
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==\r
PNG_OPTION_ON)\r
{\r
\r
else\r
{\r
- window_bits = 0;\r
png_ptr->zstream_start = 1;\r
}\r
-# else\r
-# define window_bits 0\r
# endif\r
-#endif\r
+\r
+#endif /* ZLIB_VERNUM >= 0x1240 */\r
\r
/* Set this for safety, just in case the previous owner left pointers to\r
* memory allocations.\r
\r
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)\r
{\r
-#if PNG_ZLIB_VERNUM < 0x1240\r
- ret = inflateReset(&png_ptr->zstream);\r
-#else\r
+#if ZLIB_VERNUM >= 0x1240\r
ret = inflateReset2(&png_ptr->zstream, window_bits);\r
+#else\r
+ ret = inflateReset(&png_ptr->zstream);\r
#endif\r
}\r
\r
else\r
{\r
-#if PNG_ZLIB_VERNUM < 0x1240\r
- ret = inflateInit(&png_ptr->zstream);\r
-#else\r
+#if ZLIB_VERNUM >= 0x1240\r
ret = inflateInit2(&png_ptr->zstream, window_bits);\r
+#else\r
+ ret = inflateInit(&png_ptr->zstream);\r
#endif\r
\r
if (ret == Z_OK)\r
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;\r
}\r
\r
+#if ZLIB_VERNUM >= 0x1290 && \\r
+ defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)\r
+ if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)\r
+ /* Turn off validation of the ADLER32 checksum in IDAT chunks */\r
+ ret = inflateValidate(&png_ptr->zstream, 0);\r
+#endif\r
+\r
if (ret == Z_OK)\r
png_ptr->zowner = owner;\r
\r
#endif\r
}\r
\r
-#if PNG_ZLIB_VERNUM >= 0x1240\r
+#if ZLIB_VERNUM >= 0x1240\r
/* Handle the start of the inflate stream if we called inflateInit2(strm,0);\r
* in this case some zlib versions skip validation of the CINFO field and, in\r
* certain circumstances, libpng may end up displaying an invalid image, in\r
#endif /* Zlib >= 1.2.4 */\r
\r
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED\r
+#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)\r
/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to\r
* allow the caller to do multiple calls if required. If the 'finish' flag is\r
* set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must\r
*/\r
static int\r
png_decompress_chunk(png_structrp png_ptr,\r
- png_uint_32 chunklength, png_uint_32 prefix_size,\r
- png_alloc_size_t *newlength /* must be initialized to the maximum! */,\r
- int terminate /*add a '\0' to the end of the uncompressed data*/)\r
+ png_uint_32 chunklength, png_uint_32 prefix_size,\r
+ png_alloc_size_t *newlength /* must be initialized to the maximum! */,\r
+ int terminate /*add a '\0' to the end of the uncompressed data*/)\r
{\r
/* TODO: implement different limits for different types of chunk.\r
*\r
png_uint_32 lzsize = chunklength - prefix_size;\r
\r
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,\r
- /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,\r
- /* output: */ NULL, newlength);\r
+ /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,\r
+ /* output: */ NULL, newlength);\r
\r
if (ret == Z_STREAM_END)\r
{\r
*/\r
png_alloc_size_t new_size = *newlength;\r
png_alloc_size_t buffer_size = prefix_size + new_size +\r
- (terminate != 0);\r
+ (terminate != 0);\r
png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,\r
- buffer_size));\r
+ buffer_size));\r
\r
if (text != NULL)\r
{\r
+ memset(text, 0, buffer_size);\r
+\r
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,\r
- png_ptr->read_buffer + prefix_size, &lzsize,\r
- text + prefix_size, newlength);\r
+ png_ptr->read_buffer + prefix_size, &lzsize,\r
+ text + prefix_size, newlength);\r
\r
if (ret == Z_STREAM_END)\r
{\r
* the extra space may otherwise be used as a Trojan Horse.\r
*/\r
if (ret == Z_STREAM_END &&\r
- chunklength - prefix_size != lzsize)\r
+ chunklength - prefix_size != lzsize)\r
png_chunk_benign_error(png_ptr, "extra compressed data");\r
}\r
\r
{\r
/* inflateReset failed, store the error message */\r
png_zstream_error(png_ptr, ret);\r
-\r
- if (ret == Z_STREAM_END)\r
- ret = PNG_UNEXPECTED_ZLIB_RETURN;\r
+ ret = PNG_UNEXPECTED_ZLIB_RETURN;\r
}\r
}\r
\r
return Z_MEM_ERROR;\r
}\r
}\r
+#endif /* READ_zTXt || READ_iTXt */\r
#endif /* READ_COMPRESSED_TEXT */\r
\r
#ifdef PNG_READ_iCCP_SUPPORTED\r
*/\r
static int\r
png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,\r
- png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,\r
- int finish)\r
+ png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,\r
+ int finish)\r
{\r
if (png_ptr->zowner == png_ptr->chunk_name)\r
{\r
* the available output is produced; this allows reading of truncated\r
* streams.\r
*/\r
- ret = PNG_INFLATE(png_ptr,\r
- *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));\r
+ ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?\r
+ Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));\r
}\r
while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));\r
\r
return Z_STREAM_ERROR;\r
}\r
}\r
-#endif\r
+#endif /* READ_iCCP */\r
\r
/* Read and check the IDHR chunk */\r
\r
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\r
#endif\r
{\r
- png_crc_finish(png_ptr, (int) length - num * 3);\r
+ png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3));\r
}\r
\r
#ifndef PNG_READ_OPT_PLTE_SUPPORTED\r
\r
png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;\r
(void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,\r
- 1/*prefer cHRM values*/);\r
+ 1/*prefer cHRM values*/);\r
png_colorspace_sync(png_ptr, info_ptr);\r
}\r
#endif\r
* chunk is just ignored, so does not invalidate the color space. An\r
* alternative is to set the 'invalid' flags at the start of this routine\r
* and only clear them in they were not set before and all the tests pass.\r
- * The minimum 'deflate' stream is assumed to be just the 2 byte header and\r
- * 4 byte checksum. The keyword must be at least one character and there is\r
- * a terminator (0) byte and the compression method.\r
*/\r
- if (length < 9)\r
+\r
+ /* The keyword must be at least one character and there is a\r
+ * terminator (0) byte and the compression method byte, and the\r
+ * 'zlib' datastream is at least 11 bytes.\r
+ */\r
+ if (length < 14)\r
{\r
png_crc_finish(png_ptr, length);\r
png_chunk_benign_error(png_ptr, "too short");\r
png_crc_read(png_ptr, (png_bytep)keyword, read_length);\r
length -= read_length;\r
\r
+ /* The minimum 'zlib' stream is assumed to be just the 2 byte header,\r
+ * 5 bytes minimum 'deflate' stream, and the 4 byte checksum.\r
+ */\r
+ if (length < 11)\r
+ {\r
+ png_crc_finish(png_ptr, length);\r
+ png_chunk_benign_error(png_ptr, "too short");\r
+ return;\r
+ }\r
+\r
keyword_length = 0;\r
while (keyword_length < 80 && keyword_length < read_length &&\r
keyword[keyword_length] != 0)\r
\r
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)\r
{\r
- Byte profile_header[132];\r
+ Byte profile_header[132]={0};\r
Byte local_buffer[PNG_INFLATE_BUF_SIZE];\r
png_alloc_size_t size = (sizeof profile_header);\r
\r
png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);\r
png_ptr->zstream.avail_in = read_length;\r
(void)png_inflate_read(png_ptr, local_buffer,\r
- (sizeof local_buffer), &length, profile_header, &size,\r
- 0/*finish: don't, because the output is too small*/);\r
+ (sizeof local_buffer), &length, profile_header, &size,\r
+ 0/*finish: don't, because the output is too small*/);\r
\r
if (size == 0)\r
{\r
/* We have the ICC profile header; do the basic header checks.\r
*/\r
- const png_uint_32 profile_length =\r
- png_get_uint_32(profile_header);\r
+ png_uint_32 profile_length = png_get_uint_32(profile_header);\r
\r
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,\r
- keyword, profile_length) != 0)\r
+ keyword, profile_length) != 0)\r
{\r
/* The length is apparently ok, so we can check the 132\r
* byte header.\r
*/\r
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,\r
- keyword, profile_length, profile_header,\r
- png_ptr->color_type) != 0)\r
+ keyword, profile_length, profile_header,\r
+ png_ptr->color_type) != 0)\r
{\r
/* Now read the tag table; a variable size buffer is\r
* needed at this point, allocate one for the whole\r
* profile. The header check has already validated\r
- * that none of these stuff will overflow.\r
+ * that none of this stuff will overflow.\r
*/\r
- const png_uint_32 tag_count = png_get_uint_32(\r
- profile_header+128);\r
+ png_uint_32 tag_count =\r
+ png_get_uint_32(profile_header + 128);\r
png_bytep profile = png_read_buffer(png_ptr,\r
- profile_length, 2/*silent*/);\r
+ profile_length, 2/*silent*/);\r
\r
if (profile != NULL)\r
{\r
memcpy(profile, profile_header,\r
- (sizeof profile_header));\r
+ (sizeof profile_header));\r
\r
size = 12 * tag_count;\r
\r
(void)png_inflate_read(png_ptr, local_buffer,\r
- (sizeof local_buffer), &length,\r
- profile + (sizeof profile_header), &size, 0);\r
+ (sizeof local_buffer), &length,\r
+ profile + (sizeof profile_header), &size, 0);\r
\r
/* Still expect a buffer error because we expect\r
* there to be some tag data!\r
if (size == 0)\r
{\r
if (png_icc_check_tag_table(png_ptr,\r
- &png_ptr->colorspace, keyword, profile_length,\r
- profile) != 0)\r
+ &png_ptr->colorspace, keyword, profile_length,\r
+ profile) != 0)\r
{\r
/* The profile has been validated for basic\r
* security issues, so read the whole thing in.\r
*/\r
size = profile_length - (sizeof profile_header)\r
- - 12 * tag_count;\r
+ - 12 * tag_count;\r
\r
(void)png_inflate_read(png_ptr, local_buffer,\r
- (sizeof local_buffer), &length,\r
- profile + (sizeof profile_header) +\r
- 12 * tag_count, &size, 1/*finish*/);\r
+ (sizeof local_buffer), &length,\r
+ profile + (sizeof profile_header) +\r
+ 12 * tag_count, &size, 1/*finish*/);\r
\r
if (length > 0 && !(png_ptr->flags &\r
- PNG_FLAG_BENIGN_ERRORS_WARN))\r
+ PNG_FLAG_BENIGN_ERRORS_WARN))\r
errmsg = "extra compressed data";\r
\r
/* But otherwise allow extra data: */\r
* keep going.\r
*/\r
png_chunk_warning(png_ptr,\r
- "extra compressed data");\r
+ "extra compressed data");\r
}\r
\r
png_crc_finish(png_ptr, length);\r
finished = 1;\r
\r
-# ifdef PNG_sRGB_SUPPORTED\r
+# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0\r
/* Check for a match against sRGB */\r
png_icc_set_sRGB(png_ptr,\r
- &png_ptr->colorspace, profile,\r
- png_ptr->zstream.adler);\r
-# endif\r
+ &png_ptr->colorspace, profile,\r
+ png_ptr->zstream.adler);\r
+# endif\r
\r
/* Steal the profile for info_ptr. */\r
if (info_ptr != NULL)\r
{\r
png_free_data(png_ptr, info_ptr,\r
- PNG_FREE_ICCP, 0);\r
+ PNG_FREE_ICCP, 0);\r
\r
info_ptr->iccp_name = png_voidcast(char*,\r
- png_malloc_base(png_ptr,\r
- keyword_length+1));\r
+ png_malloc_base(png_ptr,\r
+ keyword_length+1));\r
if (info_ptr->iccp_name != NULL)\r
{\r
memcpy(info_ptr->iccp_name, keyword,\r
- keyword_length+1);\r
+ keyword_length+1);\r
info_ptr->iccp_proflen =\r
- profile_length;\r
+ profile_length;\r
info_ptr->iccp_profile = profile;\r
png_ptr->read_buffer = NULL; /*steal*/\r
info_ptr->free_me |= PNG_FREE_ICCP;\r
return;\r
}\r
}\r
-\r
- else if (size > 0)\r
- errmsg = "truncated";\r
-\r
-#ifndef __COVERITY__\r
- else\r
+ if (errmsg == NULL)\r
errmsg = png_ptr->zstream.msg;\r
-#endif\r
}\r
-\r
/* else png_icc_check_tag_table output an error */\r
}\r
-\r
else /* profile truncated */\r
errmsg = png_ptr->zstream.msg;\r
}\r
int entry_size, i;\r
png_uint_32 skip = 0;\r
png_uint_32 dl;\r
- png_size_t max_dl;\r
+ size_t max_dl;\r
\r
png_debug(1, "in png_handle_sPLT");\r
\r
data_length = length - (png_uint_32)(entry_start - buffer);\r
\r
/* Integrity-check the data length */\r
- if ((data_length % entry_size) != 0)\r
+ if ((data_length % (unsigned int)entry_size) != 0)\r
{\r
png_warning(png_ptr, "sPLT chunk has bad length");\r
return;\r
}\r
\r
- dl = (png_int_32)(data_length / entry_size);\r
+ dl = (png_uint_32)(data_length / (unsigned int)entry_size);\r
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));\r
\r
if (dl > max_dl)\r
return;\r
}\r
\r
- new_palette.nentries = (png_int_32)(data_length / entry_size);\r
+ new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size);\r
\r
- new_palette.entries = (png_sPLT_entryp)png_malloc_warn(\r
- png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));\r
+ new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,\r
+ (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry)));\r
\r
if (new_palette.entries == NULL)\r
{\r
\r
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */\r
{\r
+ if (png_ptr->bit_depth <= 8)\r
+ {\r
+ if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth))\r
+ {\r
+ png_chunk_benign_error(png_ptr, "invalid gray level");\r
+ return;\r
+ }\r
+ }\r
+\r
background.index = 0;\r
background.red =\r
background.green =\r
\r
else\r
{\r
+ if (png_ptr->bit_depth <= 8)\r
+ {\r
+ if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0)\r
+ {\r
+ png_chunk_benign_error(png_ptr, "invalid color");\r
+ return;\r
+ }\r
+ }\r
+\r
background.index = 0;\r
background.red = png_get_uint_16(buf);\r
background.green = png_get_uint_16(buf + 2);\r
}\r
#endif\r
\r
+#ifdef PNG_READ_eXIf_SUPPORTED\r
+void /* PRIVATE */\r
+png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\r
+{\r
+ unsigned int i;\r
+\r
+ png_debug(1, "in png_handle_eXIf");\r
+\r
+ if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\r
+ png_chunk_error(png_ptr, "missing IHDR");\r
+\r
+ if (length < 2)\r
+ {\r
+ png_crc_finish(png_ptr, length);\r
+ png_chunk_benign_error(png_ptr, "too short");\r
+ return;\r
+ }\r
+\r
+ else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0)\r
+ {\r
+ png_crc_finish(png_ptr, length);\r
+ png_chunk_benign_error(png_ptr, "duplicate");\r
+ return;\r
+ }\r
+\r
+ info_ptr->free_me |= PNG_FREE_EXIF;\r
+\r
+ info_ptr->eXIf_buf = png_voidcast(png_bytep,\r
+ png_malloc_warn(png_ptr, length));\r
+\r
+ if (info_ptr->eXIf_buf == NULL)\r
+ {\r
+ png_crc_finish(png_ptr, length);\r
+ png_chunk_benign_error(png_ptr, "out of memory");\r
+ return;\r
+ }\r
+\r
+ for (i = 0; i < length; i++)\r
+ {\r
+ png_byte buf[1];\r
+ png_crc_read(png_ptr, buf, 1);\r
+ info_ptr->eXIf_buf[i] = buf[0];\r
+ if (i == 1 && buf[0] != 'M' && buf[0] != 'I'\r
+ && info_ptr->eXIf_buf[0] != buf[0])\r
+ {\r
+ png_crc_finish(png_ptr, length);\r
+ png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");\r
+ png_free(png_ptr, info_ptr->eXIf_buf);\r
+ info_ptr->eXIf_buf = NULL;\r
+ return;\r
+ }\r
+ }\r
+\r
+ if (png_crc_finish(png_ptr, 0) != 0)\r
+ return;\r
+\r
+ png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);\r
+\r
+ png_free(png_ptr, info_ptr->eXIf_buf);\r
+ info_ptr->eXIf_buf = NULL;\r
+}\r
+#endif\r
+\r
#ifdef PNG_READ_hIST_SUPPORTED\r
void /* PRIVATE */\r
png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\r
}\r
\r
png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,\r
- (png_charp)units, params);\r
+ (png_charp)units, params);\r
\r
png_free(png_ptr, params);\r
}\r
png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\r
{\r
png_bytep buffer;\r
- png_size_t i;\r
+ size_t i;\r
int state;\r
\r
png_debug(1, "in png_handle_sCAL");\r
}\r
\r
png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",\r
- length + 1);\r
+ length + 1);\r
\r
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);\r
\r
\r
else\r
{\r
- png_size_t heighti = i;\r
+ size_t heighti = i;\r
\r
state = 0;\r
if (png_check_fp_number((png_const_charp)buffer, length,\r
else\r
/* This is the (only) success case. */\r
png_set_sCAL_s(png_ptr, info_ptr, buffer[0],\r
- (png_charp)buffer+1, (png_charp)buffer+heighti);\r
+ (png_charp)buffer+1, (png_charp)buffer+heighti);\r
}\r
}\r
#endif\r
\r
if (buffer == NULL)\r
{\r
- png_chunk_benign_error(png_ptr, "out of memory");\r
- return;\r
+ png_chunk_benign_error(png_ptr, "out of memory");\r
+ return;\r
}\r
\r
png_crc_read(png_ptr, buffer, length);\r
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\r
png_ptr->mode |= PNG_AFTER_IDAT;\r
\r
+ /* Note, "length" is sufficient here; we won't be adding\r
+ * a null terminator later.\r
+ */\r
buffer = png_read_buffer(png_ptr, length, 2/*silent*/);\r
\r
if (buffer == NULL)\r
* and text chunks.\r
*/\r
if (png_decompress_chunk(png_ptr, length, keyword_length+2,\r
- &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\r
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\r
{\r
png_text text;\r
\r
- /* It worked; png_ptr->read_buffer now looks like a tEXt chunk except\r
- * for the extra compression type byte and the fact that it isn't\r
- * necessarily '\0' terminated.\r
- */\r
- buffer = png_ptr->read_buffer;\r
- buffer[uncompressed_length+(keyword_length+2)] = 0;\r
-\r
- text.compression = PNG_TEXT_COMPRESSION_zTXt;\r
- text.key = (png_charp)buffer;\r
- text.text = (png_charp)(buffer + keyword_length+2);\r
- text.text_length = uncompressed_length;\r
- text.itxt_length = 0;\r
- text.lang = NULL;\r
- text.lang_key = NULL;\r
-\r
- if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)\r
- errmsg = "insufficient memory";\r
+ if (png_ptr->read_buffer == NULL)\r
+ errmsg="Read failure in png_handle_zTXt";\r
+ else\r
+ {\r
+ /* It worked; png_ptr->read_buffer now looks like a tEXt chunk\r
+ * except for the extra compression type byte and the fact that\r
+ * it isn't necessarily '\0' terminated.\r
+ */\r
+ buffer = png_ptr->read_buffer;\r
+ buffer[uncompressed_length+(keyword_length+2)] = 0;\r
+\r
+ text.compression = PNG_TEXT_COMPRESSION_zTXt;\r
+ text.key = (png_charp)buffer;\r
+ text.text = (png_charp)(buffer + keyword_length+2);\r
+ text.text_length = uncompressed_length;\r
+ text.itxt_length = 0;\r
+ text.lang = NULL;\r
+ text.lang_key = NULL;\r
+\r
+ if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)\r
+ errmsg = "insufficient memory";\r
+ }\r
}\r
\r
else\r
* iCCP and text chunks.\r
*/\r
if (png_decompress_chunk(png_ptr, length, prefix_length,\r
- &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\r
+ &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\r
buffer = png_ptr->read_buffer;\r
\r
else\r
{\r
PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);\r
/* The following is safe because of the PNG_SIZE_MAX init above */\r
- png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/;\r
+ png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/;\r
/* 'mode' is a flag array, only the bottom four bits matter here */\r
png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;\r
\r
{\r
/* Do a 'warn' here - it is handled below. */\r
png_ptr->unknown_chunk.data = png_voidcast(png_bytep,\r
- png_malloc_warn(png_ptr, length));\r
+ png_malloc_warn(png_ptr, length));\r
}\r
}\r
\r
/* Handle an unknown, or known but disabled, chunk */\r
void /* PRIVATE */\r
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,\r
- png_uint_32 length, int keep)\r
+ png_uint_32 length, int keep)\r
{\r
int handled = 0; /* the chunk was handled */\r
\r
{\r
/* Callback to user unknown chunk handler */\r
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,\r
- &png_ptr->unknown_chunk);\r
+ &png_ptr->unknown_chunk);\r
\r
/* ret is:\r
* negative: An error occurred; png_chunk_error will be called.\r
{\r
png_chunk_warning(png_ptr, "Saving unknown chunk:");\r
png_app_warning(png_ptr,\r
- "forcing save of an unhandled chunk;"\r
- " please call png_set_keep_unknown_chunks");\r
- /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */\r
+ "forcing save of an unhandled chunk;"\r
+ " please call png_set_keep_unknown_chunks");\r
+ /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */\r
}\r
# endif\r
keep = PNG_HANDLE_CHUNK_IF_SAFE;\r
case 2:\r
png_ptr->user_chunk_cache_max = 1;\r
png_chunk_benign_error(png_ptr, "no space in chunk cache");\r
- /* FALL THROUGH */\r
+ /* FALLTHROUGH */\r
case 1:\r
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical\r
* chunk being skipped, now there will be a hard error below.\r
\r
default: /* not at limit */\r
--(png_ptr->user_chunk_cache_max);\r
- /* FALL THROUGH */\r
+ /* FALLTHROUGH */\r
case 0: /* no limit */\r
# endif /* USER_LIMITS */\r
/* Here when the limit isn't reached or when limits are compiled\r
* out; store the chunk.\r
*/\r
png_set_unknown_chunks(png_ptr, info_ptr,\r
- &png_ptr->unknown_chunk, 1);\r
+ &png_ptr->unknown_chunk, 1);\r
handled = 1;\r
# ifdef PNG_USER_LIMITS_SUPPORTED\r
break;\r
*/\r
\r
void /* PRIVATE */\r
-png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name)\r
+png_check_chunk_name(png_const_structrp png_ptr, png_uint_32 chunk_name)\r
{\r
int i;\r
+ png_uint_32 cn=chunk_name;\r
\r
png_debug(1, "in png_check_chunk_name");\r
\r
for (i=1; i<=4; ++i)\r
{\r
- int c = chunk_name & 0xff;\r
+ int c = cn & 0xff;\r
\r
if (c < 65 || c > 122 || (c > 90 && c < 97))\r
png_chunk_error(png_ptr, "invalid chunk type");\r
\r
- chunk_name >>= 8;\r
+ cn >>= 8;\r
+ }\r
+}\r
+\r
+void /* PRIVATE */\r
+png_check_chunk_length(png_const_structrp png_ptr, png_uint_32 length)\r
+{\r
+ png_alloc_size_t limit = PNG_UINT_31_MAX;\r
+\r
+# ifdef PNG_SET_USER_LIMITS_SUPPORTED\r
+ if (png_ptr->user_chunk_malloc_max > 0 &&\r
+ png_ptr->user_chunk_malloc_max < limit)\r
+ limit = png_ptr->user_chunk_malloc_max;\r
+# elif PNG_USER_CHUNK_MALLOC_MAX > 0\r
+ if (PNG_USER_CHUNK_MALLOC_MAX < limit)\r
+ limit = PNG_USER_CHUNK_MALLOC_MAX;\r
+# endif\r
+ if (png_ptr->chunk_name == png_IDAT)\r
+ {\r
+ png_alloc_size_t idat_limit = PNG_UINT_31_MAX;\r
+ size_t row_factor =\r
+ (size_t)png_ptr->width\r
+ * (size_t)png_ptr->channels\r
+ * (png_ptr->bit_depth > 8? 2: 1)\r
+ + 1\r
+ + (png_ptr->interlaced? 6: 0);\r
+ if (png_ptr->height > PNG_UINT_32_MAX/row_factor)\r
+ idat_limit = PNG_UINT_31_MAX;\r
+ else\r
+ idat_limit = png_ptr->height * row_factor;\r
+ row_factor = row_factor > 32566? 32566 : row_factor;\r
+ idat_limit += 6 + 5*(idat_limit/row_factor+1); /* zlib+deflate overhead */\r
+ idat_limit=idat_limit < PNG_UINT_31_MAX? idat_limit : PNG_UINT_31_MAX;\r
+ limit = limit < idat_limit? idat_limit : limit;\r
+ }\r
+\r
+ if (length > limit)\r
+ {\r
+ png_debug2(0," length = %lu, limit = %lu",\r
+ (unsigned long)length,(unsigned long)limit);\r
+ png_chunk_error(png_ptr, "chunk data is too large");\r
}\r
}\r
\r
# ifdef PNG_READ_PACKSWAP_SUPPORTED\r
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\r
/* little-endian byte */\r
- end_mask = 0xff << end_mask;\r
+ end_mask = (unsigned int)(0xff << end_mask);\r
\r
else /* big-endian byte */\r
# endif\r
/* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and\r
* then pass:\r
*/\r
- static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =\r
+ static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =\r
{\r
/* Little-endian byte masks for PACKSWAP */\r
{ S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },\r
/* display_mask has only three entries for the odd passes, so index by\r
* pass>>1.\r
*/\r
- static PNG_CONST png_uint_32 display_mask[2][3][3] =\r
+ static const png_uint_32 display_mask[2][3][3] =\r
{\r
/* Little-endian byte masks for PACKSWAP */\r
{ B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },\r
*/\r
do\r
{\r
- dp[0] = sp[0], dp[1] = sp[1];\r
+ dp[0] = sp[0]; dp[1] = sp[1];\r
\r
if (row_width <= bytes_to_jump)\r
return;\r
*/\r
for (;;)\r
{\r
- dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];\r
+ dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];\r
\r
if (row_width <= bytes_to_jump)\r
return;\r
/* Everything is aligned for png_uint_16 copies, but try for\r
* png_uint_32 first.\r
*/\r
- if (png_isaligned(dp, png_uint_32) != 0 &&\r
- png_isaligned(sp, png_uint_32) != 0 &&\r
+ if (png_isaligned(dp, png_uint_32) &&\r
+ png_isaligned(sp, png_uint_32) &&\r
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&\r
bytes_to_jump % (sizeof (png_uint_32)) == 0)\r
{\r
#ifdef PNG_READ_INTERLACING_SUPPORTED\r
void /* PRIVATE */\r
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,\r
- png_uint_32 transformations /* Because these may affect the byte layout */)\r
+ png_uint_32 transformations /* Because these may affect the byte layout */)\r
{\r
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\r
/* Offset to next interlace block */\r
- static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
+ static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
\r
png_debug(1, "in png_do_read_interlace");\r
if (row != NULL && row_info != NULL)\r
{\r
case 1:\r
{\r
- png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);\r
- png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);\r
- int sshift, dshift;\r
- int s_start, s_end, s_inc;\r
- int jstop = png_pass_inc[pass];\r
+ png_bytep sp = row + (size_t)((row_info->width - 1) >> 3);\r
+ png_bytep dp = row + (size_t)((final_width - 1) >> 3);\r
+ unsigned int sshift, dshift;\r
+ unsigned int s_start, s_end;\r
+ int s_inc;\r
+ int jstop = (int)png_pass_inc[pass];\r
png_byte v;\r
png_uint_32 i;\r
int j;\r
#ifdef PNG_READ_PACKSWAP_SUPPORTED\r
if ((transformations & PNG_PACKSWAP) != 0)\r
{\r
- sshift = (int)((row_info->width + 7) & 0x07);\r
- dshift = (int)((final_width + 7) & 0x07);\r
+ sshift = ((row_info->width + 7) & 0x07);\r
+ dshift = ((final_width + 7) & 0x07);\r
s_start = 7;\r
s_end = 0;\r
s_inc = -1;\r
else\r
#endif\r
{\r
- sshift = 7 - (int)((row_info->width + 7) & 0x07);\r
- dshift = 7 - (int)((final_width + 7) & 0x07);\r
+ sshift = 7 - ((row_info->width + 7) & 0x07);\r
+ dshift = 7 - ((final_width + 7) & 0x07);\r
s_start = 0;\r
s_end = 7;\r
s_inc = 1;\r
for (j = 0; j < jstop; j++)\r
{\r
unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));\r
- tmp |= v << dshift;\r
+ tmp |= (unsigned int)(v << dshift);\r
*dp = (png_byte)(tmp & 0xff);\r
\r
if (dshift == s_end)\r
}\r
\r
else\r
- dshift += s_inc;\r
+ dshift = (unsigned int)((int)dshift + s_inc);\r
}\r
\r
if (sshift == s_end)\r
}\r
\r
else\r
- sshift += s_inc;\r
+ sshift = (unsigned int)((int)sshift + s_inc);\r
}\r
break;\r
}\r
{\r
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);\r
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);\r
- int sshift, dshift;\r
- int s_start, s_end, s_inc;\r
- int jstop = png_pass_inc[pass];\r
+ unsigned int sshift, dshift;\r
+ unsigned int s_start, s_end;\r
+ int s_inc;\r
+ int jstop = (int)png_pass_inc[pass];\r
png_uint_32 i;\r
\r
#ifdef PNG_READ_PACKSWAP_SUPPORTED\r
if ((transformations & PNG_PACKSWAP) != 0)\r
{\r
- sshift = (int)(((row_info->width + 3) & 0x03) << 1);\r
- dshift = (int)(((final_width + 3) & 0x03) << 1);\r
+ sshift = (((row_info->width + 3) & 0x03) << 1);\r
+ dshift = (((final_width + 3) & 0x03) << 1);\r
s_start = 6;\r
s_end = 0;\r
s_inc = -2;\r
else\r
#endif\r
{\r
- sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);\r
- dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);\r
+ sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1);\r
+ dshift = ((3 - ((final_width + 3) & 0x03)) << 1);\r
s_start = 0;\r
s_end = 6;\r
s_inc = 2;\r
for (j = 0; j < jstop; j++)\r
{\r
unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));\r
- tmp |= v << dshift;\r
+ tmp |= (unsigned int)(v << dshift);\r
*dp = (png_byte)(tmp & 0xff);\r
\r
if (dshift == s_end)\r
}\r
\r
else\r
- dshift += s_inc;\r
+ dshift = (unsigned int)((int)dshift + s_inc);\r
}\r
\r
if (sshift == s_end)\r
}\r
\r
else\r
- sshift += s_inc;\r
+ sshift = (unsigned int)((int)sshift + s_inc);\r
}\r
break;\r
}\r
\r
case 4:\r
{\r
- png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);\r
- png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);\r
- int sshift, dshift;\r
- int s_start, s_end, s_inc;\r
+ png_bytep sp = row + (size_t)((row_info->width - 1) >> 1);\r
+ png_bytep dp = row + (size_t)((final_width - 1) >> 1);\r
+ unsigned int sshift, dshift;\r
+ unsigned int s_start, s_end;\r
+ int s_inc;\r
png_uint_32 i;\r
- int jstop = png_pass_inc[pass];\r
+ int jstop = (int)png_pass_inc[pass];\r
\r
#ifdef PNG_READ_PACKSWAP_SUPPORTED\r
if ((transformations & PNG_PACKSWAP) != 0)\r
{\r
- sshift = (int)(((row_info->width + 1) & 0x01) << 2);\r
- dshift = (int)(((final_width + 1) & 0x01) << 2);\r
+ sshift = (((row_info->width + 1) & 0x01) << 2);\r
+ dshift = (((final_width + 1) & 0x01) << 2);\r
s_start = 4;\r
s_end = 0;\r
s_inc = -4;\r
else\r
#endif\r
{\r
- sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);\r
- dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);\r
+ sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2);\r
+ dshift = ((1 - ((final_width + 1) & 0x01)) << 2);\r
s_start = 0;\r
s_end = 4;\r
s_inc = 4;\r
for (j = 0; j < jstop; j++)\r
{\r
unsigned int tmp = *dp & (0xf0f >> (4 - dshift));\r
- tmp |= v << dshift;\r
+ tmp |= (unsigned int)(v << dshift);\r
*dp = (png_byte)(tmp & 0xff);\r
\r
if (dshift == s_end)\r
}\r
\r
else\r
- dshift += s_inc;\r
+ dshift = (unsigned int)((int)dshift + s_inc);\r
}\r
\r
if (sshift == s_end)\r
}\r
\r
else\r
- sshift += s_inc;\r
+ sshift = (unsigned int)((int)sshift + s_inc);\r
}\r
break;\r
}\r
\r
default:\r
{\r
- png_size_t pixel_bytes = (row_info->pixel_depth >> 3);\r
+ size_t pixel_bytes = (row_info->pixel_depth >> 3);\r
\r
- png_bytep sp = row + (png_size_t)(row_info->width - 1)\r
+ png_bytep sp = row + (size_t)(row_info->width - 1)\r
* pixel_bytes;\r
\r
- png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;\r
+ png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes;\r
\r
- int jstop = png_pass_inc[pass];\r
+ int jstop = (int)png_pass_inc[pass];\r
png_uint_32 i;\r
\r
for (i = 0; i < row_info->width; i++)\r
\r
static void\r
png_read_filter_row_sub(png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row)\r
+ png_const_bytep prev_row)\r
{\r
- png_size_t i;\r
- png_size_t istop = row_info->rowbytes;\r
+ size_t i;\r
+ size_t istop = row_info->rowbytes;\r
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;\r
png_bytep rp = row + bpp;\r
\r
\r
static void\r
png_read_filter_row_up(png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row)\r
+ png_const_bytep prev_row)\r
{\r
- png_size_t i;\r
- png_size_t istop = row_info->rowbytes;\r
+ size_t i;\r
+ size_t istop = row_info->rowbytes;\r
png_bytep rp = row;\r
png_const_bytep pp = prev_row;\r
\r
\r
static void\r
png_read_filter_row_avg(png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row)\r
+ png_const_bytep prev_row)\r
{\r
- png_size_t i;\r
+ size_t i;\r
png_bytep rp = row;\r
png_const_bytep pp = prev_row;\r
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;\r
- png_size_t istop = row_info->rowbytes - bpp;\r
+ size_t istop = row_info->rowbytes - bpp;\r
\r
for (i = 0; i < bpp; i++)\r
{\r
\r
static void\r
png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row)\r
+ png_const_bytep prev_row)\r
{\r
png_bytep rp_end = row + row_info->rowbytes;\r
int a, c;\r
/* Find the best predictor, the least of pa, pb, pc favoring the earlier\r
* ones in the case of a tie.\r
*/\r
- if (pb < pa) pa = pb, a = b;\r
+ if (pb < pa)\r
+ {\r
+ pa = pb; a = b;\r
+ }\r
if (pc < pa) a = c;\r
\r
/* Calculate the current pixel in a, and move the previous row pixel to c\r
\r
static void\r
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row)\r
+ png_const_bytep prev_row)\r
{\r
- int bpp = (row_info->pixel_depth + 7) >> 3;\r
+ unsigned int bpp = (row_info->pixel_depth + 7) >> 3;\r
png_bytep rp_end = row + bpp;\r
\r
/* Process the first pixel in the row completely (this is the same as 'up'\r
}\r
\r
/* Remainder */\r
- rp_end += row_info->rowbytes - bpp;\r
+ rp_end = rp_end + (row_info->rowbytes - bpp);\r
\r
while (row < rp_end)\r
{\r
pc = (p + pc) < 0 ? -(p + pc) : p + pc;\r
#endif\r
\r
- if (pb < pa) pa = pb, a = b;\r
+ if (pb < pa)\r
+ {\r
+ pa = pb; a = b;\r
+ }\r
if (pc < pa) a = c;\r
\r
a += *row;\r
\r
void /* PRIVATE */\r
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,\r
- png_const_bytep prev_row, int filter)\r
+ png_const_bytep prev_row, int filter)\r
{\r
/* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define\r
* PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic\r
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\r
void /* PRIVATE */\r
png_read_IDAT_data(png_structrp png_ptr, png_bytep output,\r
- png_alloc_size_t avail_out)\r
+ png_alloc_size_t avail_out)\r
{\r
/* Loop reading IDATs and decompressing the result into output[avail_out] */\r
png_ptr->zstream.next_out = output;\r
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\r
\r
/* Start of interlace block */\r
- static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\r
+ static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\r
\r
/* Offset to next interlace block */\r
- static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
+ static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
\r
/* Start of interlace block in the y direction */\r
- static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\r
+ static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\r
\r
/* Offset to next interlace block in the y direction */\r
- static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\r
+ static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\r
\r
png_debug(1, "in png_read_finish_row");\r
png_ptr->row_number++;\r
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\r
\r
/* Start of interlace block */\r
- static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\r
+ static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\r
\r
/* Offset to next interlace block */\r
- static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
+ static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\r
\r
/* Start of interlace block in the y direction */\r
- static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\r
+ static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\r
\r
/* Offset to next interlace block in the y direction */\r
- static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\r
+ static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\r
\r
- int max_pixel_depth;\r
- png_size_t row_bytes;\r
+ unsigned int max_pixel_depth;\r
+ size_t row_bytes;\r
\r
png_debug(1, "in png_read_start_row");\r
\r
png_ptr->iwidth = png_ptr->width;\r
}\r
\r
- max_pixel_depth = png_ptr->pixel_depth;\r
+ max_pixel_depth = (unsigned int)png_ptr->pixel_depth;\r
\r
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of\r
* calculations to calculate the final pixel depth, then\r
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)\r
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)\r
{\r
- int user_pixel_depth = png_ptr->user_transform_depth *\r
+ unsigned int user_pixel_depth = png_ptr->user_transform_depth *\r
png_ptr->user_transform_channels;\r
\r
if (user_pixel_depth > max_pixel_depth)\r
* for safety's sake\r
*/\r
row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +\r
- 1 + ((max_pixel_depth + 7) >> 3);\r
+ 1 + ((max_pixel_depth + 7) >> 3U);\r
\r
#ifdef PNG_MAX_MALLOC_64K\r
if (row_bytes > (png_uint_32)65536L)\r
\r
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)\r
{\r
- png_free(png_ptr, png_ptr->big_row_buf);\r
- png_free(png_ptr, png_ptr->big_prev_row);\r
+ png_free(png_ptr, png_ptr->big_row_buf);\r
+ png_free(png_ptr, png_ptr->big_prev_row);\r
\r
- if (png_ptr->interlaced != 0)\r
- png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,\r
- row_bytes + 48);\r
+ if (png_ptr->interlaced != 0)\r
+ png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,\r
+ row_bytes + 48);\r
\r
- else\r
- png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\r
+ else\r
+ png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\r
\r
- png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\r
+ png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\r
\r
#ifdef PNG_ALIGNED_MEMORY_SUPPORTED\r
- /* Use 16-byte aligned memory for row_buf with at least 16 bytes\r
- * of padding before and after row_buf; treat prev_row similarly.\r
- * NOTE: the alignment is to the start of the pixels, one beyond the start\r
- * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this\r
- * was incorrect; the filter byte was aligned, which had the exact\r
- * opposite effect of that intended.\r
- */\r
- {\r
- png_bytep temp = png_ptr->big_row_buf + 32;\r
- int extra = (int)((temp - (png_bytep)0) & 0x0f);\r
- png_ptr->row_buf = temp - extra - 1/*filter byte*/;\r
-\r
- temp = png_ptr->big_prev_row + 32;\r
- extra = (int)((temp - (png_bytep)0) & 0x0f);\r
- png_ptr->prev_row = temp - extra - 1/*filter byte*/;\r
- }\r
+ /* Use 16-byte aligned memory for row_buf with at least 16 bytes\r
+ * of padding before and after row_buf; treat prev_row similarly.\r
+ * NOTE: the alignment is to the start of the pixels, one beyond the start\r
+ * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this\r
+ * was incorrect; the filter byte was aligned, which had the exact\r
+ * opposite effect of that intended.\r
+ */\r
+ {\r
+ png_bytep temp = png_ptr->big_row_buf + 32;\r
+ int extra = (int)((temp - (png_bytep)0) & 0x0f);\r
+ png_ptr->row_buf = temp - extra - 1/*filter byte*/;\r
+\r
+ temp = png_ptr->big_prev_row + 32;\r
+ extra = (int)((temp - (png_bytep)0) & 0x0f);\r
+ png_ptr->prev_row = temp - extra - 1/*filter byte*/;\r
+ }\r
\r
#else\r
- /* Use 31 bytes of padding before and 17 bytes after row_buf. */\r
- png_ptr->row_buf = png_ptr->big_row_buf + 31;\r
- png_ptr->prev_row = png_ptr->big_prev_row + 31;\r
+ /* Use 31 bytes of padding before and 17 bytes after row_buf. */\r
+ png_ptr->row_buf = png_ptr->big_row_buf + 31;\r
+ png_ptr->prev_row = png_ptr->big_prev_row + 31;\r
#endif\r
- png_ptr->old_big_row_buf_size = row_bytes + 48;\r
+ png_ptr->old_big_row_buf_size = row_bytes + 48;\r
}\r
\r
#ifdef PNG_MAX_MALLOC_64K\r
* does not, so free the read buffer now regardless; the sequential reader\r
* reallocates it on demand.\r
*/\r
- if (png_ptr->read_buffer != 0)\r
+ if (png_ptr->read_buffer != NULL)\r
{\r
png_bytep buffer = png_ptr->read_buffer;\r
\r