X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4946a942d77cf51e00aa56404756e124d7c11411..fbb7dfffb098c0c1a71f15674fba0d3af9609028:/src/png/png.c diff --git a/src/png/png.c b/src/png/png.c index 380c19c8cb..a0332b9abc 100644 --- a/src/png/png.c +++ b/src/png/png.c @@ -1,11 +1,11 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.2.4 - July 8, 2002 - * Copyright (c) 1998-2002 Glenn Randers-Pehrson + * libpng version 1.2.7 - September 12, 2004 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2004 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.) - * */ #define PNG_INTERNAL @@ -13,14 +13,14 @@ #include "png.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_2_4 Your_png_h_is_not_version_1_2_4; +typedef version_1_2_7 Your_png_h_is_not_version_1_2_7; /* Version information for C files. This had better match the version * string defined in png.h. */ #ifdef PNG_USE_GLOBAL_ARRAYS /* png_libpng_ver was changed to a function in version 1.0.5c */ -const char png_libpng_ver[18] = "1.2.4"; +const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -136,22 +136,29 @@ png_check_sig(png_bytep sig, int num) /* Function to allocate memory for zlib and clear it to 0. */ #ifdef PNG_1_0_X -void PNGAPI +voidpf PNGAPI #else voidpf /* private */ #endif png_zalloc(voidpf png_ptr, uInt items, uInt size) { - png_uint_32 num_bytes = (png_uint_32)items * size; png_voidp ptr; - png_structp p=png_ptr; + png_structp p=(png_struct*)png_ptr; png_uint_32 save_flags=p->flags; + png_uint_32 num_bytes; + + if (items > PNG_UINT_32_MAX/size) + { + png_warning (png_ptr, "Potential overflow in png_zalloc()"); + return (NULL); + } + num_bytes = (png_uint_32)items * size; p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); p->flags=save_flags; -#ifndef PNG_NO_ZALLOC_ZERO +#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO) if (ptr == NULL) return ((voidpf)ptr); @@ -217,7 +224,7 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) /* Allocate the memory for an info_struct for the application. We don't * really need the png_ptr, but it could potentially be useful in the - * future. This should be used in favour of malloc(sizeof(png_info)) + * future. This should be used in favour of malloc(png_sizeof(png_info)) * and png_info_init() so that applications that want to use a shared * libpng don't have to be recompiled if png_info changes size. */ @@ -235,7 +242,7 @@ png_create_info_struct(png_structp png_ptr) info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); #endif if (info_ptr != NULL) - png_info_init_3(&info_ptr, sizeof(png_info)); + png_info_init_3(&info_ptr, png_sizeof(png_info)); return (info_ptr); } @@ -287,7 +294,7 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) png_debug(1, "in png_info_init_3\n"); - if(sizeof(png_info) > png_info_struct_size) + if(png_sizeof(png_info) > png_info_struct_size) { png_destroy_struct(info_ptr); info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); @@ -295,7 +302,7 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) } /* set everything to 0 */ - png_memset(info_ptr, 0, sizeof (png_info)); + png_memset(info_ptr, 0, png_sizeof (png_info)); } #ifdef PNG_FREE_ME_SUPPORTED @@ -581,7 +588,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) } #endif - png_info_init_3(&info_ptr, sizeof(png_info)); + png_info_init_3(&info_ptr, png_sizeof(png_info)); } /* This function returns a pointer to the io_ptr associated with the user @@ -623,7 +630,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) if (png_ptr->time_buffer == NULL) { png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* - sizeof(char))); + png_sizeof(char))); } #if defined(_WIN32_WCE) @@ -645,7 +652,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) ptime->year, ptime->hour % 24, ptime->minute % 60, ptime->second % 61); png_memcpy(png_ptr->time_buffer, near_time_buf, - 29*sizeof(char)); + 29*png_sizeof(char)); } #else sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", @@ -670,45 +677,47 @@ png_sig_bytes(void) png_charp PNGAPI png_get_copyright(png_structp png_ptr) { - if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ - return ((png_charp) "\n libpng version 1.2.4 - July 8, 2002\n\ - Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\ + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) "\n libpng version 1.2.7 - September 12, 2004\n\ + Copyright (c) 1998-2004 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) ""); } /* The following return the library version as a short string in the - * format 1.0.0 through 99.99.99zz. To get the version of *.h files used - * with your application, print out PNG_LIBPNG_VER_STRING, which is defined - * in png.h. + * format 1.0.0 through 99.99.99zz. To get the version of *.h files + * used with your application, print out PNG_LIBPNG_VER_STRING, which + * is defined in png.h. + * Note: now there is no difference between png_get_libpng_ver() and + * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, + * it is guaranteed that png.c uses the correct version of png.h. */ - png_charp PNGAPI png_get_libpng_ver(png_structp png_ptr) { /* Version of *.c files used when building libpng */ - if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return((png_charp) "1.2.4"); - return((png_charp) "1.2.4"); + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); + return ((png_charp) ""); } png_charp PNGAPI png_get_header_ver(png_structp png_ptr) { /* Version of *.h files used when building libpng */ - if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return((png_charp) PNG_LIBPNG_VER_STRING); - return((png_charp) PNG_LIBPNG_VER_STRING); + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); + return ((png_charp) ""); } png_charp PNGAPI png_get_header_version(png_structp png_ptr) { /* Returns longer string containing both version and date */ - if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return((png_charp) PNG_HEADER_VERSION_STRING); - return((png_charp) PNG_HEADER_VERSION_STRING); + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_HEADER_VERSION_STRING); + return ((png_charp) ""); } #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED @@ -740,7 +749,7 @@ png_uint_32 PNGAPI png_access_version_number(void) { /* Version of *.c files used when building libpng */ - return((png_uint_32) 10204L); + return((png_uint_32) PNG_LIBPNG_VER); } @@ -758,7 +767,7 @@ png_init_mmx_flags (png_structp png_ptr) png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED; - if (png_mmx_support()) { + if (png_mmx_support() > 0) { png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU # ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW @@ -803,3 +812,15 @@ png_mmx_support(void) } #endif #endif /* PNG_1_0_X */ + +#ifdef PNG_SIZE_T +/* Added at libpng version 1.2.6 */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); +png_size_t PNGAPI +png_convert_size(size_t size) +{ + if (size > (png_size_t)-1) + PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ + return ((png_size_t)size); +} +#endif /* PNG_SIZE_T */