\r
/* pngset.c - storage of image information into info struct\r
*\r
- * Last changed in libpng 1.6.23 [June 9, 2016]\r
- * Copyright (c) 1998-2016 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-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
double green_x, double green_y, double blue_x, double blue_y)\r
{\r
png_set_cHRM_fixed(png_ptr, info_ptr,\r
- png_fixed(png_ptr, white_x, "cHRM White X"),\r
- png_fixed(png_ptr, white_y, "cHRM White Y"),\r
- png_fixed(png_ptr, red_x, "cHRM Red X"),\r
- png_fixed(png_ptr, red_y, "cHRM Red Y"),\r
- png_fixed(png_ptr, green_x, "cHRM Green X"),\r
- png_fixed(png_ptr, green_y, "cHRM Green Y"),\r
- png_fixed(png_ptr, blue_x, "cHRM Blue X"),\r
- png_fixed(png_ptr, blue_y, "cHRM Blue Y"));\r
+ png_fixed(png_ptr, white_x, "cHRM White X"),\r
+ png_fixed(png_ptr, white_y, "cHRM White Y"),\r
+ png_fixed(png_ptr, red_x, "cHRM Red X"),\r
+ png_fixed(png_ptr, red_y, "cHRM Red Y"),\r
+ png_fixed(png_ptr, green_x, "cHRM Green X"),\r
+ png_fixed(png_ptr, green_y, "cHRM Green Y"),\r
+ png_fixed(png_ptr, blue_x, "cHRM Blue X"),\r
+ png_fixed(png_ptr, blue_y, "cHRM Blue Y"));\r
}\r
\r
void PNGAPI\r
double blue_X, double blue_Y, double blue_Z)\r
{\r
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,\r
- png_fixed(png_ptr, red_X, "cHRM Red X"),\r
- png_fixed(png_ptr, red_Y, "cHRM Red Y"),\r
- png_fixed(png_ptr, red_Z, "cHRM Red Z"),\r
- png_fixed(png_ptr, green_X, "cHRM Green X"),\r
- png_fixed(png_ptr, green_Y, "cHRM Green Y"),\r
- png_fixed(png_ptr, green_Z, "cHRM Green Z"),\r
- png_fixed(png_ptr, blue_X, "cHRM Blue X"),\r
- png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),\r
- png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));\r
+ png_fixed(png_ptr, red_X, "cHRM Red X"),\r
+ png_fixed(png_ptr, red_Y, "cHRM Red Y"),\r
+ png_fixed(png_ptr, red_Z, "cHRM Red Z"),\r
+ png_fixed(png_ptr, green_X, "cHRM Green X"),\r
+ png_fixed(png_ptr, green_Y, "cHRM Green Y"),\r
+ png_fixed(png_ptr, green_Z, "cHRM Green Z"),\r
+ png_fixed(png_ptr, blue_X, "cHRM Blue X"),\r
+ png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),\r
+ png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));\r
}\r
# endif /* FLOATING_POINT */\r
\r
#endif /* cHRM */\r
\r
+#ifdef PNG_eXIf_SUPPORTED\r
+void PNGAPI\r
+png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,\r
+ png_bytep eXIf_buf)\r
+{\r
+ png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1");\r
+ PNG_UNUSED(info_ptr)\r
+ PNG_UNUSED(eXIf_buf)\r
+}\r
+\r
+void PNGAPI\r
+png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr,\r
+ png_uint_32 num_exif, png_bytep eXIf_buf)\r
+{\r
+ int i;\r
+\r
+ png_debug1(1, "in %s storage function", "eXIf");\r
+\r
+ if (png_ptr == NULL || info_ptr == NULL)\r
+ return;\r
+\r
+ if (info_ptr->exif)\r
+ {\r
+ png_free(png_ptr, info_ptr->exif);\r
+ info_ptr->exif = NULL;\r
+ }\r
+\r
+ info_ptr->num_exif = num_exif;\r
+\r
+ info_ptr->exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr,\r
+ info_ptr->num_exif));\r
+\r
+ if (info_ptr->exif == NULL)\r
+ {\r
+ png_warning(png_ptr, "Insufficient memory for eXIf chunk data");\r
+ return;\r
+ }\r
+\r
+ info_ptr->free_me |= PNG_FREE_EXIF;\r
+\r
+ for (i = 0; i < (int) info_ptr->num_exif; i++)\r
+ info_ptr->exif[i] = eXIf_buf[i];\r
+\r
+ info_ptr->valid |= PNG_INFO_eXIf;\r
+}\r
+#endif /* eXIf */\r
+\r
#ifdef PNG_gAMA_SUPPORTED\r
void PNGFAPI\r
png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,\r
png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,\r
int nparams, png_const_charp units, png_charpp params)\r
{\r
- png_size_t length;\r
+ size_t length;\r
int i;\r
\r
png_debug1(1, "in %s storage function", "pCAL");\r
\r
/* Check that the type matches the specification. */\r
if (type < 0 || type > 3)\r
- png_error(png_ptr, "Invalid pCAL equation type");\r
+ {\r
+ png_chunk_report(png_ptr, "Invalid pCAL equation type",\r
+ PNG_CHUNK_WRITE_ERROR);\r
+ return;\r
+ }\r
\r
if (nparams < 0 || nparams > 255)\r
- png_error(png_ptr, "Invalid pCAL parameter count");\r
+ {\r
+ png_chunk_report(png_ptr, "Invalid pCAL parameter count",\r
+ PNG_CHUNK_WRITE_ERROR);\r
+ return;\r
+ }\r
\r
/* Validate params[nparams] */\r
for (i=0; i<nparams; ++i)\r
{\r
if (params[i] == NULL ||\r
!png_check_fp_string(params[i], strlen(params[i])))\r
- png_error(png_ptr, "Invalid format for pCAL parameter");\r
+ {\r
+ png_chunk_report(png_ptr, "Invalid format for pCAL parameter",\r
+ PNG_CHUNK_WRITE_ERROR);\r
+ return;\r
+ }\r
}\r
\r
info_ptr->pcal_purpose = png_voidcast(png_charp,\r
\r
if (info_ptr->pcal_purpose == NULL)\r
{\r
- png_warning(png_ptr, "Insufficient memory for pCAL purpose");\r
-\r
+ png_chunk_report(png_ptr, "Insufficient memory for pCAL purpose",\r
+ PNG_CHUNK_WRITE_ERROR);\r
return;\r
}\r
\r
\r
length = strlen(units) + 1;\r
png_debug1(3, "allocating units for info (%lu bytes)",\r
- (unsigned long)length);\r
+ (unsigned long)length);\r
\r
info_ptr->pcal_units = png_voidcast(png_charp,\r
- png_malloc_warn(png_ptr, length));\r
+ png_malloc_warn(png_ptr, length));\r
\r
if (info_ptr->pcal_units == NULL)\r
{\r
memcpy(info_ptr->pcal_units, units, length);\r
\r
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,\r
- (png_size_t)((nparams + 1) * (sizeof (png_charp)))));\r
+ (size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp)))));\r
\r
if (info_ptr->pcal_params == NULL)\r
{\r
return;\r
}\r
\r
- memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));\r
+ memset(info_ptr->pcal_params, 0, ((unsigned int)nparams + 1) *\r
+ (sizeof (png_charp)));\r
\r
for (i = 0; i < nparams; i++)\r
{\r
png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,\r
int unit, png_const_charp swidth, png_const_charp sheight)\r
{\r
- png_size_t lengthw = 0, lengthh = 0;\r
+ size_t lengthw = 0, lengthh = 0;\r
\r
png_debug1(1, "in %s storage function", "sCAL");\r
\r
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);\r
\r
info_ptr->scal_s_width = png_voidcast(png_charp,\r
- png_malloc_warn(png_ptr, lengthw));\r
+ png_malloc_warn(png_ptr, lengthw));\r
\r
if (info_ptr->scal_s_width == NULL)\r
{\r
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);\r
\r
info_ptr->scal_s_height = png_voidcast(png_charp,\r
- png_malloc_warn(png_ptr, lengthh));\r
+ png_malloc_warn(png_ptr, lengthh));\r
\r
if (info_ptr->scal_s_height == NULL)\r
{\r
char sheight[PNG_sCAL_MAX_DIGITS+1];\r
\r
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,\r
- PNG_sCAL_PRECISION);\r
+ PNG_sCAL_PRECISION);\r
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,\r
- PNG_sCAL_PRECISION);\r
+ PNG_sCAL_PRECISION);\r
\r
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);\r
}\r
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));\r
\r
if (num_palette > 0)\r
- memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));\r
+ memcpy(png_ptr->palette, palette, (unsigned int)num_palette *\r
+ (sizeof (png_color)));\r
info_ptr->palette = png_ptr->palette;\r
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;\r
\r
{\r
png_charp new_iccp_name;\r
png_bytep new_iccp_profile;\r
- png_size_t length;\r
+ size_t length;\r
\r
png_debug1(1, "in %s storage function", "iCCP");\r
\r
*/\r
{\r
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,\r
- proflen, profile, info_ptr->color_type);\r
+ proflen, profile, info_ptr->color_type);\r
\r
png_colorspace_sync_info(png_ptr, info_ptr);\r
\r
\r
memcpy(new_iccp_name, name, length);\r
new_iccp_profile = png_voidcast(png_bytep,\r
- png_malloc_warn(png_ptr, proflen));\r
+ png_malloc_warn(png_ptr, proflen));\r
\r
if (new_iccp_profile == NULL)\r
{\r
* the overflow checks.\r
*/\r
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,\r
- info_ptr->text, old_num_text, max_text-old_num_text,\r
- sizeof *new_text));\r
+ info_ptr->text, old_num_text, max_text-old_num_text,\r
+ sizeof *new_text));\r
}\r
\r
if (new_text == NULL)\r
{\r
png_chunk_report(png_ptr, "too many text chunks",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
\r
return 1;\r
}\r
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)\r
{\r
png_chunk_report(png_ptr, "text compression mode is out of range",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
continue;\r
}\r
\r
# else /* iTXt */\r
{\r
png_chunk_report(png_ptr, "iTXt chunk not supported",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
continue;\r
}\r
# endif\r
if (textp->key == NULL)\r
{\r
png_chunk_report(png_ptr, "text chunk: out of memory",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
\r
return 1;\r
}\r
{\r
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */\r
info_ptr->trans_alpha = png_voidcast(png_bytep,\r
- png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));\r
- memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);\r
+ png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));\r
+ memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans);\r
}\r
png_ptr->trans_alpha = info_ptr->trans_alpha;\r
}\r
trans_color->green > sample_max ||\r
trans_color->blue > sample_max)))\r
png_warning(png_ptr,\r
- "tRNS chunk has out-of-range samples for bit_depth");\r
+ "tRNS chunk has out-of-range samples for bit_depth");\r
}\r
#endif\r
\r
* overflows. Notice that the parameters are (int) and (size_t)\r
*/\r
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,\r
- info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,\r
- sizeof *np));\r
+ info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,\r
+ sizeof *np));\r
\r
if (np == NULL)\r
{\r
\r
do\r
{\r
- png_size_t length;\r
+ size_t length;\r
\r
/* Skip invalid input entries */\r
if (entries->name == NULL || entries->entries == NULL)\r
* checked it when doing the allocation.\r
*/\r
memcpy(np->entries, entries->entries,\r
- entries->nentries * sizeof (png_sPLT_entry));\r
+ (unsigned int)entries->nentries * sizeof (png_sPLT_entry));\r
\r
/* Note that 'continue' skips the advance of the out pointer and out\r
* count, so an invalid entry is not added.\r
info_ptr->valid |= PNG_INFO_sPLT;\r
++(info_ptr->splt_palettes_num);\r
++np;\r
+ ++entries;\r
}\r
- while (++entries, --nentries);\r
+ while (--nentries);\r
\r
if (nentries > 0)\r
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);\r
{\r
/* Write struct, so unknown chunks come from the app */\r
png_app_warning(png_ptr,\r
- "png_set_unknown_chunks now expects a valid location");\r
+ "png_set_unknown_chunks now expects a valid location");\r
/* Use the old behavior */\r
location = (png_byte)(png_ptr->mode &\r
- (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));\r
+ (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));\r
}\r
\r
/* This need not be an internal error - if the app calls\r
\r
void PNGAPI\r
png_set_unknown_chunks(png_const_structrp png_ptr,\r
- png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)\r
+ png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)\r
{\r
png_unknown_chunkp np;\r
\r
* appropriate to read or write.\r
*/\r
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,\r
- info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,\r
- sizeof *np));\r
+ info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,\r
+ sizeof *np));\r
\r
if (np == NULL)\r
{\r
png_chunk_report(png_ptr, "too many unknown chunks",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
\r
return;\r
}\r
else\r
{\r
np->data = png_voidcast(png_bytep,\r
- png_malloc_base(png_ptr, unknowns->size));\r
+ png_malloc_base(png_ptr, unknowns->size));\r
\r
if (np->data == NULL)\r
{\r
png_chunk_report(png_ptr, "unknown chunk: out of memory",\r
- PNG_CHUNK_WRITE_ERROR);\r
+ PNG_CHUNK_WRITE_ERROR);\r
/* But just skip storing the unknown chunk */\r
continue;\r
}\r
{\r
png_app_error(png_ptr, "invalid unknown chunk location");\r
/* Fake out the pre 1.6.0 behavior: */\r
- if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */\r
+ if (((unsigned int)location & PNG_HAVE_IDAT) != 0) /* undocumented! */\r
location = PNG_AFTER_IDAT;\r
\r
else\r
/* Ignore all unknown chunks and all chunks recognized by\r
* libpng except for IHDR, PLTE, tRNS, IDAT, and IEND\r
*/\r
- static PNG_CONST png_byte chunks_to_ignore[] = {\r
+ static const png_byte chunks_to_ignore[] = {\r
98, 75, 71, 68, '\0', /* bKGD */\r
99, 72, 82, 77, '\0', /* cHRM */\r
+ 101, 88, 73, 102, '\0', /* eXIf */\r
103, 65, 77, 65, '\0', /* gAMA */\r
104, 73, 83, 84, '\0', /* hIST */\r
105, 67, 67, 80, '\0', /* iCCP */\r
return;\r
}\r
\r
- num_chunks = num_chunks_in;\r
+ num_chunks = (unsigned int)num_chunks_in;\r
}\r
\r
old_num_chunks = png_ptr->num_chunk_list;\r
for (i=0; i<num_chunks; ++i)\r
{\r
old_num_chunks = add_one_chunk(new_list, old_num_chunks,\r
- chunk_list+5*i, keep);\r
+ chunk_list+5*i, keep);\r
}\r
\r
/* Now remove any spurious 'default' entries. */\r
#endif\r
\r
void PNGAPI\r
-png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)\r
+png_set_compression_buffer_size(png_structrp png_ptr, size_t size)\r
{\r
- if (png_ptr == NULL)\r
- return;\r
+ if (png_ptr == NULL)\r
+ return;\r
\r
- if (size == 0 || size > PNG_UINT_31_MAX)\r
- png_error(png_ptr, "invalid compression buffer size");\r
+ if (size == 0 || size > PNG_UINT_31_MAX)\r
+ png_error(png_ptr, "invalid compression buffer size");\r
\r
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED\r
- if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\r
- {\r
- png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */\r
- return;\r
- }\r
+ if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\r
+ {\r
+ png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */\r
+ return;\r
+ }\r
# endif\r
\r
# ifdef PNG_WRITE_SUPPORTED\r
- if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\r
+ if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\r
+ {\r
+ if (png_ptr->zowner != 0)\r
{\r
- if (png_ptr->zowner != 0)\r
- {\r
- png_warning(png_ptr,\r
- "Compression buffer size cannot be changed because it is in use");\r
+ png_warning(png_ptr,\r
+ "Compression buffer size cannot be changed because it is in use");\r
\r
- return;\r
- }\r
+ return;\r
+ }\r
\r
#ifndef __COVERITY__\r
- /* Some compilers complain that this is always false. However, it\r
- * can be true when integer overflow happens.\r
- */\r
- if (size > ZLIB_IO_MAX)\r
- {\r
- png_warning(png_ptr,\r
- "Compression buffer size limited to system maximum");\r
- size = ZLIB_IO_MAX; /* must fit */\r
- }\r
+ /* Some compilers complain that this is always false. However, it\r
+ * can be true when integer overflow happens.\r
+ */\r
+ if (size > ZLIB_IO_MAX)\r
+ {\r
+ png_warning(png_ptr,\r
+ "Compression buffer size limited to system maximum");\r
+ size = ZLIB_IO_MAX; /* must fit */\r
+ }\r
#endif\r
\r
- if (size < 6)\r
- {\r
- /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH\r
- * if this is permitted.\r
- */\r
- png_warning(png_ptr,\r
- "Compression buffer size cannot be reduced below 6");\r
+ if (size < 6)\r
+ {\r
+ /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH\r
+ * if this is permitted.\r
+ */\r
+ png_warning(png_ptr,\r
+ "Compression buffer size cannot be reduced below 6");\r
\r
- return;\r
- }\r
+ return;\r
+ }\r
\r
- if (png_ptr->zbuffer_size != size)\r
- {\r
- png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);\r
- png_ptr->zbuffer_size = (uInt)size;\r
- }\r
+ if (png_ptr->zbuffer_size != size)\r
+ {\r
+ png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);\r
+ png_ptr->zbuffer_size = (uInt)size;\r
}\r
+ }\r
# endif\r
}\r
\r
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)\r
{\r
if (png_ptr != NULL && info_ptr != NULL)\r
- info_ptr->valid &= ~mask;\r
+ info_ptr->valid &= (unsigned int)(~mask);\r
}\r
\r
\r
png_uint_32 /* PRIVATE */\r
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)\r
{\r
+#ifdef PNG_WARNINGS_SUPPORTED\r
png_const_charp orig_key = key;\r
+#endif\r
png_uint_32 key_len = 0;\r
int bad_character = 0;\r
int space = 1;\r
png_byte ch = (png_byte)*key++;\r
\r
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))\r
- *new_key++ = ch, ++key_len, space = 0;\r
+ {\r
+ *new_key++ = ch; ++key_len; space = 0;\r
+ }\r
\r
else if (space == 0)\r
{\r
/* A space or an invalid character when one wasn't seen immediately\r
* before; output just a space.\r
*/\r
- *new_key++ = 32, ++key_len, space = 1;\r
+ *new_key++ = 32; ++key_len; space = 1;\r
\r
/* If the character was not a space then it is invalid. */\r
if (ch != 32)\r
\r
if (key_len > 0 && space != 0) /* trailing space */\r
{\r
- --key_len, --new_key;\r
+ --key_len; --new_key;\r
if (bad_character == 0)\r
bad_character = 32;\r
}\r
\r
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");\r
}\r
-#endif /* WARNINGS */\r
+#else /* !WARNINGS */\r
+ PNG_UNUSED(png_ptr)\r
+#endif /* !WARNINGS */\r
\r
return key_len;\r
}\r