From e0e239ada02296dff3cb176b2dbe417ecd29302c Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sat, 31 Jan 2015 13:54:10 -0600 Subject: [PATCH] [libpng12] Quieted some harmless warnings from Coverity-scan. --- ANNOUNCE | 1 + CHANGES | 1 + pngget.c | 13 ++++++++----- pngread.c | 8 +++++--- pngrtran.c | 34 +++++++++++++++++++++++----------- pngrutil.c | 23 ++++++++++++++++------- pngset.c | 4 ++-- pngwrite.c | 12 ++++++------ pngwutil.c | 12 +++++++++--- 9 files changed, 71 insertions(+), 37 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index c8780b2c..674e3137 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -48,6 +48,7 @@ version 1.2.53beta01 [RDATE%] potentially too large for the architecture, in case the calling application has overridden the default 1,000,000-column limit (fixes CVE-2014-9495 and CVE-2015-0973). + Quieted some harmless warnings from Coverity-scan. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index ed26a043..9953144c 100644 --- a/CHANGES +++ b/CHANGES @@ -2833,6 +2833,7 @@ version 1.2.53beta01 [RDATE%] potentially too large for the architecture, in case the calling application has overridden the default 1,000,000-column limit (fixes CVE-2014-9495 and CVE-2015-0973). + Quieted some harmless warnings from Coverity-scan. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngget.c b/pngget.c index c5d65433..cc824b39 100644 --- a/pngget.c +++ b/pngget.c @@ -1,8 +1,8 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.2.51 [February 6, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -885,7 +885,8 @@ png_uint_32 PNGAPI png_get_asm_flags (png_structp png_ptr) { /* Obsolete, to be removed from libpng-1.4.0 */ - return (png_ptr? 0L: 0L); + PNG_UNUSED(png_ptr) + return 0L; } /* This function was added to libpng 1.2.0 and should exist by default */ @@ -913,7 +914,8 @@ png_byte PNGAPI png_get_mmx_bitdepth_threshold (png_structp png_ptr) { /* Obsolete, to be removed from libpng-1.4.0 */ - return (png_ptr? 0: 0); + PNG_UNUSED(png_ptr) + return 0L; } /* This function was added to libpng 1.2.0 */ @@ -921,7 +923,8 @@ png_uint_32 PNGAPI png_get_mmx_rowbytes_threshold (png_structp png_ptr) { /* Obsolete, to be removed from libpng-1.4.0 */ - return (png_ptr? 0L: 0L); + PNG_UNUSED(png_ptr) + return 0L; } #endif /* ?PNG_1_0_X */ #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ diff --git a/pngread.c b/pngread.c index 24277b18..bbe015f6 100644 --- a/pngread.c +++ b/pngread.c @@ -1,8 +1,8 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.2.52 [November 20, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -274,7 +274,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, do { - if (user_png_ver[i] != png_libpng_ver[i]) + if (user_png_ver == NULL || user_png_ver[i] != png_libpng_ver[i]) { #ifdef PNG_LEGACY_SUPPORTED png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; @@ -597,10 +597,12 @@ png_start_read_image(png_structp png_ptr) void PNGAPI png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) { +#ifndef PNG_USE_GLOBAL_ARRAYS PNG_CONST PNG_IDAT; PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; +#endif int ret; if (png_ptr == NULL) diff --git a/pngrtran.c b/pngrtran.c index 0a760cef..0254d832 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,8 +1,8 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.2.51 [February 6, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -2410,10 +2410,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) for (i = 0; i < row_width; i++) { png_uint_16 red, green, blue, w; + png_byte hi,lo; - red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + hi=*(sp)++; lo=*(sp)++; + red = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + green = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + blue = (png_uint_16)((hi << 8) | (lo)); if (red == green && red == blue) w = red; @@ -2445,10 +2449,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) for (i = 0; i < row_width; i++) { png_uint_16 red, green, blue, gray16; + png_byte hi,lo; - red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + hi=*(sp)++; lo=*(sp)++; + red = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + green = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + blue = (png_uint_16)((hi << 8) | (lo)); if (red != green || red != blue) rgb_error |= 1; @@ -2508,10 +2516,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) for (i = 0; i < row_width; i++) { png_uint_16 red, green, blue, w; + png_byte hi,lo; - red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + hi=*(sp)++; lo=*(sp)++; + red = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + green = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; + blue = (png_uint_16)((hi << 8) | (lo)); if (red == green && red == blue) w = red; diff --git a/pngrutil.c b/pngrutil.c index 543b7e0e..7c388635 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,8 +1,8 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.2.51 [February 6, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -60,7 +60,7 @@ png_get_uint_31(png_structp png_ptr, png_bytep buf) png_uint_32 i = ((png_uint_32)(*buf) << 24) + ((png_uint_32)(*(buf + 1)) << 16) + ((png_uint_32)(*(buf + 2)) << 8) + - (png_uint_32)(*(buf + 3)); + ((png_uint_32)(*(buf + 3)) ); #endif if (i > PNG_UINT_31_MAX) png_error(png_ptr, "PNG unsigned integer out of range."); @@ -294,12 +294,15 @@ png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size, png_snprintf(umsg, sizeof umsg, msg, png_ptr->chunk_name); msg = umsg; + png_warning(png_ptr, msg); #else msg = "Damaged compressed datastream in chunk other than IDAT"; #endif } +#ifndef PNG_STDIO_SUPPORTED png_warning(png_ptr, msg); +#endif } /* 0 means an error - notice that this code simple ignores @@ -1130,10 +1133,10 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Check the profile_size recorded in the first 32 bits of the ICC profile */ pC = (png_bytep)(png_ptr->chunkdata + prefix_length); - profile_size = ((*(pC ))<<24) | - ((*(pC + 1))<<16) | - ((*(pC + 2))<< 8) | - ((*(pC + 3)) ); + profile_size = ((png_uint_32) (*(pC )<<24)) | + ((png_uint_32) (*(pC + 1)<<16)) | + ((png_uint_32) (*(pC + 2)<< 8)) | + ((png_uint_32) (*(pC + 3) )); if (profile_size < profile_length) profile_length = profile_size; @@ -2714,7 +2717,9 @@ png_do_read_interlace(png_structp png_ptr) png_uint_32 transformations = png_ptr->transformations; /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Offset to next interlace block */ +#ifndef PNG_USE_GLOBAL_ARRAYS PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; +#endif png_debug(1, "in png_do_read_interlace"); if (row != NULL && row_info != NULL) @@ -3054,6 +3059,7 @@ void /* PRIVATE */ png_read_finish_row(png_structp png_ptr) { #ifdef PNG_READ_INTERLACING_SUPPORTED +#ifndef PNG_USE_GLOBAL_ARRAYS /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ @@ -3067,6 +3073,7 @@ png_read_finish_row(png_structp png_ptr) /* Offset to next interlace block in the y direction */ PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif #endif /* PNG_READ_INTERLACING_SUPPORTED */ png_debug(1, "in png_read_finish_row"); @@ -3182,6 +3189,7 @@ void /* PRIVATE */ png_read_start_row(png_structp png_ptr) { #ifdef PNG_READ_INTERLACING_SUPPORTED +#ifndef PNG_USE_GLOBAL_ARRAYS /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ @@ -3195,6 +3203,7 @@ png_read_start_row(png_structp png_ptr) /* Offset to next interlace block in the y direction */ PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif #endif int max_pixel_depth; diff --git a/pngset.c b/pngset.c index 809a6d9c..6793787d 100644 --- a/pngset.c +++ b/pngset.c @@ -1,8 +1,8 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.2.51 [February 6, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * diff --git a/pngwrite.c b/pngwrite.c index 894a9843..251ac552 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,8 +1,8 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.2.52 [November 20, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -1201,14 +1201,13 @@ png_set_filter(png_structp png_ptr, int method, int filters) { switch (filters & (PNG_ALL_FILTERS | 0x07)) { + case PNG_FILTER_VALUE_NONE: + png_ptr->do_filter = PNG_FILTER_NONE; break; #ifdef PNG_WRITE_FILTER_SUPPORTED case 5: case 6: case 7: png_warning(png_ptr, "Unknown row filter for method 0"); -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - case PNG_FILTER_VALUE_NONE: - png_ptr->do_filter = PNG_FILTER_NONE; break; -#ifdef PNG_WRITE_FILTER_SUPPORTED + break; case PNG_FILTER_VALUE_SUB: png_ptr->do_filter = PNG_FILTER_SUB; break; case PNG_FILTER_VALUE_UP: @@ -1220,6 +1219,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) default: png_ptr->do_filter = (png_byte)filters; break; #else default: png_warning(png_ptr, "Unknown row filter for method 0"); + break; #endif /* PNG_WRITE_FILTER_SUPPORTED */ } diff --git a/pngwutil.c b/pngwutil.c index c75f53eb..fa398353 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,8 +1,8 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.2.43 [February 25, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.2.53 [%RDATE%] + * Copyright (c) 1998-2015 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.) * @@ -254,7 +254,7 @@ png_text_compress(png_structp png_ptr, old_ptr = comp->output_ptr; comp->output_ptr = (png_charpp)png_malloc(png_ptr, (png_uint_32) - (comp->max_output_ptr * png_sizeof(png_charpp))); + (comp->max_output_ptr * png_sizeof(png_charp))); png_memcpy(comp->output_ptr, old_ptr, old_max * png_sizeof(png_charp)); png_free(png_ptr, old_ptr); @@ -1759,6 +1759,7 @@ void /* PRIVATE */ png_write_start_row(png_structp png_ptr) { #ifdef PNG_WRITE_INTERLACING_SUPPORTED +#ifndef PNG_USE_GLOBAL_ARRAYS /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ @@ -1772,6 +1773,7 @@ png_write_start_row(png_structp png_ptr) /* Offset to next interlace block in the y direction */ int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif #endif png_size_t buf_size; @@ -1857,6 +1859,7 @@ void /* PRIVATE */ png_write_finish_row(png_structp png_ptr) { #ifdef PNG_WRITE_INTERLACING_SUPPORTED +#ifndef PNG_USE_GLOBAL_ARRAYS /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Start of interlace block */ @@ -1870,6 +1873,7 @@ png_write_finish_row(png_structp png_ptr) /* Offset to next interlace block in the y direction */ int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif #endif int ret; @@ -1976,11 +1980,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) { /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ +#ifndef PNG_USE_GLOBAL_ARRAYS /* Start of interlace block */ int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; /* Offset to next interlace block */ int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; +#endif png_debug(1, "in png_do_write_interlace");