[libpng17] Prevent setting or writing over-length PLTE chunk (Cosmin Truta).

Silently truncate over-length PLTE chunk while reading.
This commit is contained in:
Glenn Randers-Pehrson
2015-11-01 13:01:56 -06:00
parent 5b05197604
commit 9f7d5aa973
5 changed files with 42 additions and 17 deletions

View File

@@ -911,17 +911,20 @@ void /* PRIVATE */
png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
unsigned int num_pal)
{
png_uint_32 i;
png_uint_32 max_palette_length, i;
png_const_colorp pal_ptr;
png_byte buf[3];
png_debug(1, "in png_write_PLTE");
max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?
(1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;
if ((
# ifdef PNG_MNG_FEATURES_SUPPORTED
(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&
# endif /* MNG_FEATURES */
num_pal == 0) || num_pal > PNG_MAX_PALETTE_LENGTH)
num_pal == 0) || num_pal > max_palette_length)
{
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{