From f604c74a5f06d939c9940adc8fc481e0a5f96870 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Fri, 20 Jan 2017 14:46:21 -0600 Subject: [PATCH] [libpng16] Avoid conditional directives that break statements in pngrutil.c (Romero Malaquias) --- ANNOUNCE | 6 ++++-- CHANGES | 4 +++- pngwutil.c | 15 +++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 6dd2058da..f9828884c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -Libpng 1.6.29beta02 - January 12, 2017 +Libpng 1.6.29beta02 - January 20, 2017 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. @@ -32,7 +32,9 @@ Version 1.6.29beta01 [January 12, 2017] libpng with "-DPNG_INTEL_SSE" in CPPFLAGS to enable it. Simplified conditional compilation in pngvalid.c, for AIX (Michael Felt). -Version 1.6.29beta02 [January 12, 2017] +Version 1.6.29beta02 [January 20, 2017] + Avoid conditional directives that break statements in pngrutil.c (Romero + Malaquias) Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index b7b7e1666..fda475b4c 100644 --- a/CHANGES +++ b/CHANGES @@ -5801,7 +5801,9 @@ Version 1.6.29beta01 [January 12, 2017] libpng with "-DPNG_INTEL_SSE" in CPPFLAGS to enable it. Simplified conditional compilation in pngvalid.c, for AIX (Michael Felt). -Version 1.6.29beta02 [January 12, 2017] +Version 1.6.29beta02 [January 20, 2017] + Avoid conditional directives that break statements in pngrutil.c (Romero + Malaquias) Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngwutil.c b/pngwutil.c index 87d4981f4..0f98d582d 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -675,10 +675,9 @@ png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height, int interlace_type) { png_byte buf[13]; /* Buffer to store the IHDR info */ + int is_invalid_depth; png_debug(1, "in png_write_IHDR"); - - int is_invalid_depth; /* Check that we have valid input data from the application info */ switch (color_type) @@ -728,18 +727,22 @@ png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height, break; case PNG_COLOR_TYPE_GRAY_ALPHA: - if (bit_depth != 8 && bit_depth != 16) + is_invalid_depth = (bit_depth != 8); +#ifdef PNG_WRITE_16BIT_SUPPORTED + is_invalid_depth = (is_invalid_depth && bit_depth != 16); +#endif + if (is_invalid_depth) png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); png_ptr->channels = 2; break; case PNG_COLOR_TYPE_RGB_ALPHA: + is_invalid_depth = (bit_depth != 8); #ifdef PNG_WRITE_16BIT_SUPPORTED - if (bit_depth != 8 && bit_depth != 16) -#else - if (bit_depth != 8) + is_invalid_depth = (is_invalid_depth && bit_depth != 16); #endif + if (is_invalid_depth) png_error(png_ptr, "Invalid bit depth for RGBA image"); png_ptr->channels = 4;