Imported from libpng-1.2.0beta2.tar
diff --git a/pngset.c b/pngset.c
index f851fac..096d44c 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
- * libpng 1.2.0beta1 - May 6, 2001
+ * libpng 1.2.0beta2 - May 7, 2001
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -109,9 +109,10 @@
info_ptr->int_gamma = (int)(file_gamma*100000.+.5);
#endif
info_ptr->valid |= PNG_INFO_gAMA;
+ if(file_gamma == 0.0)
+ png_warning(png_ptr, "Setting gamma=0");
}
#endif
-#endif
void PNGAPI
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
int_gamma)
@@ -127,7 +128,10 @@
info_ptr->int_gamma = int_gamma;
#endif
info_ptr->valid |= PNG_INFO_gAMA;
+ if(int_gamma == 0)
+ png_warning(png_ptr, "Setting gamma=0");
}
+#endif
#if defined(PNG_hIST_SUPPORTED)
void PNGAPI
@@ -139,8 +143,11 @@
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->num_palette == 0)
+ {
png_warning(png_ptr,
- "Palette size 0, hIST allocation skipped.");
+ "Palette size 0, hIST allocation skipped.");
+ return;
+ }
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
@@ -172,6 +179,61 @@
if (png_ptr == NULL || info_ptr == NULL)
return;
+ /* check for width and height valid values */
+ if (width == 0 || height == 0)
+ png_error(png_ptr, "Image width or height is zero in IHDR");
+ if (width > PNG_MAX_UINT || height > PNG_MAX_UINT)
+ png_error(png_ptr, "Invalid image size in IHDR");
+
+ /* check other values */
+ if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
+ bit_depth != 8 && bit_depth != 16)
+ png_error(png_ptr, "Invalid bit depth in IHDR");
+
+ if (color_type < 0 || color_type == 1 ||
+ color_type == 5 || color_type > 6)
+ png_error(png_ptr, "Invalid color type in IHDR");
+
+ if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
+ ((color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
+ png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
+
+ if (interlace_type >= PNG_INTERLACE_LAST)
+ png_error(png_ptr, "Unknown interlace method in IHDR");
+
+ if (compression_type != PNG_COMPRESSION_TYPE_BASE)
+ png_error(png_ptr, "Unknown compression method in IHDR");
+
+#if defined(PNG_MNG_FEATURES_SUPPORTED)
+ /* Accept filter_method 64 (intrapixel differencing) only if
+ * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
+ * 2. Libpng did not read a PNG signature (this filter_method is only
+ * used in PNG datastreams that are embedded in MNG datastreams) and
+ * 3. The application called png_permit_mng_features with a mask that
+ * included PNG_FLAG_MNG_FILTER_64 and
+ * 4. The filter_method is 64 and
+ * 5. The color_type is RGB or RGBA
+ */
+ if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
+ png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
+ if(filter_type != PNG_FILTER_TYPE_BASE)
+ {
+ if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
+ (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
+ ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
+ (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
+ png_error(png_ptr, "Unknown filter method in IHDR");
+ if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
+ png_warning(png_ptr, "Invalid filter method in IHDR");
+ }
+#else
+ if(filter_type != PNG_FILTER_TYPE_BASE)
+ png_error(png_ptr, "Unknown filter method in IHDR");
+#endif
+
info_ptr->width = width;
info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth;
@@ -248,6 +310,7 @@
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
+
info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++)
@@ -302,7 +365,7 @@
length = png_strlen(sheight) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
- info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length);
+ info_ptr->scal_s_height = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
info_ptr->valid |= PNG_INFO_sCAL;
@@ -349,7 +412,7 @@
#endif
png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
sizeof (png_color));
- memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
+ png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -472,9 +535,9 @@
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
- new_iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
- strcpy(new_iccp_name, name);
- new_iccp_profile = png_malloc(png_ptr, proflen);
+ new_iccp_name = (png_charp)png_malloc(png_ptr, png_strlen(name)+1);
+ png_strcpy(new_iccp_name, name);
+ new_iccp_profile = (png_charp)png_malloc(png_ptr, proflen);
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
@@ -543,7 +606,7 @@
png_size_t lang_len,lang_key_len;
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
- if (text_ptr[i].key == (png_charp)NULL)
+ if (text_ptr[i].key == NULL)
continue;
key_len = png_strlen(text_ptr[i].key);
@@ -557,11 +620,11 @@
#ifdef PNG_iTXt_SUPPORTED
{
/* set iTXt data */
- if (text_ptr[i].key != (png_charp)NULL)
+ if (text_ptr[i].key != NULL)
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
- if (text_ptr[i].lang_key != (png_charp)NULL)
+ if (text_ptr[i].lang_key != NULL)
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
@@ -573,7 +636,7 @@
}
#endif
- if (text_ptr[i].text == (png_charp)NULL || text_ptr[i].text[0] == '\0')
+ if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
{
text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
@@ -676,8 +739,9 @@
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif
- png_ptr->trans = info_ptr->trans = png_malloc(png_ptr, num_trans);
- memcpy(info_ptr->trans, trans, num_trans);
+ png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
+ num_trans);
+ png_memcpy(info_ptr->trans, trans, num_trans);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS;
#else
@@ -719,12 +783,12 @@
png_sPLT_tp from = entries + i;
to->name = (png_charp)png_malloc(png_ptr,
- png_strlen(from->name) + 1);
+ png_strlen(from->name) + 1);
png_strcpy(to->name, from->name);
to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
- from->nentries * sizeof(png_sPLT_t));
+ from->nentries * sizeof(png_sPLT_t));
png_memcpy(to->entries, from->entries,
- from->nentries * sizeof(png_sPLT_t));
+ from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries;
to->depth = from->depth;
}
@@ -738,7 +802,7 @@
}
#endif /* PNG_sPLT_SUPPORTED */
-#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
+#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void PNGAPI
png_set_unknown_chunks(png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
@@ -840,8 +904,8 @@
if (chunk_list == NULL)
return;
old_num_chunks=png_ptr->num_chunk_list;
- new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks));
- if(png_ptr->chunk_list != (png_bytep)NULL)
+ new_list=(png_bytep)png_malloc(png_ptr,5*(num_chunks+old_num_chunks));
+ if(png_ptr->chunk_list != NULL)
{
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
png_free(png_ptr, png_ptr->chunk_list);
@@ -883,7 +947,6 @@
info_ptr->row_pointers = row_pointers;
if(row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
-
}
#endif
@@ -894,8 +957,6 @@
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
- if(!png_ptr->zbuf)
- png_error(png_ptr,"Unable to malloc zbuf");
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}