diff options
author | Casimir666 <casimir666@users.sourceforge.net> | 2007-05-06 18:55:57 +0400 |
---|---|---|
committer | Casimir666 <casimir666@users.sourceforge.net> | 2007-05-06 18:55:57 +0400 |
commit | f3e882346fd6d58a6c82477b9559e56b3ab0ec2b (patch) | |
tree | b71878d61f65b2c81289ddd0f14e4675877464f9 /src/libpng | |
parent | ee19999dc6b7d7e8805f3210265f692404249c6f (diff) |
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@76 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/libpng')
-rw-r--r-- | src/libpng/png.c | 37 | ||||
-rw-r--r-- | src/libpng/png.h | 94 | ||||
-rw-r--r-- | src/libpng/pngconf.h | 17 | ||||
-rw-r--r-- | src/libpng/pngerror.c | 23 | ||||
-rw-r--r-- | src/libpng/pnggccrd.c | 82 | ||||
-rw-r--r-- | src/libpng/pngget.c | 30 | ||||
-rw-r--r-- | src/libpng/pngmem.c | 14 | ||||
-rw-r--r-- | src/libpng/pngpread.c | 19 | ||||
-rw-r--r-- | src/libpng/pngread.c | 28 | ||||
-rw-r--r-- | src/libpng/pngrio.c | 5 | ||||
-rw-r--r-- | src/libpng/pngrtran.c | 56 | ||||
-rw-r--r-- | src/libpng/pngrutil.c | 40 | ||||
-rw-r--r-- | src/libpng/pngset.c | 20 | ||||
-rw-r--r-- | src/libpng/pngtest.c | 46 | ||||
-rw-r--r-- | src/libpng/pngtrans.c | 21 | ||||
-rw-r--r-- | src/libpng/pngwio.c | 8 | ||||
-rw-r--r-- | src/libpng/pngwrite.c | 9 | ||||
-rw-r--r-- | src/libpng/pngwutil.c | 90 |
18 files changed, 433 insertions, 206 deletions
diff --git a/src/libpng/png.c b/src/libpng/png.c index 3fe66400d..f8d6950c4 100644 --- a/src/libpng/png.c +++ b/src/libpng/png.c @@ -1,9 +1,9 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) */ @@ -13,7 +13,7 @@ #include "png.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_2_10 Your_png_h_is_not_version_1_2_10; +typedef version_1_2_16 Your_png_h_is_not_version_1_2_16; /* Version information for C files. This had better match the version * string defined in png.h. */ @@ -97,6 +97,7 @@ const int FARDATA png_pass_dsp_mask[] void PNGAPI png_set_sig_bytes(png_structp png_ptr, int num_bytes) { + if(png_ptr == NULL) return; png_debug(1, "in png_set_sig_bytes\n"); if (num_bytes > 8) png_error(png_ptr, "Too many bytes for PNG signature."); @@ -153,13 +154,14 @@ voidpf /* private */ png_zalloc(voidpf png_ptr, uInt items, uInt size) { png_voidp ptr; - png_structp p=png_ptr; + png_structp p=(png_structp)png_ptr; png_uint_32 save_flags=p->flags; png_uint_32 num_bytes; + if(png_ptr == NULL) return (NULL); if (items > PNG_UINT_32_MAX/size) { - png_warning (png_ptr, "Potential overflow in png_zalloc()"); + png_warning (p, "Potential overflow in png_zalloc()"); return (NULL); } num_bytes = (png_uint_32)items * size; @@ -266,6 +268,7 @@ void PNGAPI png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) { png_infop info_ptr = NULL; + if(png_ptr == NULL) return; png_debug(1, "in png_destroy_info_struct\n"); if (info_ptr_ptr != NULL) @@ -304,6 +307,8 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) { png_infop info_ptr = *ptr_ptr; + if(info_ptr == NULL) return; + png_debug(1, "in png_info_init_3\n"); if(png_sizeof(png_info) > png_info_struct_size) @@ -611,6 +616,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) png_voidp PNGAPI png_get_io_ptr(png_structp png_ptr) { + if(png_ptr == NULL) return (NULL); return (png_ptr->io_ptr); } @@ -626,6 +632,7 @@ void PNGAPI png_init_io(png_structp png_ptr, png_FILE_p fp) { png_debug(1, "in png_init_io\n"); + if(png_ptr == NULL) return; png_ptr->io_ptr = (png_voidp)fp; } #endif @@ -641,6 +648,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + if(png_ptr == NULL) return (NULL); if (png_ptr->time_buffer == NULL) { png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* @@ -693,8 +701,8 @@ png_charp PNGAPI png_get_copyright(png_structp png_ptr) { if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return ((png_charp) "\n libpng version 1.2.10 - April 23, 2006\n\ - Copyright (c) 1998-2006 Glenn Randers-Pehrson\n\ + return ((png_charp) "\n libpng version 1.2.16 - January 31, 2007\n\ + Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\ Copyright (c) 1996-1997 Andreas Dilger\n\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); return ((png_charp) ""); @@ -757,6 +765,7 @@ png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) int PNGAPI png_reset_zstream(png_structp png_ptr) { + if (png_ptr == NULL) return Z_STREAM_ERROR; return (inflateReset(&png_ptr->zstream)); } #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ @@ -770,14 +779,14 @@ png_access_version_number(void) } -#if defined(PNG_READ_SUPPORTED) +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) #if !defined(PNG_1_0_X) -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) - /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ +#if defined(PNG_MMX_CODE_SUPPORTED) /* this INTERNAL function was added to libpng 1.2.0 */ void /* PRIVATE */ png_init_mmx_flags (png_structp png_ptr) { + if(png_ptr == NULL) return; png_ptr->mmx_rowbytes_threshold = 0; png_ptr->mmx_bitdepth_threshold = 0; @@ -810,7 +819,7 @@ png_init_mmx_flags (png_structp png_ptr) | PNG_MMX_WRITE_FLAGS ); } -# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */ +# else /* !(PNGVCRD || PNGGCCRD) */ /* clear all MMX flags; no support is compiled in */ png_ptr->asm_flags &= ~( PNG_MMX_FLAGS ); @@ -818,18 +827,18 @@ png_init_mmx_flags (png_structp png_ptr) # endif /* ?(PNGVCRD || PNGGCCRD) */ } -#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */ +#endif /* !(PNG_MMX_CODE_SUPPORTED) */ /* this function was added to libpng 1.2.0 */ #if !defined(PNG_USE_PNGGCCRD) && \ - !(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)) + !(defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)) int PNGAPI png_mmx_support(void) { return -1; } #endif -#endif /* PNG_1_0_X */ +#endif /* PNG_1_0_X && PNG_ASSEMBLER_CODE_SUPPORTED */ #endif /* PNG_READ_SUPPORTED */ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) diff --git a/src/libpng/png.h b/src/libpng/png.h index 4e8582a9e..1793e9df7 100644 --- a/src/libpng/png.h +++ b/src/libpng/png.h @@ -1,15 +1,15 @@ /* png.h - header file for PNG reference library * - * libpng version 1.2.10 - April 23, 2006 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * libpng version 1.2.16 - January 31, 2007 + * Copyright (c) 1998-2007 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.) * * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.2.10 - April 23, 2006: Glenn + * libpng versions 0.97, January 1998, through 1.2.16 - January 31, 2007: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -103,14 +103,14 @@ * 1.0.16 10 10016 10.so.0.1.0.16 * 1.2.6 13 10206 12.so.0.1.2.6 * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 - * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 + * 1.0.17rc1 10 10017 10.so.0.1.0.17rc1 * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 - * 1.0.17 10 10017 12.so.0.1.0.17 + * 1.0.17 10 10017 10.so.0.1.0.17 * 1.2.7 13 10207 12.so.0.1.2.7 * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 - * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 + * 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5 * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 - * 1.0.18 10 10018 12.so.0.1.0.18 + * 1.0.18 10 10018 10.so.0.1.0.18 * 1.2.8 13 10208 12.so.0.1.2.8 * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 * 1.2.9beta4-11 13 10209 12.so.0.9[.0] @@ -119,6 +119,30 @@ * 1.2.10beta1-8 13 10210 12.so.0.10[.0] * 1.2.10rc1-3 13 10210 12.so.0.10[.0] * 1.2.10 13 10210 12.so.0.10[.0] + * 1.2.11beta1-4 13 10211 12.so.0.11[.0] + * 1.0.19rc1-5 10 10019 10.so.0.19[.0] + * 1.2.11rc1-5 13 10211 12.so.0.11[.0] + * 1.0.19 10 10019 10.so.0.19[.0] + * 1.2.11 13 10211 12.so.0.11[.0] + * 1.0.20 10 10020 10.so.0.20[.0] + * 1.2.12 13 10212 12.so.0.12[.0] + * 1.2.13beta1 13 10213 12.so.0.13[.0] + * 1.0.21 10 10021 10.so.0.21[.0] + * 1.2.13 13 10213 12.so.0.13[.0] + * 1.2.14beta1-2 13 10214 12.so.0.14[.0] + * 1.0.22rc1 10 10022 10.so.0.22[.0] + * 1.2.14rc1 13 10214 12.so.0.14[.0] + * 1.0.22 10 10022 10.so.0.22[.0] + * 1.2.14 13 10214 12.so.0.14[.0] + * 1.2.15beta1-6 13 10215 12.so.0.15[.0] + * 1.0.23rc1-5 10 10023 10.so.0.23[.0] + * 1.2.15rc1-5 13 10215 12.so.0.15[.0] + * 1.0.23 10 10023 10.so.0.23[.0] + * 1.2.15 13 10215 12.so.0.15[.0] + * 1.2.16beta1-2 13 10216 12.so.0.16[.0] + * 1.2.16rc1 13 10216 12.so.0.16[.0] + * 1.0.24 10 10024 10.so.0.24[.0] + * 1.2.16 13 10216 12.so.0.16[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -148,8 +172,8 @@ * If you modify libpng you may insert additional notices immediately following * this sentence. * - * libpng versions 1.2.6, August 15, 2004, through 1.2.10, April 23, 2006, are - * Copyright (c) 2004, 2006 Glenn Randers-Pehrson, and are + * libpng versions 1.2.6, August 15, 2004, through 1.2.16, January 31, 2007, are + * Copyright (c) 2004, 2007 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: * @@ -260,13 +284,13 @@ * Y2K compliance in libpng: * ========================= * - * April 23, 2006 + * January 31, 2007 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.2.10 are Y2K compliant. It is my belief that earlier + * upward through 1.2.16 are Y2K compliant. It is my belief that earlier * versions were also Y2K compliant. * * Libpng only has three year fields. One is a 2-byte unsigned integer @@ -322,9 +346,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.2.10" +#define PNG_LIBPNG_VER_STRING "1.2.16" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.2.10 - April 23, 2006 (header)\n" + " libpng version 1.2.16 - January 31, 2007 (header)\n" #define PNG_LIBPNG_VER_SONUM 0 #define PNG_LIBPNG_VER_DLLNUM 13 @@ -332,7 +356,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 2 -#define PNG_LIBPNG_VER_RELEASE 10 +#define PNG_LIBPNG_VER_RELEASE 16 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ @@ -360,7 +384,7 @@ * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10210 /* 1.2.10 */ +#define PNG_LIBPNG_VER 10216 /* 1.2.16 */ #ifndef PNG_VERSION_INFO_ONLY /* include the compression library's header */ @@ -1327,10 +1351,14 @@ struct png_struct_def #endif /* New members added in libpng-1.2.0 */ -#if !defined(PNG_1_0_X) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +# if !defined(PNG_1_0_X) +# if defined(PNG_MMX_CODE_SUPPORTED) png_byte mmx_bitdepth_threshold; png_uint_32 mmx_rowbytes_threshold; +# endif png_uint_32 asm_flags; +# endif #endif /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ @@ -1366,7 +1394,7 @@ struct png_struct_def /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef png_structp version_1_2_10; +typedef png_structp version_1_2_16; typedef png_struct FAR * FAR * png_structpp; @@ -2472,6 +2500,7 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp /* Added to version 1.2.0 */ #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */ #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */ #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04 @@ -2497,6 +2526,7 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp #define PNG_SELECT_READ 1 #define PNG_SELECT_WRITE 2 +#endif /* PNG_MMX_CODE_SUPPORTED */ #if !defined(PNG_1_0_X) /* pngget.c */ @@ -2529,11 +2559,11 @@ extern PNG_EXPORT(void,png_set_mmx_thresholds) png_uint_32 mmx_rowbytes_threshold)); #endif /* PNG_1_0_X */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ #if !defined(PNG_1_0_X) /* png.c, pnggccrd.c, or pngvcrd.c */ extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ /* Strip the prepended error numbers ("#nnn ") from error and warning * messages before passing them to the error or warning handler. */ @@ -2649,7 +2679,7 @@ extern PNG_EXPORT(void,png_save_uint_16) #define PNG_HAVE_IHDR 0x01 #define PNG_HAVE_PLTE 0x02 #define PNG_HAVE_IDAT 0x04 -#define PNG_AFTER_IDAT 0x08 +#define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */ #define PNG_HAVE_IEND 0x10 #define PNG_HAVE_gAMA 0x20 #define PNG_HAVE_cHRM 0x40 @@ -2659,6 +2689,7 @@ extern PNG_EXPORT(void,png_save_uint_16) #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 #define PNG_BACKGROUND_IS_GRAY 0x800 #define PNG_HAVE_PNG_SIGNATURE 0x1000 +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ /* flags for the transformations the PNG library does on the image data */ #define PNG_BGR 0x0001 @@ -3434,9 +3465,34 @@ PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, #endif #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) /* png.c */ /* PRIVATE */ PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr)); #endif +#endif + +#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) +PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#if defined(PNG_pHYs_SUPPORTED) +PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr, +png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ + /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ #endif /* PNG_INTERNAL */ diff --git a/src/libpng/pngconf.h b/src/libpng/pngconf.h index c12d1825c..d71a15329 100644 --- a/src/libpng/pngconf.h +++ b/src/libpng/pngconf.h @@ -1,9 +1,9 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.2.10 - April 23, 2006 + * libpng version 1.2.16 - January 31, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2005 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) */ @@ -721,11 +721,22 @@ #endif /* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 - even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined */ + * even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined. + * + * PNG_NO_ASSEMBLER_CODE disables use of all assembler code and optimized C, + * and removes or includes several functions in the API. + * + * PNG_NO_MMX_CODE disables the use of MMX code without changing the API. + * When MMX code is off, then optimized C replacement functions are used. +*/ #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) # ifndef PNG_ASSEMBLER_CODE_SUPPORTED # define PNG_ASSEMBLER_CODE_SUPPORTED # endif +# if defined(XP_MACOSX) && !defined(PNG_NO_MMX_CODE) + /* work around Intel-Mac compiler bug */ +# define PNG_NO_MMX_CODE +# endif # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) && \ defined(__MMX__) # define PNG_MMX_CODE_SUPPORTED diff --git a/src/libpng/pngerror.c b/src/libpng/pngerror.c index ad6ae0e82..c8c58b91d 100644 --- a/src/libpng/pngerror.c +++ b/src/libpng/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2006 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -157,8 +157,11 @@ png_chunk_error(png_structp png_ptr, png_const_charp error_message) char msg[18+64]; if (png_ptr == NULL) png_error(png_ptr, error_message); - png_format_buffer(png_ptr, msg, error_message); - png_error(png_ptr, msg); + else + { + png_format_buffer(png_ptr, msg, error_message); + png_error(png_ptr, msg); + } } void PNGAPI @@ -167,8 +170,11 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) char msg[18+64]; if (png_ptr == NULL) png_warning(png_ptr, warning_message); - png_format_buffer(png_ptr, msg, warning_message); - png_warning(png_ptr, msg); + else + { + png_format_buffer(png_ptr, msg, warning_message); + png_warning(png_ptr, msg); + } } /* This is the default error handling function. Note that replacements for @@ -206,6 +212,8 @@ png_default_error(png_structp png_ptr, png_const_charp error_message) #endif #ifdef PNG_SETJMP_SUPPORTED + if (png_ptr) + { # ifdef USE_FAR_KEYWORD { jmp_buf jmpbuf; @@ -214,10 +222,9 @@ png_default_error(png_structp png_ptr, png_const_charp error_message) } # else longjmp(png_ptr->jmpbuf, 1); -# endif +# endif + } #else - /* make compiler happy */ ; - if (png_ptr) PNG_ABORT(); #endif #ifdef PNG_NO_CONSOLE_IO diff --git a/src/libpng/pnggccrd.c b/src/libpng/pnggccrd.c index 8dc9c537e..7983f8ea1 100644 --- a/src/libpng/pnggccrd.c +++ b/src/libpng/pnggccrd.c @@ -7,9 +7,9 @@ * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm * for Intel's performance analysis of the MMX vs. non-MMX code. * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation * * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998. @@ -245,7 +245,7 @@ #define PNG_INTERNAL #include "png.h" -#if defined(PNG_USE_PNGGCCRD) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGGCCRD) int PNGAPI png_mmx_support(void); @@ -255,7 +255,7 @@ static const int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1}; #endif -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) /* djgpp, Win32, Cygwin, and OS2 add their own underscores to global variables, * so define them without: */ #if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) || \ @@ -378,7 +378,7 @@ png_squelch_warnings(void) _mask48_1 = _mask48_1; _mask48_0 = _mask48_0; } -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ static int _mmx_supported = 2; @@ -389,7 +389,7 @@ static int _mmx_supported = 2; /* */ /*===========================================================================*/ -#if defined(PNG_HAVE_ASSEMBLER_COMBINE_ROW) +#if defined(PNG_HAVE_MMX_COMBINE_ROW) #define BPP2 2 #define BPP3 3 /* bytes per pixel (a.k.a. pixel_bytes) */ @@ -416,7 +416,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) { png_debug(1, "in png_combine_row (pnggccrd.c)\n"); -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) if (_mmx_supported == 2) { #if !defined(PNG_1_0_X) /* this should have happened in png_init_mmx_flags() already */ @@ -607,7 +607,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_bytep srcptr; png_bytep dstptr; -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) /* && _mmx_supported */ ) @@ -700,7 +700,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = png_pass_start[png_ptr->pass]; @@ -745,7 +745,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_bytep srcptr; png_bytep dstptr; -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) /* && _mmx_supported */ ) @@ -854,7 +854,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass]; @@ -898,7 +898,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_bytep srcptr; png_bytep dstptr; -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) /* && _mmx_supported */ ) @@ -1022,7 +1022,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass]; @@ -1066,7 +1066,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_bytep srcptr; png_bytep dstptr; -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) /* && _mmx_supported */ ) @@ -1197,7 +1197,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass]; @@ -1241,7 +1241,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_bytep srcptr; png_bytep dstptr; -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) /* && _mmx_supported */ ) @@ -1389,7 +1389,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass]; @@ -1480,7 +1480,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) } /* end png_combine_row() */ -#endif /* PNG_HAVE_ASSEMBLER_COMBINE_ROW */ +#endif /* PNG_HAVE_MMX_COMBINE_ROW */ @@ -1492,7 +1492,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) /*===========================================================================*/ #if defined(PNG_READ_INTERLACING_SUPPORTED) -#if defined(PNG_HAVE_ASSEMBLER_READ_INTERLACE) +#if defined(PNG_HAVE_MMX_READ_INTERLACE) /* png_do_read_interlace() is called after any 16-bit to 8-bit conversion * has taken place. [GRR: what other steps come before and/or after?] @@ -1510,7 +1510,7 @@ png_do_read_interlace(png_structp png_ptr) png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n"); -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) if (_mmx_supported == 2) { #if !defined(PNG_1_0_X) /* this should have happened in png_init_mmx_flags() already */ @@ -1723,7 +1723,7 @@ png_do_read_interlace(png_structp png_ptr) /* New code by Nirav Chhatrapati - Intel Corporation */ -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE) /* && _mmx_supported */ ) @@ -2628,7 +2628,7 @@ png_do_read_interlace(png_structp png_ptr) /* GRR 19991007: does it? or should pixel_bytes in each * block be replaced with immediate value (e.g., 1)? */ /* GRR 19991017: replaced with constants in each case */ -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { if (pixel_bytes == 1) { @@ -2753,13 +2753,13 @@ png_do_read_interlace(png_structp png_ptr) } /* end png_do_read_interlace() */ -#endif /* PNG_HAVE_ASSEMBLER_READ_INTERLACE */ +#endif /* PNG_HAVE_MMX_READ_INTERLACE */ #endif /* PNG_READ_INTERLACING_SUPPORTED */ -#if defined(PNG_HAVE_ASSEMBLER_READ_FILTER_ROW) -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_HAVE_MMX_READ_FILTER_ROW) +#if defined(PNG_MMX_CODE_SUPPORTED) // These variables are utilized in the functions below. They are declared // globally here to ensure alignment on 8-byte boundaries. @@ -5066,7 +5066,7 @@ png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row, } // end of png_read_filter_row_mmx_up() -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ @@ -5088,7 +5088,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep char filnm[10]; #endif -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) /* GRR: these are superseded by png_ptr->asm_flags: */ #define UseMMX_sub 1 // GRR: converted 20000730 #define UseMMX_up 1 // GRR: converted 20000729 @@ -5102,7 +5102,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep #endif png_mmx_support(); } -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ #ifdef PNG_DEBUG png_debug(1, "in png_read_filter_row (pnggccrd.c)\n"); @@ -5111,7 +5111,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep case 0: sprintf(filnm, "none"); break; case 1: sprintf(filnm, "sub-%s", -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : #endif @@ -5119,7 +5119,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep "x86"); break; case 2: sprintf(filnm, "up-%s", -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED #if !defined(PNG_1_0_X) (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : #endif @@ -5127,7 +5127,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep "x86"); break; case 3: sprintf(filnm, "avg-%s", -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : #endif @@ -5135,7 +5135,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep "x86"); break; case 4: sprintf(filnm, "Paeth-%s", -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX": #endif @@ -5158,7 +5158,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep break; case PNG_FILTER_VALUE_SUB: -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) && @@ -5170,7 +5170,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_read_filter_row_mmx_sub(row_info, row); } else -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { png_uint_32 i; png_uint_32 istop = row_info->rowbytes; @@ -5187,7 +5187,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep break; case PNG_FILTER_VALUE_UP: -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#if defined(PNG_MMX_CODE_SUPPORTED) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) && @@ -5199,7 +5199,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_read_filter_row_mmx_up(row_info, row, prev_row); } else -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { png_uint_32 i; png_uint_32 istop = row_info->rowbytes; @@ -5215,7 +5215,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep break; case PNG_FILTER_VALUE_AVG: -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) && @@ -5227,7 +5227,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_read_filter_row_mmx_avg(row_info, row, prev_row); } else -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { png_uint_32 i; png_bytep rp = row; @@ -5253,7 +5253,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep break; case PNG_FILTER_VALUE_PAETH: -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) +#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK) #if !defined(PNG_1_0_X) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) && @@ -5265,7 +5265,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_read_filter_row_mmx_paeth(row_info, row, prev_row); } else -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* PNG_MMX_CODE_SUPPORTED */ { png_uint_32 i; png_bytep rp = row; @@ -5326,7 +5326,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep } } -#endif /* PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ +#endif /* PNG_HAVE_MMX_READ_FILTER_ROW */ /*===========================================================================*/ diff --git a/src/libpng/pngget.c b/src/libpng/pngget.c index df7658587..036e9af6e 100644 --- a/src/libpng/pngget.c +++ b/src/libpng/pngget.c @@ -1,9 +1,9 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) */ @@ -829,19 +829,24 @@ png_get_compression_buffer_size(png_structp png_ptr) } #endif -#ifndef PNG_1_0_X #ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifndef PNG_1_0_X /* this function was added to libpng 1.2.0 and should exist by default */ png_uint_32 PNGAPI png_get_asm_flags (png_structp png_ptr) { +#ifdef PNG_MMX_CODE_SUPPORTED return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L); +#else + return (png_ptr? 0L: 0L); +#endif } /* this function was added to libpng 1.2.0 and should exist by default */ png_uint_32 PNGAPI png_get_asm_flagmask (int flag_select) { +#ifdef PNG_MMX_CODE_SUPPORTED png_uint_32 settable_asm_flags = 0; if (flag_select & PNG_SELECT_READ) @@ -862,16 +867,18 @@ png_get_asm_flagmask (int flag_select) #endif /* 0 */ return settable_asm_flags; /* _theoretically_ settable capabilities only */ +#else + return (0L); +#endif /* PNG_MMX_CODE_SUPPORTED */ } -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ /* this function was added to libpng 1.2.0 */ png_uint_32 PNGAPI png_get_mmx_flagmask (int flag_select, int *compilerID) { +#if defined(PNG_MMX_CODE_SUPPORTED) png_uint_32 settable_mmx_flags = 0; if (flag_select & PNG_SELECT_READ) @@ -902,23 +909,34 @@ png_get_mmx_flagmask (int flag_select, int *compilerID) } return settable_mmx_flags; /* _theoretically_ settable capabilities only */ +#else + return (0L); +#endif /* ?PNG_MMX_CODE_SUPPORTED */ } /* this function was added to libpng 1.2.0 */ png_byte PNGAPI png_get_mmx_bitdepth_threshold (png_structp png_ptr) { +#if defined(PNG_MMX_CODE_SUPPORTED) return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0); +#else + return (png_ptr? 0: 0); +#endif /* ?PNG_MMX_CODE_SUPPORTED */ } /* this function was added to libpng 1.2.0 */ png_uint_32 PNGAPI png_get_mmx_rowbytes_threshold (png_structp png_ptr) { +#if defined(PNG_MMX_CODE_SUPPORTED) return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L); +#else + return (png_ptr? 0L: 0L); +#endif /* ?PNG_MMX_CODE_SUPPORTED */ } -#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #endif /* ?PNG_1_0_X */ +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* these functions were added to libpng 1.2.6 */ diff --git a/src/libpng/pngmem.c b/src/libpng/pngmem.c index cfe3e0fde..248060f38 100644 --- a/src/libpng/pngmem.c +++ b/src/libpng/pngmem.c @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2006 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -137,6 +137,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size) png_voidp ret; #endif /* PNG_USER_MEM_SUPPORTED */ + if (png_ptr == NULL || size == 0) + return (NULL); + #ifdef PNG_MAX_MALLOC_64K if (size > (png_uint_32)65536L) { @@ -290,6 +293,8 @@ png_free_default(png_structp png_ptr, png_voidp ptr) { #endif /* PNG_USER_MEM_SUPPORTED */ + if(png_ptr == NULL) return; + if (png_ptr->offset_table != NULL) { int i; @@ -536,8 +541,10 @@ png_voidp PNGAPI png_malloc_warn(png_structp png_ptr, png_uint_32 size) { png_voidp ptr; - png_uint_32 save_flags=png_ptr->flags; + png_uint_32 save_flags; + if(png_ptr == NULL) return (NULL); + save_flags=png_ptr->flags; png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); png_ptr->flags=save_flags; @@ -580,9 +587,11 @@ void PNGAPI png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn) { + if(png_ptr != NULL) { png_ptr->mem_ptr = mem_ptr; png_ptr->malloc_fn = malloc_fn; png_ptr->free_fn = free_fn; + } } /* This function returns a pointer to the mem_ptr associated with the user @@ -592,6 +601,7 @@ png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr png_voidp PNGAPI png_get_mem_ptr(png_structp png_ptr) { + if(png_ptr == NULL) return (NULL); return ((png_voidp)png_ptr->mem_ptr); } #endif /* PNG_USER_MEM_SUPPORTED */ diff --git a/src/libpng/pngpread.c b/src/libpng/pngpread.c index 4a98a2e24..d226c75d3 100644 --- a/src/libpng/pngpread.c +++ b/src/libpng/pngpread.c @@ -1,9 +1,9 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.2.8 - December 3, 2004 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2004 Glenn Randers-Pehrson + * Copyright (c) 1998-2006 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.) */ @@ -28,6 +28,7 @@ void PNGAPI png_process_data(png_structp png_ptr, png_infop info_ptr, png_bytep buffer, png_size_t buffer_size) { + if(png_ptr == NULL) return; png_push_restore_buffer(png_ptr, buffer, buffer_size); while (png_ptr->buffer_size) @@ -42,6 +43,7 @@ png_process_data(png_structp png_ptr, png_infop info_ptr, void /* PRIVATE */ png_process_some_data(png_structp png_ptr, png_infop info_ptr) { + if(png_ptr == NULL) return; switch (png_ptr->process_mode) { case PNG_READ_SIG_MODE: @@ -214,6 +216,10 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; } + if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) + if(png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) { if (png_ptr->push_length + 4 > png_ptr->buffer_size) @@ -281,8 +287,9 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) if (png_ptr->mode & PNG_HAVE_IDAT) { - if (png_ptr->push_length == 0) - return; + if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + if (png_ptr->push_length == 0) + return; if (png_ptr->mode & PNG_AFTER_IDAT) png_error(png_ptr, "Too many IDAT's found"); @@ -556,6 +563,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) { png_bytep ptr; + if(png_ptr == NULL) return; ptr = buffer; if (png_ptr->save_buffer_size) { @@ -1545,6 +1553,7 @@ void PNGAPI png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, png_bytep new_row) { + if(png_ptr == NULL) return; #ifdef PNG_USE_LOCAL_ARRAYS const int FARDATA png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; @@ -1558,6 +1567,7 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn) { + if(png_ptr == NULL) return; png_ptr->info_fn = info_fn; png_ptr->row_fn = row_fn; png_ptr->end_fn = end_fn; @@ -1568,6 +1578,7 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, png_voidp PNGAPI png_get_progressive_ptr(png_structp png_ptr) { + if(png_ptr == NULL) return (NULL); return png_ptr->io_ptr; } #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ diff --git a/src/libpng/pngread.c b/src/libpng/pngread.c index e99639f0d..56dac8a80 100644 --- a/src/libpng/pngread.c +++ b/src/libpng/pngread.c @@ -1,9 +1,9 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) * @@ -56,7 +56,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, return (NULL); #if !defined(PNG_1_0_X) -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ #endif #endif /* PNG_1_0_X */ @@ -188,6 +188,7 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size) { /* We only come here via pre-1.0.12-compiled applications */ + if(png_ptr == NULL) return; #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) if(png_sizeof(png_struct) > png_struct_size || png_sizeof(png_info) > png_info_size) @@ -239,6 +240,8 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, png_structp png_ptr=*ptr_ptr; + if(png_ptr == NULL) return; + do { if(user_png_ver[i] != png_libpng_ver[i]) @@ -317,6 +320,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, void PNGAPI png_read_info(png_structp png_ptr, png_infop info_ptr) { + if(png_ptr == NULL) return; png_debug(1, "in png_read_info\n"); /* If we haven't checked all of the PNG signature bytes, do so now. */ if (png_ptr->sig_bytes < 8) @@ -413,6 +417,10 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) /* This should be a binary subdivision search or a hash for * matching the chunk name rather than a linear search. */ + if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) + if(png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) png_handle_IHDR(png_ptr, info_ptr, length); else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) @@ -529,6 +537,7 @@ void PNGAPI png_read_update_info(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_read_update_info\n"); + if(png_ptr == NULL) return; if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) png_read_start_row(png_ptr); else @@ -547,6 +556,7 @@ void PNGAPI png_start_read_image(png_structp png_ptr) { png_debug(1, "in png_start_read_image\n"); + if(png_ptr == NULL) return; if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) png_read_start_row(png_ptr); } @@ -562,6 +572,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; #endif int ret; + if(png_ptr == NULL) return; png_debug2(1, "in png_read_row (row %lu, pass %d)\n", png_ptr->row_number, png_ptr->pass); if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) @@ -820,6 +831,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row, png_bytepp dp; png_debug(1, "in png_read_rows\n"); + if(png_ptr == NULL) return; rp = row; dp = display_row; if (rp != NULL && dp != NULL) @@ -868,6 +880,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) png_bytepp rp; png_debug(1, "in png_read_image\n"); + if(png_ptr == NULL) return; #ifdef PNG_READ_INTERLACING_SUPPORTED pass = png_set_interlace_handling(png_ptr); @@ -906,6 +919,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) png_uint_32 length; png_debug(1, "in png_read_end\n"); + if(png_ptr == NULL) return; png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ do @@ -985,11 +999,9 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) { if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) { - if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) png_error(png_ptr, "Too many IDAT's found"); } - else - png_ptr->mode |= PNG_AFTER_IDAT; png_handle_unknown(png_ptr, info_ptr, length); if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) png_ptr->mode |= PNG_HAVE_PLTE; @@ -1000,7 +1012,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) /* Zero length IDATs are legal after the last IDAT has been * read, but not after other chunks have been read. */ - if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) png_error(png_ptr, "Too many IDAT's found"); png_crc_finish(png_ptr, length); } @@ -1298,6 +1310,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr void PNGAPI png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) { + if(png_ptr == NULL) return; png_ptr->read_row_fn = read_row_fn; } @@ -1311,6 +1324,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, { int row; + if(png_ptr == NULL) return; #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) /* invert the alpha channel from opacity to transparency */ diff --git a/src/libpng/pngrio.c b/src/libpng/pngrio.c index ce05cada7..7d2522f1f 100644 --- a/src/libpng/pngrio.c +++ b/src/libpng/pngrio.c @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2006 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -46,6 +46,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { png_size_t check; + if(png_ptr == NULL) return; /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ @@ -76,6 +77,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_byte *n_data; png_FILE_p io_ptr; + if(png_ptr == NULL) return; /* Check if data really is near. If so, use usual code. */ n_data = (png_byte *)CVT_PTR_NOCHECK(data); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); @@ -136,6 +138,7 @@ void PNGAPI png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn) { + if(png_ptr == NULL) return; png_ptr->io_ptr = io_ptr; #if !defined(PNG_NO_STDIO) diff --git a/src/libpng/pngrtran.c b/src/libpng/pngrtran.c index 8b580807c..2fa96f312 100644 --- a/src/libpng/pngrtran.c +++ b/src/libpng/pngrtran.c @@ -1,9 +1,9 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) * @@ -24,6 +24,7 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) { png_debug(1, "in png_set_crc_action\n"); /* Tell libpng how we react to CRC errors in critical chunks */ + if(png_ptr == NULL) return; switch (crit_action) { case PNG_CRC_NO_CHANGE: /* leave setting as is */ @@ -80,6 +81,7 @@ png_set_background(png_structp png_ptr, int need_expand, double background_gamma) { png_debug(1, "in png_set_background\n"); + if(png_ptr == NULL) return; if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) { png_warning(png_ptr, "Application must supply a known background gamma"); @@ -92,17 +94,6 @@ png_set_background(png_structp png_ptr, png_ptr->background_gamma = (float)background_gamma; png_ptr->background_gamma_type = (png_byte)(background_gamma_code); png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); - - /* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA - * (in which case need_expand is superfluous anyway), the background color - * might actually be gray yet not be flagged as such. This is not a problem - * for the current code, which uses PNG_BACKGROUND_IS_GRAY only to - * decide when to do the png_do_gray_to_rgb() transformation. - */ - if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) || - (!need_expand && background_color->red == background_color->green && - background_color->red == background_color->blue)) - png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; } #endif @@ -112,6 +103,7 @@ void PNGAPI png_set_strip_16(png_structp png_ptr) { png_debug(1, "in png_set_strip_16\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_16_TO_8; } #endif @@ -121,6 +113,7 @@ void PNGAPI png_set_strip_alpha(png_structp png_ptr) { png_debug(1, "in png_set_strip_alpha\n"); + if(png_ptr == NULL) return; png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; } #endif @@ -150,6 +143,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette, int full_dither) { png_debug(1, "in png_set_dither\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_DITHER; if (!full_dither) @@ -533,6 +527,7 @@ void PNGAPI png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) { png_debug(1, "in png_set_gamma\n"); + if(png_ptr == NULL) return; if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) @@ -551,6 +546,7 @@ void PNGAPI png_set_expand(png_structp png_ptr) { png_debug(1, "in png_set_expand\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); } @@ -576,6 +572,7 @@ void PNGAPI png_set_palette_to_rgb(png_structp png_ptr) { png_debug(1, "in png_set_palette_to_rgb\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); } @@ -585,6 +582,7 @@ void PNGAPI png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) { png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_EXPAND_tRNS; } #endif @@ -596,6 +594,7 @@ void PNGAPI png_set_gray_1_2_4_to_8(png_structp png_ptr) { png_debug(1, "in png_set_gray_1_2_4_to_8\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); } #endif @@ -631,6 +630,7 @@ png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, { int red_fixed = (int)((float)red*100000.0 + 0.5); int green_fixed = (int)((float)green*100000.0 + 0.5); + if(png_ptr == NULL) return; png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); } #endif @@ -640,6 +640,7 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, png_fixed_point red, png_fixed_point green) { png_debug(1, "in png_set_rgb_to_gray\n"); + if(png_ptr == NULL) return; switch(error_action) { case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; @@ -690,6 +691,7 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr read_user_transform_fn) { png_debug(1, "in png_set_read_user_transform_fn\n"); + if(png_ptr == NULL) return; #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->read_user_transform_fn = read_user_transform_fn; @@ -719,6 +721,32 @@ png_init_read_transformations(png_structp png_ptr) #endif #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + /* Detect gray background and attempt to enable optimization + * for gray --> RGB case */ + /* Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or + * RGB_ALPHA (in which case need_expand is superfluous anyway), the + * background color might actually be gray yet not be flagged as such. + * This is not a problem for the current code, which uses + * PNG_BACKGROUND_IS_GRAY only to decide when to do the + * png_do_gray_to_rgb() transformation. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + !(color_type & PNG_COLOR_MASK_COLOR)) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + } else if ((png_ptr->transformations & PNG_BACKGROUND) && + !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_GRAY_TO_RGB) && + png_ptr->background.red == png_ptr->background.green && + png_ptr->background.red == png_ptr->background.blue) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + png_ptr->background.gray = png_ptr->background.red; + } +#endif + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && (png_ptr->transformations & PNG_EXPAND)) { @@ -3938,7 +3966,7 @@ png_do_dither(png_row_infop row_info, png_bytep row, #ifdef PNG_FLOATING_POINT_SUPPORTED #if defined(PNG_READ_GAMMA_SUPPORTED) static int png_gamma_shift[] = - {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0}; + {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00}; /* We build the 8- or 16-bit gamma tables here. Note that for 16-bit * tables, we don't make a full table if we are reducing to 8-bit in diff --git a/src/libpng/pngrutil.c b/src/libpng/pngrutil.c index a436d435e..6157b3de4 100644 --- a/src/libpng/pngrutil.c +++ b/src/libpng/pngrutil.c @@ -1,9 +1,9 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) * @@ -16,27 +16,29 @@ #if defined(PNG_READ_SUPPORTED) -#if defined(_WIN32_WCE) +#ifdef PNG_FLOATING_POINT_SUPPORTED +# if defined(_WIN32_WCE) /* strtod() function is not supported on WindowsCE */ -# ifdef PNG_FLOATING_POINT_SUPPORTED -__inline double strtod(const char *nptr, char **endptr) +__inline double png_strtod(png_structp png_ptr, const char *nptr, char **endptr) { double result = 0; int len; wchar_t *str, *end; len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); - str = (wchar_t *)malloc(len * sizeof(wchar_t)); + str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t)); if ( NULL != str ) { MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); result = wcstod(str, &end); len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL); *endptr = (char *)nptr + (png_strlen(nptr) - len + 1); - free(str); + png_free(str); } return result; } +# else +# define png_strtod(p,a,b) strtod(a,b) # endif #endif @@ -90,6 +92,7 @@ png_get_uint_16(png_bytep buf) void /* PRIVATE */ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) { + if(png_ptr == NULL) return; png_read_data(png_ptr, buf, length); png_calculate_crc(png_ptr, buf, length); } @@ -276,7 +279,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, if (ret != Z_STREAM_END) { #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) - char umsg[50]; + char umsg[52]; if (ret == Z_BUF_ERROR) sprintf(umsg,"Buffer error in compressed datastream in %s chunk", @@ -829,7 +832,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #endif #if defined(PNG_READ_sRGB_SUPPORTED) - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) { if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) || @@ -840,7 +843,6 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) || PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000)) { - png_warning(png_ptr, "Ignoring incorrect cHRM value when sRGB is also present"); #ifndef PNG_NO_CONSOLE_IO @@ -1731,7 +1733,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) ep = buffer + 1; /* skip unit byte */ #ifdef PNG_FLOATING_POINT_SUPPORTED - width = strtod(ep, &vp); + width = png_strtod(png_ptr, ep, &vp); if (*vp) { png_warning(png_ptr, "malformed width string in sCAL chunk"); @@ -1754,7 +1756,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) ep++; #ifdef PNG_FLOATING_POINT_SUPPORTED - height = strtod(ep, &vp); + height = png_strtod(png_ptr, ep, &vp); if (*vp) { png_warning(png_ptr, "malformed height string in sCAL chunk"); @@ -2247,7 +2249,7 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name) a zero indicates the pixel is to be skipped. This is in addition to any alpha or transparency value associated with the pixel. If you want all pixels to be combined, pass 0xff (255) in mask. */ -#ifndef PNG_HAVE_ASSEMBLER_COMBINE_ROW +#ifndef PNG_HAVE_MMX_COMBINE_ROW void /* PRIVATE */ png_combine_row(png_structp png_ptr, png_bytep row, int mask) { @@ -2448,10 +2450,10 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) } } } -#endif /* !PNG_HAVE_ASSEMBLER_COMBINE_ROW */ +#endif /* !PNG_HAVE_MMX_COMBINE_ROW */ #ifdef PNG_READ_INTERLACING_SUPPORTED -#ifndef PNG_HAVE_ASSEMBLER_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */ +#ifndef PNG_HAVE_MMX_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */ /* OLD pre-1.0.9 interface: void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, png_uint_32 transformations) @@ -2677,10 +2679,10 @@ png_do_read_interlace(png_structp png_ptr) return; #endif } -#endif /* !PNG_HAVE_ASSEMBLER_READ_INTERLACE */ +#endif /* !PNG_HAVE_MMX_READ_INTERLACE */ #endif /* PNG_READ_INTERLACING_SUPPORTED */ -#ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +#ifndef PNG_HAVE_MMX_READ_FILTER_ROW void /* PRIVATE */ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter) @@ -2803,7 +2805,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, break; } } -#endif /* !PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ +#endif /* !PNG_HAVE_MMX_READ_FILTER_ROW */ void /* PRIVATE */ png_read_finish_row(png_structp png_ptr) @@ -3105,7 +3107,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) png_error(png_ptr, "This image requires a row greater than 64KB"); #endif - if ((png_uint_32)png_ptr->rowbytes > PNG_SIZE_MAX - 1) + if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1)) png_error(png_ptr, "Row has too many bytes to allocate in memory."); png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( png_ptr->rowbytes + 1)); diff --git a/src/libpng/pngset.c b/src/libpng/pngset.c index 9e499c9bc..24fa24dea 100644 --- a/src/libpng/pngset.c +++ b/src/libpng/pngset.c @@ -1,9 +1,9 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) * @@ -976,10 +976,10 @@ png_set_sPLT(png_structp png_ptr, /* TODO: use png_malloc_warn */ png_strcpy(to->name, from->name); to->entries = (png_sPLT_entryp)png_malloc(png_ptr, - from->nentries * png_sizeof(png_sPLT_t)); + from->nentries * png_sizeof(png_sPLT_entry)); /* TODO: use png_malloc_warn */ png_memcpy(to->entries, from->entries, - from->nentries * png_sizeof(png_sPLT_t)); + from->nentries * png_sizeof(png_sPLT_entry)); to->nentries = from->nentries; to->depth = from->depth; } @@ -1191,11 +1191,13 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) void PNGAPI png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) { +#ifdef PNG_MMX_CODE_SUPPORTED png_uint_32 settable_asm_flags; png_uint_32 settable_mmx_flags; - +#endif if (png_ptr == NULL) return; +#ifdef PNG_MMX_CODE_SUPPORTED settable_mmx_flags = #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW @@ -1224,15 +1226,14 @@ png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) } /* we're replacing the settable bits with those passed in by the user, - * so first zero them out of the master copy, then logical-OR in the + * so first zero them out of the master copy, then bitwise-OR in the * allowed subset that was requested */ png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */ png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */ +#endif /* ?PNG_MMX_CODE_SUPPORTED */ } -#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED /* this function was added to libpng 1.2.0 */ void PNGAPI png_set_mmx_thresholds (png_structp png_ptr, @@ -1241,8 +1242,10 @@ png_set_mmx_thresholds (png_structp png_ptr, { if (png_ptr == NULL) return; +#ifdef PNG_MMX_CODE_SUPPORTED png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold; png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold; +#endif /* ?PNG_MMX_CODE_SUPPORTED */ } #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ @@ -1256,6 +1259,7 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, * rejected by png_set_IHDR(). To accept any PNG datastream * regardless of dimensions, set both limits to 0x7ffffffL. */ + if(png_ptr == NULL) return; png_ptr->user_width_max = user_width_max; png_ptr->user_height_max = user_height_max; } diff --git a/src/libpng/pngtest.c b/src/libpng/pngtest.c index 793162846..3d09dee3f 100644 --- a/src/libpng/pngtest.c +++ b/src/libpng/pngtest.c @@ -81,18 +81,6 @@ static float t_start, t_stop, t_decode, t_encode, t_misc; #include <time.h> #endif -/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ -#ifndef png_jmpbuf -# define png_jmpbuf(png_ptr) png_ptr->jmpbuf -#endif - -#ifdef PNGTEST_TIMING -static float t_start, t_stop, t_decode, t_encode, t_misc; -#if !defined(PNG_tIME_SUPPORTED) -#include <time.h> -#endif -#endif - #if defined(PNG_TIME_RFC1123_SUPPORTED) static int tIME_chunk_present=0; static char tIME_string[30] = "no tIME chunk present in file"; @@ -115,6 +103,16 @@ static int status_pass=1; static int status_dots_requested=0; static int status_dots=1; +/* In case a system header (e.g., on AIX) defined jmpbuf */ +#ifdef jmpbuf +# undef jmpbuf +#endif + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) png_ptr->jmpbuf +#endif + void #ifdef PNG_1_0_X PNGAPI @@ -536,7 +534,8 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size) /* Make sure the caller isn't assuming zeroed memory. */ png_memset(pinfo->pointer, 0xdd, pinfo->size); if(verbose) - printf("png_malloc %lu bytes at %x\n",size,pinfo->pointer); + printf("png_malloc %lu bytes at %x\n",(unsigned long)size, + pinfo->pointer); return (png_voidp)(pinfo->pointer); } } @@ -1188,7 +1187,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) iwidth = png_get_image_width(write_ptr, write_info_ptr); iheight = png_get_image_height(write_ptr, write_info_ptr); fprintf(STDERR, "Image width = %lu, height = %lu\n", - iwidth, iheight); + (unsigned long)iwidth, (unsigned long)iheight); } #endif @@ -1312,7 +1311,8 @@ main(int argc, char *argv[]) fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); fprintf(STDERR,"%s",png_get_copyright(NULL)); /* Show the version of libpng used in building the library */ - fprintf(STDERR," library (%lu):%s", png_access_version_number(), + fprintf(STDERR," library (%lu):%s", + (unsigned long)png_access_version_number(), png_get_header_version(NULL)); /* Show the version of libpng used in building the application */ fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, @@ -1400,7 +1400,8 @@ main(int argc, char *argv[]) if (kerror == 0) { #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); #else fprintf(STDERR, " PASS\n"); #endif @@ -1408,7 +1409,7 @@ main(int argc, char *argv[]) for (k=0; k<256; k++) if(filters_used[k]) fprintf(STDERR, " Filter %d was used %lu times\n", - k,filters_used[k]); + k,(unsigned long)filters_used[k]); #endif #if defined(PNG_TIME_RFC1123_SUPPORTED) if(tIME_chunk_present != 0) @@ -1433,7 +1434,7 @@ main(int argc, char *argv[]) current_allocation); while (pinfo != NULL) { - fprintf(STDERR, " %lu bytes at %x\n", pinfo->size, + fprintf(STDERR, " %lu bytes at %x\n", (unsigned long)pinfo->size, (unsigned int) pinfo->pointer); pinfo = pinfo->next; } @@ -1473,7 +1474,8 @@ main(int argc, char *argv[]) int k; #endif #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); #else fprintf(STDERR, " PASS\n"); #endif @@ -1481,7 +1483,7 @@ main(int argc, char *argv[]) for (k=0; k<256; k++) if(filters_used[k]) fprintf(STDERR, " Filter %d was used %lu times\n", - k,filters_used[k]); + k,(unsigned long)filters_used[k]); #endif #if defined(PNG_TIME_RFC1123_SUPPORTED) if(tIME_chunk_present != 0) @@ -1509,7 +1511,7 @@ main(int argc, char *argv[]) while (pinfo != NULL) { fprintf(STDERR," %lu bytes at %x\n", - pinfo->size, (unsigned int)pinfo->pointer); + (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); pinfo = pinfo->next; } } @@ -1549,4 +1551,4 @@ main(int argc, char *argv[]) } /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_2_10 your_png_h_is_not_version_1_2_10; +typedef version_1_2_16 your_png_h_is_not_version_1_2_16; diff --git a/src/libpng/pngtrans.c b/src/libpng/pngtrans.c index 9c4d67cd0..25f42c871 100644 --- a/src/libpng/pngtrans.c +++ b/src/libpng/pngtrans.c @@ -1,7 +1,7 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2006 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -18,6 +18,7 @@ void PNGAPI png_set_bgr(png_structp png_ptr) { png_debug(1, "in png_set_bgr\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_BGR; } #endif @@ -28,6 +29,7 @@ void PNGAPI png_set_swap(png_structp png_ptr) { png_debug(1, "in png_set_swap\n"); + if(png_ptr == NULL) return; if (png_ptr->bit_depth == 16) png_ptr->transformations |= PNG_SWAP_BYTES; } @@ -39,6 +41,7 @@ void PNGAPI png_set_packing(png_structp png_ptr) { png_debug(1, "in png_set_packing\n"); + if(png_ptr == NULL) return; if (png_ptr->bit_depth < 8) { png_ptr->transformations |= PNG_PACK; @@ -53,6 +56,7 @@ void PNGAPI png_set_packswap(png_structp png_ptr) { png_debug(1, "in png_set_packswap\n"); + if(png_ptr == NULL) return; if (png_ptr->bit_depth < 8) png_ptr->transformations |= PNG_PACKSWAP; } @@ -63,6 +67,7 @@ void PNGAPI png_set_shift(png_structp png_ptr, png_color_8p true_bits) { png_debug(1, "in png_set_shift\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_SHIFT; png_ptr->shift = *true_bits; } @@ -74,7 +79,7 @@ int PNGAPI png_set_interlace_handling(png_structp png_ptr) { png_debug(1, "in png_set_interlace handling\n"); - if (png_ptr->interlaced) + if (png_ptr && png_ptr->interlaced) { png_ptr->transformations |= PNG_INTERLACE; return (7); @@ -94,6 +99,7 @@ void PNGAPI png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) { png_debug(1, "in png_set_filler\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_FILLER; png_ptr->filler = (png_byte)filler; if (filler_loc == PNG_FILLER_AFTER) @@ -126,6 +132,7 @@ void PNGAPI png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) { png_debug(1, "in png_set_add_alpha\n"); + if(png_ptr == NULL) return; png_set_filler(png_ptr, filler, filler_loc); png_ptr->transformations |= PNG_ADD_ALPHA; } @@ -139,6 +146,7 @@ void PNGAPI png_set_swap_alpha(png_structp png_ptr) { png_debug(1, "in png_set_swap_alpha\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_SWAP_ALPHA; } #endif @@ -149,6 +157,7 @@ void PNGAPI png_set_invert_alpha(png_structp png_ptr) { png_debug(1, "in png_set_invert_alpha\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_INVERT_ALPHA; } #endif @@ -158,6 +167,7 @@ void PNGAPI png_set_invert_mono(png_structp png_ptr) { png_debug(1, "in png_set_invert_mono\n"); + if(png_ptr == NULL) return; png_ptr->transformations |= PNG_INVERT_MONO; } @@ -621,6 +631,7 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels) { png_debug(1, "in png_set_user_transform_info\n"); + if(png_ptr == NULL) return; #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) png_ptr->user_transform_ptr = user_transform_ptr; png_ptr->user_transform_depth = (png_byte)user_transform_depth; @@ -641,12 +652,10 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp png_voidp PNGAPI png_get_user_transform_ptr(png_structp png_ptr) { + if (png_ptr == NULL) return (NULL); #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) return ((png_voidp)png_ptr->user_transform_ptr); -#else - if(png_ptr) - return (NULL); - return (NULL); #endif + return (NULL); } #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/src/libpng/pngwio.c b/src/libpng/pngwio.c index a9c1dc53d..4d9d57e36 100644 --- a/src/libpng/pngwio.c +++ b/src/libpng/pngwio.c @@ -1,7 +1,7 @@ /* pngwio.c - functions for data output * - * Last changed in libpng 1.2.3 - May 21, 2002 + * Last changed in libpng 1.2.13 November 13, 2006 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2002 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -45,6 +45,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { png_uint_32 check; + if(png_ptr == NULL) return; #if defined(_WIN32_WCE) if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) check = 0; @@ -70,6 +71,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ png_FILE_p io_ptr; + if(png_ptr == NULL) return; /* Check if data really is near. If so, use usual code. */ near_data = (png_byte *)CVT_PTR_NOCHECK(data); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); @@ -131,6 +133,9 @@ png_default_flush(png_structp png_ptr) { #if !defined(_WIN32_WCE) png_FILE_p io_ptr; +#endif + if(png_ptr == NULL) return; +#if !defined(_WIN32_WCE) io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); if (io_ptr != NULL) fflush(io_ptr); @@ -165,6 +170,7 @@ void PNGAPI png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) { + if(png_ptr == NULL) return; png_ptr->io_ptr = io_ptr; #if !defined(PNG_NO_STDIO) diff --git a/src/libpng/pngwrite.c b/src/libpng/pngwrite.c index 95984f6e5..df7ade334 100644 --- a/src/libpng/pngwrite.c +++ b/src/libpng/pngwrite.c @@ -1,9 +1,9 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) */ @@ -461,8 +461,10 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #if !defined(PNG_1_0_X) #ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ #endif +#endif #endif /* PNG_1_0_X */ /* added at libpng-1.2.6 */ @@ -576,6 +578,7 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size) { /* We only come here via pre-1.0.12-compiled applications */ + if(png_ptr == NULL) return; #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) if(png_sizeof(png_struct) > png_struct_size || png_sizeof(png_info) > png_info_size) @@ -670,8 +673,10 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, #if !defined(PNG_1_0_X) #ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ #endif +#endif #endif /* PNG_1_0_X */ #ifdef PNG_SETJMP_SUPPORTED diff --git a/src/libpng/pngwutil.c b/src/libpng/pngwutil.c index 82bf58a1a..e108c6106 100644 --- a/src/libpng/pngwutil.c +++ b/src/libpng/pngwutil.c @@ -1,9 +1,9 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.2.9 April 14, 2006 + * Last changed in libpng 1.2.15 January 5, 2007 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2007 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.) */ @@ -62,6 +62,7 @@ void PNGAPI png_write_chunk(png_structp png_ptr, png_bytep chunk_name, png_bytep data, png_size_t length) { + if(png_ptr == NULL) return; png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); png_write_chunk_data(png_ptr, data, length); png_write_chunk_end(png_ptr); @@ -77,6 +78,7 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, { png_byte buf[4]; png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length); + if(png_ptr == NULL) return; /* write the length */ png_save_uint_32(buf, length); @@ -98,6 +100,7 @@ void PNGAPI png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) { /* write the data, and run the CRC over it */ + if(png_ptr == NULL) return; if (data != NULL && length > 0) { png_calculate_crc(png_ptr, data, length); @@ -111,6 +114,8 @@ png_write_chunk_end(png_structp png_ptr) { png_byte buf[4]; + if(png_ptr == NULL) return; + /* write the crc */ png_save_uint_32(buf, png_ptr->crc); @@ -728,6 +733,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, png_size_t name_len; png_charp new_name; compression_state comp; + int embedded_profile_len = 0; png_debug(1, "in png_write_iCCP\n"); @@ -750,6 +756,27 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, if (profile == NULL) profile_len = 0; + if (profile_len > 3) + embedded_profile_len = + ((*( (png_bytep)profile ))<<24) | + ((*( (png_bytep)profile+1))<<16) | + ((*( (png_bytep)profile+2))<< 8) | + ((*( (png_bytep)profile+3)) ); + + if (profile_len < embedded_profile_len) + { + png_warning(png_ptr, + "Embedded profile length too large in iCCP chunk"); + return; + } + + if (profile_len > embedded_profile_len) + { + png_warning(png_ptr, + "Truncating profile to actual length in iCCP chunk"); + profile_len = embedded_profile_len; + } + if (profile_len) profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); @@ -1567,39 +1594,41 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, /* write the sCAL chunk */ #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) void /* PRIVATE */ -png_write_sCAL(png_structp png_ptr, int unit, double width,double height) +png_write_sCAL(png_structp png_ptr, int unit, double width, double height) { #ifdef PNG_USE_LOCAL_ARRAYS PNG_sCAL; #endif + char buf[64]; png_size_t total_len; - char wbuf[32], hbuf[32]; - png_byte bunit = (png_byte)unit; png_debug(1, "in png_write_sCAL\n"); + buf[0] = (char)unit; #if defined(_WIN32_WCE) /* sprintf() function is not supported on WindowsCE */ { wchar_t wc_buf[32]; + size_t wc_len; swprintf(wc_buf, TEXT("%12.12e"), width); - WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, wbuf, 32, NULL, NULL); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL); + total_len = wc_len + 2; swprintf(wc_buf, TEXT("%12.12e"), height); - WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, hbuf, 32, NULL, NULL); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len, + NULL, NULL); + total_len += wc_len; } #else - sprintf(wbuf, "%12.12e", width); - sprintf(hbuf, "%12.12e", height); + sprintf(buf + 1, "%12.12e", width); + total_len = 1 + png_strlen(buf + 1) + 1; + sprintf(buf + total_len, "%12.12e", height); + total_len += png_strlen(buf + total_len); #endif - total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); - - png_debug1(3, "sCAL total length = %d\n", (int)total_len); - png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len); - png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1); - png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); - png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); - png_write_chunk_end(png_ptr); + png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); + png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len); } #else #ifdef PNG_FIXED_POINT_SUPPORTED @@ -1610,23 +1639,26 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, #ifdef PNG_USE_LOCAL_ARRAYS PNG_sCAL; #endif - png_size_t total_len; - char wbuf[32], hbuf[32]; - png_byte bunit = unit; + png_byte buf[64]; + png_size_t wlen, hlen, total_len; png_debug(1, "in png_write_sCAL_s\n"); - png_strcpy(wbuf,(const char *)width); - png_strcpy(hbuf,(const char *)height); - total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); + wlen = png_strlen(width); + hlen = png_strlen(height); + total_len = wlen + hlen + 2; + if (total_len > 64) + { + png_warning(png_ptr, "Can't write sCAL (buffer too small)"); + return; + } - png_debug1(3, "sCAL total length = %d\n", total_len); - png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len); - png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1); - png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); - png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); + buf[0] = (png_byte)unit; + png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */ + png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */ - png_write_chunk_end(png_ptr); + png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); + png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len); } #endif #endif |