From 2e8aa25844711968788f6ab80257d1102b950e6e Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sat, 31 Oct 2009 19:20:20 -0500 Subject: [PATCH] [master] Apply png_user_chunk_cache_max within png_decompress_chunk(). --- ANNOUNCE | 5 +++-- CHANGES | 5 +++-- pngread.c | 14 +++++++++----- pngrutil.c | 22 ++++++++++++++++++---- pngset.c | 9 ++++++--- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 2c3e864b..a73e567c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.2.41beta09 - October 31, 2009 +Libpng 1.2.41beta09 - November 1, 2009 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -84,10 +84,11 @@ version 1.2.41beta08 [October 30, 2009] Relocated png_do_chop() ahead of building gamma tables in pngrtran.c This avoids building 16-bit gamma tables unnecessarily. -version 1.2.41beta09 [October 31, 2009] +version 1.2.41beta09 [November 1, 2009] Removed a harmless extra png_set_invert_alpha() from pngwrite.c More bugfixes and improvements to CMakeLists.txt (Philip Lowman) Moved CMakeLists.txt from scripts into the main libpng directory. + Apply png_user_chunk_cache_max within png_decompress_chunk(). Send comments/corrections/commendations to png-mng-implement at lists.sf.net diff --git a/CHANGES b/CHANGES index 4594a5bc..c47c72bc 100644 --- a/CHANGES +++ b/CHANGES @@ -2466,7 +2466,7 @@ version 1.2.40beta01 [August 20, 2009] version 1.2.40rc01 [September 2, 2009] Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) -version 1.2.40 and 1.0.49 [October 31, 2009] +version 1.2.40 and 1.0.49 [November 1, 2009] No changes. version 1.0.50 [September 10, 2009] @@ -2514,10 +2514,11 @@ version 1.2.41beta08 [October 30, 2009] Relocated png_do_chop() ahead of building gamma tables in pngrtran.c This avoids building 16-bit gamma tables unnecessarily. -version 1.2.41beta09 [October 31, 2009] +version 1.2.41beta09 [November 1, 2009] Removed a harmless extra png_set_invert_alpha() from pngwrite.c More bugfixes and improvements to CMakeLists.txt (Philip Lowman) Moved CMakeLists.txt from scripts into the main libpng directory. + Apply png_user_chunk_cache_max within png_decompress_chunk(). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngread.c b/pngread.c index 5526cbe9..431797b6 100644 --- a/pngread.c +++ b/pngread.c @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.2.41 [October 30, 2009] + * Last changed in libpng 1.2.41 [November 1, 2009] * Copyright (c) 1998-2009 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.) @@ -64,8 +64,10 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, /* Added at libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_ptr->user_width_max=PNG_USER_WIDTH_MAX; - png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; + /* Added at libpng-1.2.41 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; #endif #ifdef PNG_SETJMP_SUPPORTED @@ -299,8 +301,10 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, /* Added at libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_ptr->user_width_max=PNG_USER_WIDTH_MAX; - png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; + /* Added at libpng-1.2.41 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; #endif /* Initialize zbuf - compression buffer */ diff --git a/pngrutil.c b/pngrutil.c index a696db80..cbd8e9bc 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.2.41 [October 30, 2009] + * Last changed in libpng 1.2.41 [November 1, 2009] * Copyright (c) 1998-2009 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.) @@ -322,9 +322,23 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_charp tmp; tmp = text; - text = (png_charp)png_malloc_warn(png_ptr, - (png_uint_32)(text_size + - png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if ((png_ptr->user_chunk_cache_max != 0) && + (--png_ptr->user_chunk_cache_max == 0)) + { + png_warning(png_ptr, "No space in chunk cache"); + text = NULL; + } + + else + { +#endif + text = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)(text_size + + png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + } +#endif if (text == NULL) { png_free(png_ptr, tmp); diff --git a/pngset.c b/pngset.c index 200a1f46..6841096c 100644 --- a/pngset.c +++ b/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.2.41 [October 30, 2009] + * Last changed in libpng 1.2.41 [November 1, 2009] * Copyright (c) 1998-2009 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.) @@ -716,6 +716,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, lang_len = 0; lang_key_len = 0; } + else #ifdef PNG_iTXt_SUPPORTED { @@ -729,6 +730,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, else lang_key_len = 0; } + #else { png_warning(png_ptr, "iTXt chunk not supported."); @@ -746,6 +748,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, #endif textp->compression = PNG_TEXT_COMPRESSION_NONE; } + else { text_length = png_strlen(text_ptr[i].text); @@ -797,6 +800,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } else #endif + { textp->text_length = text_length; #ifdef PNG_iTXt_SUPPORTED @@ -837,8 +841,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, if (trans != NULL) { - /* - * It may not actually be necessary to set png_ptr->trans here; + /* It may not actually be necessary to set png_ptr->trans here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation. */