updated libpng to 1.2.30

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27012 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2008-08-17 22:03:24 +00:00
parent 8b97187793
commit 0b25da8b45
18 changed files with 1143 additions and 1015 deletions
+40 -15
View File
@@ -1,7 +1,6 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.2.26 - April 2, 2008 * libpng version 1.2.30 - August 15, 2008
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -9,7 +8,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * 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.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.2.26 - April 2, 2008: Glenn * libpng versions 0.97, January 1998, through 1.2.30 - August 15, 2008: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@@ -181,6 +180,24 @@
* 1.2.25 13 10225 12.so.0.25[.0] * 1.2.25 13 10225 12.so.0.25[.0]
* 1.2.26beta01-06 13 10226 12.so.0.26[.0] * 1.2.26beta01-06 13 10226 12.so.0.26[.0]
* 1.2.26rc01 13 10226 12.so.0.26[.0] * 1.2.26rc01 13 10226 12.so.0.26[.0]
* 1.2.26 13 10226 12.so.0.26[.0]
* 1.0.32 10 10032 10.so.0.32[.0]
* 1.2.27beta01-06 13 10227 12.so.0.27[.0]
* 1.2.27rc01 13 10227 12.so.0.27[.0]
* 1.0.33 10 10033 10.so.0.33[.0]
* 1.2.27 13 10227 12.so.0.27[.0]
* 1.0.34 10 10034 10.so.0.34[.0]
* 1.2.28 13 10228 12.so.0.28[.0]
* 1.2.29beta01-03 13 10229 12.so.0.29[.0]
* 1.2.29rc01 13 10229 12.so.0.29[.0]
* 1.0.35 10 10035 10.so.0.35[.0]
* 1.2.29 13 10229 12.so.0.29[.0]
* 1.0.37 10 10037 10.so.0.37[.0]
* 1.2.30beta01-04 13 10230 12.so.0.30[.0]
* 1.0.38rc01-08 10 10038 10.so.0.38[.0]
* 1.2.30rc01-08 13 10230 12.so.0.30[.0]
* 1.0.38 10 10038 10.so.0.38[.0]
* 1.2.30 13 10230 12.so.0.30[.0]
* *
* Henceforth the source version will match the shared-library major * Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be * and minor numbers; the shared-library major version number will be
@@ -190,7 +207,7 @@
* to the source version x.y.z (leading zeros in y and z). Beta versions * to the source version x.y.z (leading zeros in y and z). Beta versions
* were given the previous public release number plus a letter, until * were given the previous public release number plus a letter, until
* version 1.0.6j; from then on they were given the upcoming public * version 1.0.6j; from then on they were given the upcoming public
* release number plus "betaNN" or "rcN". * release number plus "betaNN" or "rcNN".
* *
* Binary incompatibility exists only when applications make direct access * Binary incompatibility exists only when applications make direct access
* to the info_ptr or png_ptr members through png.h, and the compiled * to the info_ptr or png_ptr members through png.h, and the compiled
@@ -210,7 +227,7 @@
* If you modify libpng you may insert additional notices immediately following * If you modify libpng you may insert additional notices immediately following
* this sentence. * this sentence.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.2.26, April 2, 2008, are * libpng versions 1.2.6, August 15, 2004, through 1.2.30, August 15, 2008, are
* Copyright (c) 2004, 2006-2008 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006-2008 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
@@ -322,13 +339,13 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* April 2, 2008 * August 15, 2008
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
* *
* This is your unofficial assurance that libpng from version 0.71 and * This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.2.26 are Y2K compliant. It is my belief that earlier * upward through 1.2.30 are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant. * versions were also Y2K compliant.
* *
* Libpng only has three year fields. One is a 2-byte unsigned integer * Libpng only has three year fields. One is a 2-byte unsigned integer
@@ -384,9 +401,9 @@
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.2.26" #define PNG_LIBPNG_VER_STRING "1.2.30"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.2.26 - April 2, 2008\n" " libpng version 1.2.30 - August 15, 2008\n"
#define PNG_LIBPNG_VER_SONUM 0 #define PNG_LIBPNG_VER_SONUM 0
#define PNG_LIBPNG_VER_DLLNUM 13 #define PNG_LIBPNG_VER_DLLNUM 13
@@ -394,7 +411,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 2 #define PNG_LIBPNG_VER_MINOR 2
#define PNG_LIBPNG_VER_RELEASE 26 #define PNG_LIBPNG_VER_RELEASE 30
/* This should match the numeric part of the final component of /* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */ * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
@@ -422,7 +439,7 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only * 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.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
#define PNG_LIBPNG_VER 10226 /* 1.2.26 */ #define PNG_LIBPNG_VER 10230 /* 1.2.30 */
#ifndef PNG_VERSION_INFO_ONLY #ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */ /* include the compression library's header */
@@ -1193,7 +1210,7 @@ struct png_struct_def
png_uint_32 row_number; /* current row in interlace pass */ png_uint_32 row_number; /* current row in interlace pass */
png_bytep prev_row; /* buffer to save previous (unfiltered) row */ png_bytep prev_row; /* buffer to save previous (unfiltered) row */
png_bytep row_buf; /* buffer to save current (unfiltered) row */ png_bytep row_buf; /* buffer to save current (unfiltered) row */
#ifndef PNG_NO_WRITE_FILTERING #ifndef PNG_NO_WRITE_FILTER
png_bytep sub_row; /* buffer to save "sub" row when filtering */ png_bytep sub_row; /* buffer to save "sub" row when filtering */
png_bytep up_row; /* buffer to save "up" row when filtering */ png_bytep up_row; /* buffer to save "up" row when filtering */
png_bytep avg_row; /* buffer to save "avg" row when filtering */ png_bytep avg_row; /* buffer to save "avg" row when filtering */
@@ -1433,13 +1450,17 @@ struct png_struct_def
/* New members added in libpng-1.2.26 */ /* New members added in libpng-1.2.26 */
png_uint_32 old_big_row_buf_size, old_prev_row_size; png_uint_32 old_big_row_buf_size, old_prev_row_size;
/* New member added in libpng-1.2.30 */
png_charp chunkdata; /* buffer for reading chunk data */
}; };
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef png_structp version_1_2_26; typedef png_structp version_1_2_30;
typedef png_struct FAR * FAR * png_structpp; typedef png_struct FAR * FAR * png_structpp;
@@ -2634,6 +2655,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
png_ptr)); png_ptr));
#endif #endif
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */ /* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
@@ -3015,8 +3037,8 @@ PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
/* Decompress data in a chunk that uses compression */ /* Decompress data in a chunk that uses compression */
#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr, PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
int comp_type, png_charp chunkdata, png_size_t chunklength, int comp_type, png_size_t chunklength,
png_size_t prefix_length, png_size_t *data_length)); png_size_t prefix_length, png_size_t *data_length));
#endif #endif
@@ -3545,6 +3567,9 @@ png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
#endif /* PNG_pHYs_SUPPORTED */ #endif /* PNG_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
/* Read the chunk header (length + type name) */
PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
#endif /* PNG_INTERNAL */ #endif /* PNG_INTERNAL */
+1 -1
View File
@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.2.26 - April 2, 2008 * libpng version 1.2.30 - August 15, 2008
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
+6 -5
View File
@@ -1,9 +1,9 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* Last changed in libpng 1.2.21 October 4, 2007 * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -13,7 +13,7 @@
#include "png.h" #include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_2_26 Your_png_h_is_not_version_1_2_26; typedef version_1_2_30 Your_png_h_is_not_version_1_2_30;
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. */ * string defined in png.h. */
@@ -380,11 +380,11 @@ if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
#endif #endif
{ {
png_free(png_ptr, info_ptr->trans); png_free(png_ptr, info_ptr->trans);
info_ptr->trans = NULL;
info_ptr->valid &= ~PNG_INFO_tRNS; info_ptr->valid &= ~PNG_INFO_tRNS;
#ifndef PNG_FREE_ME_SUPPORTED #ifndef PNG_FREE_ME_SUPPORTED
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif #endif
info_ptr->trans = NULL;
} }
#endif #endif
@@ -490,6 +490,7 @@ if (mask & PNG_FREE_SPLT)
png_free(png_ptr, png_ptr->unknown_chunk.data); png_free(png_ptr, png_ptr->unknown_chunk.data);
png_ptr->unknown_chunk.data = NULL; png_ptr->unknown_chunk.data = NULL;
} }
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
#else #else
@@ -693,7 +694,7 @@ png_charp PNGAPI
png_get_copyright(png_structp png_ptr) png_get_copyright(png_structp png_ptr)
{ {
png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
return ((png_charp) "\n libpng version 1.2.26 - April 2, 2008\n\ return ((png_charp) "\n libpng version 1.2.30 - August 15, 2008\n\
Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\ Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\ Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
+14 -12
View File
@@ -1,9 +1,9 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* Last changed in libpng 1.2.22 [October 13, 2007] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -15,8 +15,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr, png_default_error PNGARG((png_structp png_ptr,
png_const_charp error_message)); png_const_charp error_message));
@@ -44,16 +44,17 @@ png_error(png_structp png_ptr, png_const_charp error_message)
{ {
if (*error_message == '#') if (*error_message == '#')
{ {
/* Strip "#nnnn " from beginning of error message. */
int offset; int offset;
for (offset = 1; offset<15; offset++) for (offset = 1; offset<15; offset++)
if (*(error_message+offset) == ' ') if (error_message[offset] == ' ')
break; break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{ {
int i; int i;
for (i = 0; i < offset - 1; i++) for (i = 0; i < offset - 1; i++)
msg[i] = error_message[i + 1]; msg[i] = error_message[i + 1];
msg[i]='\0'; msg[i - 1] = '\0';
error_message = msg; error_message = msg;
} }
else else
@@ -111,7 +112,7 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
if (*warning_message == '#') if (*warning_message == '#')
{ {
for (offset = 1; offset < 15; offset++) for (offset = 1; offset < 15; offset++)
if (*(warning_message+offset) == ' ') if (warning_message[offset] == ' ')
break; break;
} }
} }
@@ -216,19 +217,20 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*error_message == '#') if (*error_message == '#')
{ {
/* Strip "#nnnn " from beginning of warning message. */
int offset; int offset;
char error_number[16]; char error_number[16];
for (offset = 0; offset<15; offset++) for (offset = 0; offset<15; offset++)
{ {
error_number[offset] = *(error_message+offset+1); error_number[offset] = error_message[offset + 1];
if (*(error_message+offset) == ' ') if (error_message[offset] == ' ')
break; break;
} }
if ((offset > 1) && (offset < 15)) if ((offset > 1) && (offset < 15))
{ {
error_number[offset - 1] = '\0'; error_number[offset - 1] = '\0';
fprintf(stderr, "libpng error no. %s: %s\n", error_number, fprintf(stderr, "libpng error no. %s: %s\n", error_number,
error_message+offset); error_message + offset + 1);
} }
else else
fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset); fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
@@ -276,13 +278,13 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message)
char warning_number[16]; char warning_number[16];
for (offset = 0; offset < 15; offset++) for (offset = 0; offset < 15; offset++)
{ {
warning_number[offset]=*(warning_message+offset+1); warning_number[offset] = warning_message[offset + 1];
if (*(warning_message+offset) == ' ') if (warning_message[offset] == ' ')
break; break;
} }
if ((offset > 1) && (offset < 15)) if ((offset > 1) && (offset < 15))
{ {
warning_number[offset-1]='\0'; warning_number[offset + 1] = '\0';
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number, fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
warning_message + offset); warning_message + offset);
} }
+3 -1
View File
@@ -2,8 +2,10 @@
/* This code snippet is for use by configure's compilation test. */ /* This code snippet is for use by configure's compilation test. */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ #if (!defined _MSC_VER) && \
defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \
defined(PNG_MMX_CODE_SUPPORTED) defined(PNG_MMX_CODE_SUPPORTED)
int PNGAPI png_dummy_mmx_support(void); int PNGAPI png_dummy_mmx_support(void);
static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested
+2 -3
View File
@@ -1,16 +1,15 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* Last changed in libpng 1.2.15 January 5, 2007 * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
png_uint_32 PNGAPI png_uint_32 PNGAPI
+5 -4
View File
@@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* Last changed in libpng 1.2.26 [April 2, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -16,7 +16,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Borland DOS special memory handler */ /* Borland DOS special memory handler */
@@ -273,6 +272,7 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
/* free a pointer allocated by png_malloc(). In the default /* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */ is needed. If ptr is NULL, return without taking any action. */
void PNGAPI void PNGAPI
png_free(png_structp png_ptr, png_voidp ptr) png_free(png_structp png_ptr, png_voidp ptr)
{ {
@@ -293,7 +293,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
if(png_ptr == NULL) return; if (png_ptr == NULL || ptr == NULL) return;
if (png_ptr->offset_table != NULL) if (png_ptr->offset_table != NULL)
{ {
@@ -587,7 +587,8 @@ void PNGAPI
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn) malloc_fn, png_free_ptr free_fn)
{ {
if(png_ptr != NULL) { if (png_ptr != NULL)
{
png_ptr->mem_ptr = mem_ptr; png_ptr->mem_ptr = mem_ptr;
png_ptr->malloc_fn = malloc_fn; png_ptr->malloc_fn = malloc_fn;
png_ptr->free_fn = free_fn; png_ptr->free_fn = free_fn;
+33 -32
View File
@@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* Last changed in libpng 1.2.26 [April 2, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -10,7 +10,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
/* push model modes */ /* push model modes */
@@ -213,6 +212,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
png_reset_crc(png_ptr); png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4); png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
} }
@@ -221,11 +221,11 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{ {
if (png_ptr->push_length != 13) if (png_ptr->push_length != 13)
png_error(png_ptr, "Invalid IHDR length"); png_error(png_ptr, "Invalid IHDR length");
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
png_push_save_buffer(png_ptr); png_push_save_buffer(png_ptr);
return; return;
} }
@@ -1020,23 +1020,21 @@ png_read_push_finish_row(png_structp png_ptr)
png_ptr->rowbytes + 1); png_ptr->rowbytes + 1);
do do
{ {
int pass; png_ptr->pass++;
pass = png_ptr->pass; if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
pass++; (png_ptr->pass == 3 && png_ptr->width < 3) ||
if ((pass == 1 && png_ptr->width < 5) || (png_ptr->pass == 5 && png_ptr->width < 2))
(pass == 3 && png_ptr->width < 3) || png_ptr->pass++;
(pass == 5 && png_ptr->width < 2))
pass++; if (png_ptr->pass > 7)
png_ptr->pass--;
if (png_ptr->pass >= 7)
break;
if (pass > 7)
pass--;
png_ptr->pass = (png_byte) pass;
if (pass < 7)
{
png_ptr->iwidth = (png_ptr->width + png_ptr->iwidth = (png_ptr->width +
png_pass_inc[pass] - 1 - png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[pass]) / png_pass_start[png_ptr->pass]) /
png_pass_inc[pass]; png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
png_ptr->iwidth) + 1; png_ptr->iwidth) + 1;
@@ -1045,12 +1043,9 @@ png_read_push_finish_row(png_structp png_ptr)
break; break;
png_ptr->num_rows = (png_ptr->height + png_ptr->num_rows = (png_ptr->height +
png_pass_yinc[pass] - 1 - png_pass_yinc[png_ptr->pass] - 1 -
png_pass_ystart[pass]) / png_pass_ystart[png_ptr->pass]) /
png_pass_yinc[pass]; png_pass_yinc[png_ptr->pass];
}
else
break;
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
} }
@@ -1268,8 +1263,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL) if (text == NULL)
{ {
text = (png_charp)png_malloc(png_ptr, text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out (png_uint_32)(png_ptr->zbuf_size
+ key_size + 1)); - png_ptr->zstream.avail_out + key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf, png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out); png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size); png_memcpy(text, key, key_size);
@@ -1283,8 +1278,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
tmp = text; tmp = text;
text = (png_charp)png_malloc(png_ptr, text_size + text = (png_charp)png_malloc(png_ptr, text_size +
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out (png_uint_32)(png_ptr->zbuf_size
+ 1)); - png_ptr->zstream.avail_out));
png_memcpy(text, tmp, text_size); png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp); png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf, png_memcpy(text + text_size, png_ptr->zbuf,
@@ -1469,7 +1464,6 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
length) length)
{ {
png_uint_32 skip = 0; png_uint_32 skip = 0;
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
{ {
@@ -1500,11 +1494,18 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
png_memcpy((png_charp)png_ptr->unknown_chunk.name, png_memcpy((png_charp)png_ptr->unknown_chunk.name,
(png_charp)png_ptr->chunk_name, (png_charp)png_ptr->chunk_name,
png_sizeof(png_ptr->unknown_chunk.name)); png_sizeof(png_ptr->unknown_chunk.name));
png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]='\0'; png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
= '\0';
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_ptr->unknown_chunk.size = (png_size_t)length; png_ptr->unknown_chunk.size = (png_size_t)length;
if (length == 0)
png_ptr->unknown_chunk.data = NULL;
else
{
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
(png_uint_32)length);
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
}
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if (png_ptr->read_user_chunk_fn != NULL) if (png_ptr->read_user_chunk_fn != NULL)
{ {
+63 -83
View File
@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* Last changed in libpng 1.2.25 [February 18, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -13,7 +13,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #if defined(PNG_READ_SUPPORTED)
/* Create a PNG structure for reading, and allocate any memory needed. */ /* Create a PNG structure for reading, and allocate any memory needed. */
@@ -35,6 +34,9 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_SETJMP_SUPPORTED
volatile
#endif
png_structp png_ptr; png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@@ -406,38 +408,29 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
PNG_CONST PNG_zTXt; PNG_CONST PNG_zTXt;
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
png_byte chunk_length[4]; png_uint_32 length = png_read_chunk_header(png_ptr);
png_uint_32 length; PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
png_read_data(png_ptr, chunk_length, 4);
length = png_get_uint_31(png_ptr,chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
length);
/* This should be a binary subdivision search or a hash for /* This should be a binary subdivision search or a hash for
* matching the chunk name rather than a linear search. * matching the chunk name rather than a linear search.
*/ */
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (!png_memcmp(chunk_name, png_IDAT, 4))
if (png_ptr->mode & PNG_AFTER_IDAT) if (png_ptr->mode & PNG_AFTER_IDAT)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) if (!png_memcmp(chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length); png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) else if (!png_memcmp(chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length); png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) else if (png_handle_as_unknown(png_ptr, chunk_name))
{ {
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (!png_memcmp(chunk_name, png_IDAT, 4))
png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->mode |= PNG_HAVE_IDAT;
png_handle_unknown(png_ptr, info_ptr, length); png_handle_unknown(png_ptr, info_ptr, length);
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) if (!png_memcmp(chunk_name, png_PLTE, 4))
png_ptr->mode |= PNG_HAVE_PLTE; png_ptr->mode |= PNG_HAVE_PLTE;
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) else if (!png_memcmp(chunk_name, png_IDAT, 4))
{ {
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT"); png_error(png_ptr, "Missing IHDR before IDAT");
@@ -448,9 +441,9 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
} }
} }
#endif #endif
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) else if (!png_memcmp(chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length); png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) else if (!png_memcmp(chunk_name, png_IDAT, 4))
{ {
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT"); png_error(png_ptr, "Missing IHDR before IDAT");
@@ -463,71 +456,71 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
break; break;
} }
#if defined(PNG_READ_bKGD_SUPPORTED) #if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) else if (!png_memcmp(chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length); png_handle_bKGD(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #if defined(PNG_READ_cHRM_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) else if (!png_memcmp(chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) else if (!png_memcmp(chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #if defined(PNG_READ_hIST_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) else if (!png_memcmp(chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length); png_handle_hIST(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #if defined(PNG_READ_oFFs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) else if (!png_memcmp(chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length); png_handle_oFFs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #if defined(PNG_READ_pCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) else if (!png_memcmp(chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length); png_handle_pCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #if defined(PNG_READ_sCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) else if (!png_memcmp(chunk_name, png_sCAL, 4))
png_handle_sCAL(png_ptr, info_ptr, length); png_handle_sCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #if defined(PNG_READ_pHYs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) else if (!png_memcmp(chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length); png_handle_pHYs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #if defined(PNG_READ_sBIT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) else if (!png_memcmp(chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length); png_handle_sBIT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #if defined(PNG_READ_sRGB_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) else if (!png_memcmp(chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length); png_handle_sRGB(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #if defined(PNG_READ_iCCP_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) else if (!png_memcmp(chunk_name, png_iCCP, 4))
png_handle_iCCP(png_ptr, info_ptr, length); png_handle_iCCP(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #if defined(PNG_READ_sPLT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) else if (!png_memcmp(chunk_name, png_sPLT, 4))
png_handle_sPLT(png_ptr, info_ptr, length); png_handle_sPLT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) else if (!png_memcmp(chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length); png_handle_tEXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #if defined(PNG_READ_tIME_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) else if (!png_memcmp(chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length); png_handle_tIME(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #if defined(PNG_READ_tRNS_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) else if (!png_memcmp(chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length); png_handle_tRNS(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_zTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) else if (!png_memcmp(chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length); png_handle_zTXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #if defined(PNG_READ_iTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) else if (!png_memcmp(chunk_name, png_iTXt, 4))
png_handle_iTXt(png_ptr, info_ptr, length); png_handle_iTXt(png_ptr, info_ptr, length);
#endif #endif
else else
@@ -703,15 +696,9 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
{ {
while (!png_ptr->idat_size) while (!png_ptr->idat_size)
{ {
png_byte chunk_length[4];
png_crc_finish(png_ptr, 0); png_crc_finish(png_ptr, 0);
png_read_data(png_ptr, chunk_length, 4); png_ptr->idat_size = png_read_chunk_header(png_ptr);
png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
png_error(png_ptr, "Not enough image data"); png_error(png_ptr, "Not enough image data");
} }
@@ -920,9 +907,6 @@ png_read_image(png_structp png_ptr, png_bytepp image)
void PNGAPI void PNGAPI
png_read_end(png_structp png_ptr, png_infop info_ptr) png_read_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_byte chunk_length[4];
png_uint_32 length;
png_debug(1, "in png_read_end\n"); png_debug(1, "in png_read_end\n");
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
@@ -986,33 +970,27 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
PNG_CONST PNG_zTXt; PNG_CONST PNG_zTXt;
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
png_uint_32 length = png_read_chunk_header(png_ptr);
PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
png_read_data(png_ptr, chunk_length, 4); if (!png_memcmp(chunk_name, png_IHDR, 4))
length = png_get_uint_31(png_ptr,chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length); png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) else if (!png_memcmp(chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length); png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) else if (png_handle_as_unknown(png_ptr, chunk_name))
{ {
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (!png_memcmp(chunk_name, png_IDAT, 4))
{ {
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
png_error(png_ptr, "Too many IDAT's found"); png_error(png_ptr, "Too many IDAT's found");
} }
png_handle_unknown(png_ptr, info_ptr, length); png_handle_unknown(png_ptr, info_ptr, length);
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) if (!png_memcmp(chunk_name, png_PLTE, 4))
png_ptr->mode |= PNG_HAVE_PLTE; png_ptr->mode |= PNG_HAVE_PLTE;
} }
#endif #endif
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) else if (!png_memcmp(chunk_name, png_IDAT, 4))
{ {
/* Zero length IDATs are legal after the last IDAT has been /* Zero length IDATs are legal after the last IDAT has been
* read, but not after other chunks have been read. * read, but not after other chunks have been read.
@@ -1021,74 +999,74 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
png_error(png_ptr, "Too many IDAT's found"); png_error(png_ptr, "Too many IDAT's found");
png_crc_finish(png_ptr, length); png_crc_finish(png_ptr, length);
} }
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) else if (!png_memcmp(chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length); png_handle_PLTE(png_ptr, info_ptr, length);
#if defined(PNG_READ_bKGD_SUPPORTED) #if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) else if (!png_memcmp(chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length); png_handle_bKGD(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #if defined(PNG_READ_cHRM_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) else if (!png_memcmp(chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) else if (!png_memcmp(chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #if defined(PNG_READ_hIST_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) else if (!png_memcmp(chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length); png_handle_hIST(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_oFFs_SUPPORTED) #if defined(PNG_READ_oFFs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) else if (!png_memcmp(chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length); png_handle_oFFs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #if defined(PNG_READ_pCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) else if (!png_memcmp(chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length); png_handle_pCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) #if defined(PNG_READ_sCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) else if (!png_memcmp(chunk_name, png_sCAL, 4))
png_handle_sCAL(png_ptr, info_ptr, length); png_handle_sCAL(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #if defined(PNG_READ_pHYs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) else if (!png_memcmp(chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length); png_handle_pHYs(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sBIT_SUPPORTED) #if defined(PNG_READ_sBIT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) else if (!png_memcmp(chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length); png_handle_sBIT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #if defined(PNG_READ_sRGB_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) else if (!png_memcmp(chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length); png_handle_sRGB(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #if defined(PNG_READ_iCCP_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) else if (!png_memcmp(chunk_name, png_iCCP, 4))
png_handle_iCCP(png_ptr, info_ptr, length); png_handle_iCCP(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #if defined(PNG_READ_sPLT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) else if (!png_memcmp(chunk_name, png_sPLT, 4))
png_handle_sPLT(png_ptr, info_ptr, length); png_handle_sPLT(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tEXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) else if (!png_memcmp(chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length); png_handle_tEXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #if defined(PNG_READ_tIME_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) else if (!png_memcmp(chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length); png_handle_tIME(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #if defined(PNG_READ_tRNS_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) else if (!png_memcmp(chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length); png_handle_tRNS(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_zTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) else if (!png_memcmp(chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length); png_handle_zTXt(png_ptr, info_ptr, length);
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #if defined(PNG_READ_iTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) else if (!png_memcmp(chunk_name, png_iTXt, 4))
png_handle_iTXt(png_ptr, info_ptr, length); png_handle_iTXt(png_ptr, info_ptr, length);
#endif #endif
else else
@@ -1111,9 +1089,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_debug(1, "in png_destroy_read_struct\n"); png_debug(1, "in png_destroy_read_struct\n");
if (png_ptr_ptr != NULL) if (png_ptr_ptr != NULL)
{
png_ptr = *png_ptr_ptr; png_ptr = *png_ptr_ptr;
}
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
@@ -1159,6 +1135,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
*end_info_ptr_ptr = NULL; *end_info_ptr_ptr = NULL;
} }
if (png_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr); (png_voidp)mem_ptr);
@@ -1167,6 +1145,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#endif #endif
*png_ptr_ptr = NULL; *png_ptr_ptr = NULL;
} }
}
/* free all memory used by the read (old method) */ /* free all memory used by the read (old method) */
void /* PRIVATE */ void /* PRIVATE */
@@ -1192,6 +1171,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->big_row_buf); png_free(png_ptr, png_ptr->big_row_buf);
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->chunkdata);
#if defined(PNG_READ_DITHER_SUPPORTED) #if defined(PNG_READ_DITHER_SUPPORTED)
png_free(png_ptr, png_ptr->palette_lookup); png_free(png_ptr, png_ptr->palette_lookup);
png_free(png_ptr, png_ptr->dither_index); png_free(png_ptr, png_ptr->dither_index);
+2 -3
View File
@@ -1,9 +1,9 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* Last changed in libpng 1.2.13 November 13, 2006 * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2006 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -17,7 +17,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #if defined(PNG_READ_SUPPORTED)
/* Read the data from whatever input you are using. The default routine /* Read the data from whatever input you are using. The default routine
+17 -20
View File
@@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* Last changed in libpng 1.2.25 [February 18, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -15,7 +15,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #if defined(PNG_READ_SUPPORTED)
/* Set the action on getting a CRC error for an ancillary or critical chunk. */ /* Set the action on getting a CRC error for an ancillary or critical chunk. */
@@ -39,7 +38,8 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
PNG_FLAG_CRC_CRITICAL_IGNORE; PNG_FLAG_CRC_CRITICAL_IGNORE;
break; break;
case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */ case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
png_warning(png_ptr, "Can't discard critical data on CRC error."); png_warning(png_ptr,
"Can't discard critical data on CRC error.");
case PNG_CRC_ERROR_QUIT: /* error/quit */ case PNG_CRC_ERROR_QUIT: /* error/quit */
case PNG_CRC_DEFAULT: case PNG_CRC_DEFAULT:
default: default:
@@ -548,9 +548,7 @@ png_set_expand(png_structp png_ptr)
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
#ifdef PNG_WARN_UNINITIALIZED_ROW
png_ptr->flags &= ~PNG_FLAG_ROW_INIT; png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
#endif
} }
/* GRR 19990627: the following three functions currently are identical /* GRR 19990627: the following three functions currently are identical
@@ -577,9 +575,7 @@ png_set_palette_to_rgb(png_structp png_ptr)
png_debug(1, "in png_set_palette_to_rgb\n"); png_debug(1, "in png_set_palette_to_rgb\n");
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
#ifdef PNG_WARN_UNINITIALIZED_ROW
png_ptr->flags &= ~PNG_FLAG_ROW_INIT; png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
#endif
} }
#if !defined(PNG_1_0_X) #if !defined(PNG_1_0_X)
@@ -590,9 +586,7 @@ 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"); png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= PNG_EXPAND;
#ifdef PNG_WARN_UNINITIALIZED_ROW
png_ptr->flags &= ~PNG_FLAG_ROW_INIT; png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
#endif
} }
#endif #endif
@@ -615,9 +609,7 @@ png_set_tRNS_to_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_tRNS_to_alpha\n"); png_debug(1, "in png_set_tRNS_to_alpha\n");
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
#ifdef PNG_WARN_UNINITIALIZED_ROW
png_ptr->flags &= ~PNG_FLAG_ROW_INIT; png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
#endif
} }
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
@@ -627,9 +619,7 @@ png_set_gray_to_rgb(png_structp png_ptr)
{ {
png_debug(1, "in png_set_gray_to_rgb\n"); png_debug(1, "in png_set_gray_to_rgb\n");
png_ptr->transformations |= PNG_GRAY_TO_RGB; png_ptr->transformations |= PNG_GRAY_TO_RGB;
#ifdef PNG_WARN_UNINITIALIZED_ROW
png_ptr->flags &= ~PNG_FLAG_ROW_INIT; png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
#endif
} }
#endif #endif
@@ -669,7 +659,8 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= PNG_EXPAND;
#else #else
{ {
png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); png_warning(png_ptr,
"Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
png_ptr->transformations &= ~PNG_RGB_TO_GRAY; png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
} }
#endif #endif
@@ -693,7 +684,8 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
} }
png_ptr->rgb_to_gray_red_coeff = red_int; png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_int; png_ptr->rgb_to_gray_green_coeff = green_int;
png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int); png_ptr->rgb_to_gray_blue_coeff =
(png_uint_16)(32768 - red_int - green_int);
} }
} }
#endif #endif
@@ -967,7 +959,7 @@ png_init_read_transformations(png_structp png_ptr)
/* Prevent the transformations being done again, and make sure /* Prevent the transformations being done again, and make sure
* that the now spurious alpha channel is stripped - the code * that the now spurious alpha channel is stripped - the code
* has just reduced background composition and gamma correction * has just reduced background composition and gamma correction
* to a simply alpha channel strip. * to a simple alpha channel strip.
*/ */
png_ptr->transformations &= ~PNG_BACKGROUND; png_ptr->transformations &= ~PNG_BACKGROUND;
png_ptr->transformations &= ~PNG_GAMMA; png_ptr->transformations &= ~PNG_GAMMA;
@@ -1138,7 +1130,8 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{ {
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS)) if (png_ptr->num_trans &&
(png_ptr->transformations & PNG_EXPAND_tRNS))
info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else else
info_ptr->color_type = PNG_COLOR_TYPE_RGB; info_ptr->color_type = PNG_COLOR_TYPE_RGB;
@@ -1151,8 +1144,10 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr->transformations & PNG_EXPAND_tRNS) if (png_ptr->transformations & PNG_EXPAND_tRNS)
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
#if 0 /* Removed from libpng-1.2.27 */
else else
info_ptr->color_type |= PNG_COLOR_MASK_COLOR; info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
#endif
} }
if (info_ptr->bit_depth < 8) if (info_ptr->bit_depth < 8)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
@@ -1280,7 +1275,7 @@ png_do_read_transformations(png_structp png_ptr)
char msg[50]; char msg[50];
png_snprintf2(msg, 50, png_snprintf2(msg, 50,
"NULL row buffer for row %ld, pass %d", png_ptr->row_number, "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number,
png_ptr->pass); png_ptr->pass);
png_error(png_ptr, msg); png_error(png_ptr, msg);
#else #else
@@ -2217,8 +2212,10 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
/* reduce RGB files to grayscale, with or without alpha /* reduce RGB files to grayscale, with or without alpha
* using the equation given in Poynton's ColorFAQ at * using the equation given in Poynton's ColorFAQ at
* <http://www.inforamp.net/~poynton/> * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008)
* Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net * New link:
* <http://www.poynton.com/notes/colour_and_gamma/>
* Charles Poynton poynton at poynton.com
* *
* Y = 0.212671 * R + 0.715160 * G + 0.072169 * B * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
* *
+220 -175
View File
@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file /* pngrutil.c - utilities to read a PNG file
* *
* Last changed in libpng 1.2.26 [April 2, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -13,7 +13,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) #if defined(PNG_READ_SUPPORTED)
#if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
@@ -30,7 +29,7 @@ __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **end
wchar_t *str, *end; wchar_t *str, *end;
len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t)); str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t));
if ( NULL != str ) if ( NULL != str )
{ {
MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
@@ -49,7 +48,15 @@ __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **end
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_uint_31(png_structp png_ptr, png_bytep buf) png_get_uint_31(png_structp png_ptr, png_bytep buf)
{ {
#ifdef PNG_READ_BIG_ENDIAN_SUPPORTED
png_uint_32 i = png_get_uint_32(buf); png_uint_32 i = png_get_uint_32(buf);
#else
/* Avoid an extra function call by inlining the result. */
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));
#endif
if (i > PNG_UINT_31_MAX) if (i > PNG_UINT_31_MAX)
png_error(png_ptr, "PNG unsigned integer out of range."); png_error(png_ptr, "PNG unsigned integer out of range.");
return (i); return (i);
@@ -92,6 +99,35 @@ png_get_uint_16(png_bytep buf)
} }
#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
/* Read the chunk header (length + type name).
* Put the type name into png_ptr->chunk_name, and return the length.
*/
png_uint_32 /* PRIVATE */
png_read_chunk_header(png_structp png_ptr)
{
png_byte buf[8];
png_uint_32 length;
/* read the length and the chunk name */
png_read_data(png_ptr, buf, 8);
length = png_get_uint_31(png_ptr, buf);
/* put the chunk name into png_ptr->chunk_name */
png_memcpy(png_ptr->chunk_name, buf + 4, 4);
png_debug2(0, "Reading %s chunk, length = %lu\n",
png_ptr->chunk_name, length);
/* reset the crc and run it over the chunk name */
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, png_ptr->chunk_name, 4);
/* check to see if chunk name is valid */
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
return length;
}
/* Read data, and (optionally) run it through the CRC. */ /* Read data, and (optionally) run it through the CRC. */
void /* PRIVATE */ void /* PRIVATE */
png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
@@ -180,9 +216,9 @@ png_crc_error(png_structp png_ptr)
* holding the original prefix part and an uncompressed version of the * holding the original prefix part and an uncompressed version of the
* trailing part (the malloc area passed in is freed). * trailing part (the malloc area passed in is freed).
*/ */
png_charp /* PRIVATE */ void /* PRIVATE */
png_decompress_chunk(png_structp png_ptr, int comp_type, png_decompress_chunk(png_structp png_ptr, int comp_type,
png_charp chunkdata, png_size_t chunklength, png_size_t chunklength,
png_size_t prefix_size, png_size_t *newlength) png_size_t prefix_size, png_size_t *newlength)
{ {
static PNG_CONST char msg[] = "Error decoding compressed text"; static PNG_CONST char msg[] = "Error decoding compressed text";
@@ -192,7 +228,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
if (comp_type == PNG_COMPRESSION_TYPE_BASE) if (comp_type == PNG_COMPRESSION_TYPE_BASE)
{ {
int ret = Z_OK; int ret = Z_OK;
png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size); png_ptr->zstream.next_in = (png_bytep)(png_ptr->chunkdata + prefix_size);
png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size); png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
@@ -218,18 +254,20 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text = (png_charp)png_malloc_warn(png_ptr, text_size); text = (png_charp)png_malloc_warn(png_ptr, text_size);
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr,chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_error(png_ptr, "Not enough memory to decompress chunk"); png_error(png_ptr, "Not enough memory to decompress chunk");
} }
png_memcpy(text, chunkdata, prefix_size); png_memcpy(text, png_ptr->chunkdata, prefix_size);
} }
text[text_size - 1] = 0x00; text[text_size - 1] = 0x00;
/* Copy what we can of the error message into the text chunk */ /* Copy what we can of the error message into the text chunk */
text_size = (png_size_t)(chunklength - (text - chunkdata) - 1); text_size = (png_size_t)(chunklength -
text_size = png_sizeof(msg) > text_size ? text_size : (text - png_ptr->chunkdata) - 1);
png_sizeof(msg); if (text_size > png_sizeof(msg))
text_size = png_sizeof(msg);
png_memcpy(text + prefix_size, msg, text_size); png_memcpy(text + prefix_size, msg, text_size);
break; break;
} }
@@ -242,12 +280,14 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text = (png_charp)png_malloc_warn(png_ptr, text_size + 1); text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr,chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_error(png_ptr,"Not enough memory to decompress chunk."); png_ptr->chunkdata = NULL;
png_error(png_ptr,
"Not enough memory to decompress chunk.");
} }
png_memcpy(text + prefix_size, png_ptr->zbuf, png_memcpy(text + prefix_size, png_ptr->zbuf,
text_size - prefix_size); text_size - prefix_size);
png_memcpy(text, chunkdata, prefix_size); png_memcpy(text, png_ptr->chunkdata, prefix_size);
*(text + text_size) = 0x00; *(text + text_size) = 0x00;
} }
else else
@@ -261,8 +301,10 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr, tmp); png_free(png_ptr, tmp);
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_error(png_ptr,"Not enough memory to decompress chunk.."); png_ptr->chunkdata = NULL;
png_error(png_ptr,
"Not enough memory to decompress chunk..");
} }
png_memcpy(text, tmp, text_size); png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp); png_free(png_ptr, tmp);
@@ -308,10 +350,11 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text = (png_charp)png_malloc_warn(png_ptr, text_size+1); text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_error(png_ptr, "Not enough memory for text."); png_error(png_ptr, "Not enough memory for text.");
} }
png_memcpy(text, chunkdata, prefix_size); png_memcpy(text, png_ptr->chunkdata, prefix_size);
} }
*(text + text_size) = 0x00; *(text + text_size) = 0x00;
} }
@@ -319,8 +362,8 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
inflateReset(&png_ptr->zstream); inflateReset(&png_ptr->zstream);
png_ptr->zstream.avail_in = 0; png_ptr->zstream.avail_in = 0;
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
chunkdata = text; png_ptr->chunkdata = text;
*newlength=text_size; *newlength=text_size;
} }
else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
@@ -328,18 +371,15 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char umsg[50]; char umsg[50];
png_snprintf(umsg, 50, png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type);
"Unknown zTXt compression type %d", comp_type);
png_warning(png_ptr, umsg); png_warning(png_ptr, umsg);
#else #else
png_warning(png_ptr, "Unknown zTXt compression type"); png_warning(png_ptr, "Unknown zTXt compression type");
#endif #endif
*(chunkdata + prefix_size) = 0x00; *(png_ptr->chunkdata + prefix_size) = 0x00;
*newlength = prefix_size; *newlength = prefix_size;
} }
return chunkdata;
} }
#endif #endif
@@ -725,7 +765,7 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void /* PRIVATE */ void /* PRIVATE */
png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_byte buf[4]; png_byte buf[32];
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
#endif #endif
@@ -766,62 +806,46 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return; return;
} }
png_crc_read(png_ptr, buf, 4); png_crc_read(png_ptr, buf, 32);
if (png_crc_finish(png_ptr, 0))
return;
uint_x = png_get_uint_32(buf); uint_x = png_get_uint_32(buf);
uint_y = png_get_uint_32(buf + 4);
png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf);
if (uint_x > 80000L || uint_y > 80000L || if (uint_x > 80000L || uint_y > 80000L ||
uint_x + uint_y > 100000L) uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM white point"); png_warning(png_ptr, "Invalid cHRM white point");
png_crc_finish(png_ptr, 24);
return; return;
} }
int_x_white = (png_fixed_point)uint_x; int_x_white = (png_fixed_point)uint_x;
int_y_white = (png_fixed_point)uint_y; int_y_white = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4); uint_x = png_get_uint_32(buf + 8);
uint_x = png_get_uint_32(buf); uint_y = png_get_uint_32(buf + 12);
png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf);
if (uint_x + uint_y > 100000L) if (uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM red point"); png_warning(png_ptr, "Invalid cHRM red point");
png_crc_finish(png_ptr, 16);
return; return;
} }
int_x_red = (png_fixed_point)uint_x; int_x_red = (png_fixed_point)uint_x;
int_y_red = (png_fixed_point)uint_y; int_y_red = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4); uint_x = png_get_uint_32(buf + 16);
uint_x = png_get_uint_32(buf); uint_y = png_get_uint_32(buf + 20);
png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf);
if (uint_x + uint_y > 100000L) if (uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM green point"); png_warning(png_ptr, "Invalid cHRM green point");
png_crc_finish(png_ptr, 8);
return; return;
} }
int_x_green = (png_fixed_point)uint_x; int_x_green = (png_fixed_point)uint_x;
int_y_green = (png_fixed_point)uint_y; int_y_green = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4); uint_x = png_get_uint_32(buf + 24);
uint_x = png_get_uint_32(buf); uint_y = png_get_uint_32(buf + 28);
png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf);
if (uint_x + uint_y > 100000L) if (uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM blue point"); png_warning(png_ptr, "Invalid cHRM blue point");
png_crc_finish(png_ptr, 0);
return; return;
} }
int_x_blue = (png_fixed_point)uint_x; int_x_blue = (png_fixed_point)uint_x;
@@ -866,7 +890,6 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif #endif
#endif /* PNG_NO_CONSOLE_IO */ #endif /* PNG_NO_CONSOLE_IO */
} }
png_crc_finish(png_ptr, 0);
return; return;
} }
#endif /* PNG_READ_sRGB_SUPPORTED */ #endif /* PNG_READ_sRGB_SUPPORTED */
@@ -949,7 +972,8 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
"Ignoring incorrect gAMA value when sRGB is also present"); "Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO #ifndef PNG_NO_CONSOLE_IO
# ifdef PNG_FIXED_POINT_SUPPORTED # ifdef PNG_FIXED_POINT_SUPPORTED
fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma); fprintf(stderr, "incorrect gamma=(%d/100000)\n",
(int)png_ptr->int_gamma);
# else # else
# ifdef PNG_FLOATING_POINT_SUPPORTED # ifdef PNG_FLOATING_POINT_SUPPORTED
fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma); fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma);
@@ -987,7 +1011,6 @@ void /* PRIVATE */
png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Note: this does not properly handle chunks that are > 64K under DOS */ /* Note: this does not properly handle chunks that are > 64K under DOS */
{ {
png_charp chunkdata;
png_byte compression_type; png_byte compression_type;
png_bytep pC; png_bytep pC;
png_charp profile; png_charp profile;
@@ -1025,28 +1048,31 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
chunkdata = (png_charp)png_malloc(png_ptr, length + 1); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, skip)) if (png_crc_finish(png_ptr, skip))
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
chunkdata[slength] = 0x00; png_ptr->chunkdata[slength] = 0x00;
for (profile = chunkdata; *profile; profile++) for (profile = png_ptr->chunkdata; *profile; profile++)
/* empty loop to find end of name */ ; /* empty loop to find end of name */ ;
++profile; ++profile;
/* there should be at least one zero (the compression type byte) /* there should be at least one zero (the compression type byte)
following the separator, and we should be on it */ following the separator, and we should be on it */
if ( profile >= chunkdata + slength - 1) if ( profile >= png_ptr->chunkdata + slength - 1)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "Malformed iCCP chunk"); png_warning(png_ptr, "Malformed iCCP chunk");
return; return;
} }
@@ -1060,21 +1086,22 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
wrote nonzero) */ wrote nonzero) */
} }
prefix_length = profile - chunkdata; prefix_length = profile - png_ptr->chunkdata;
chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata, png_decompress_chunk(png_ptr, compression_type,
slength, prefix_length, &data_length); slength, prefix_length, &data_length);
profile_length = data_length - prefix_length; profile_length = data_length - prefix_length;
if ( prefix_length > data_length || profile_length < 4) if ( prefix_length > data_length || profile_length < 4)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "Profile size field missing from iCCP chunk"); png_warning(png_ptr, "Profile size field missing from iCCP chunk");
return; return;
} }
/* Check the profile_size recorded in the first 32 bits of the ICC profile */ /* Check the profile_size recorded in the first 32 bits of the ICC profile */
pC = (png_bytep)(chunkdata+prefix_length); pC = (png_bytep)(png_ptr->chunkdata + prefix_length);
profile_size = ((*(pC ))<<24) | profile_size = ((*(pC ))<<24) |
((*(pC + 1))<<16) | ((*(pC + 1))<<16) |
((*(pC + 2))<< 8) | ((*(pC + 2))<< 8) |
@@ -1085,14 +1112,16 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (profile_size > profile_length) if (profile_size > profile_length)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "Ignoring truncated iCCP profile."); png_warning(png_ptr, "Ignoring truncated iCCP profile.");
return; return;
} }
png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type, png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata,
chunkdata + prefix_length, profile_length); compression_type, png_ptr->chunkdata + prefix_length, profile_length);
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
} }
#endif /* PNG_READ_iCCP_SUPPORTED */ #endif /* PNG_READ_iCCP_SUPPORTED */
@@ -1101,7 +1130,6 @@ void /* PRIVATE */
png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Note: this does not properly handle chunks that are > 64K under DOS */ /* Note: this does not properly handle chunks that are > 64K under DOS */
{ {
png_bytep chunkdata;
png_bytep entry_start; png_bytep entry_start;
png_sPLT_t new_palette; png_sPLT_t new_palette;
#ifdef PNG_NO_POINTER_INDEXING #ifdef PNG_NO_POINTER_INDEXING
@@ -1131,45 +1159,49 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
chunkdata = (png_bytep)png_malloc(png_ptr, length + 1); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, skip)) if (png_crc_finish(png_ptr, skip))
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
chunkdata[slength] = 0x00; png_ptr->chunkdata[slength] = 0x00;
for (entry_start = chunkdata; *entry_start; entry_start++) for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; entry_start++)
/* empty loop to find end of name */ ; /* empty loop to find end of name */ ;
++entry_start; ++entry_start;
/* a sample depth should follow the separator, and we should be on it */ /* a sample depth should follow the separator, and we should be on it */
if (entry_start > chunkdata + slength - 2) if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "malformed sPLT chunk"); png_warning(png_ptr, "malformed sPLT chunk");
return; return;
} }
new_palette.depth = *entry_start++; new_palette.depth = *entry_start++;
entry_size = (new_palette.depth == 8 ? 6 : 10); entry_size = (new_palette.depth == 8 ? 6 : 10);
data_length = (slength - (entry_start - chunkdata)); data_length = (slength - (entry_start - (png_bytep)png_ptr->chunkdata));
/* integrity-check the data length */ /* integrity-check the data length */
if (data_length % entry_size) if (data_length % entry_size)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "sPLT chunk has bad length"); png_warning(png_ptr, "sPLT chunk has bad length");
return; return;
} }
new_palette.nentries = (png_int_32) ( data_length / entry_size); new_palette.nentries = (png_int_32) ( data_length / entry_size);
if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX / if ((png_uint_32) new_palette.nentries >
png_sizeof(png_sPLT_entry))) (png_uint_32) (PNG_SIZE_MAX / png_sizeof(png_sPLT_entry)))
{ {
png_warning(png_ptr, "sPLT chunk too long"); png_warning(png_ptr, "sPLT chunk too long");
return; return;
@@ -1227,11 +1259,12 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif #endif
/* discard all chunk data except the name and stash that */ /* discard all chunk data except the name and stash that */
new_palette.name = (png_charp)chunkdata; new_palette.name = png_ptr->chunkdata;
png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_free(png_ptr, new_palette.entries); png_free(png_ptr, new_palette.entries);
} }
#endif /* PNG_READ_sPLT_SUPPORTED */ #endif /* PNG_READ_sPLT_SUPPORTED */
@@ -1241,15 +1274,9 @@ void /* PRIVATE */
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
int bit_mask;
png_debug(1, "in png_handle_tRNS\n"); png_debug(1, "in png_handle_tRNS\n");
/* For non-indexed color, mask off any bits in the tRNS value that
* exceed the bit depth. Some creators were writing extra bits there.
* This is not needed for indexed color. */
bit_mask = (1 << png_ptr->bit_depth) - 1;
if (!(png_ptr->mode & PNG_HAVE_IHDR)) if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before tRNS"); png_error(png_ptr, "Missing IHDR before tRNS");
else if (png_ptr->mode & PNG_HAVE_IDAT) else if (png_ptr->mode & PNG_HAVE_IDAT)
@@ -1278,7 +1305,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 2); png_crc_read(png_ptr, buf, 2);
png_ptr->num_trans = 1; png_ptr->num_trans = 1;
png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask; png_ptr->trans_values.gray = png_get_uint_16(buf);
} }
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
{ {
@@ -1292,9 +1319,9 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
png_crc_read(png_ptr, buf, (png_size_t)length); png_crc_read(png_ptr, buf, (png_size_t)length);
png_ptr->num_trans = 1; png_ptr->num_trans = 1;
png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask; png_ptr->trans_values.red = png_get_uint_16(buf);
png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask; png_ptr->trans_values.green = png_get_uint_16(buf + 2);
png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask; png_ptr->trans_values.blue = png_get_uint_16(buf + 4);
} }
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
@@ -1571,7 +1598,6 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void /* PRIVATE */ void /* PRIVATE */
png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_charp purpose;
png_int_32 X0, X1; png_int_32 X0, X1;
png_byte type, nparams; png_byte type, nparams;
png_charp buf, units, endptr; png_charp buf, units, endptr;
@@ -1598,35 +1624,38 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n", png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
length + 1); length + 1);
purpose = (png_charp)png_malloc_warn(png_ptr, length + 1); png_free(png_ptr, png_ptr->chunkdata);
if (purpose == NULL) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (png_ptr->chunkdata == NULL)
{ {
png_warning(png_ptr, "No memory for pCAL purpose."); png_warning(png_ptr, "No memory for pCAL purpose.");
return; return;
} }
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)purpose, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, 0)) if (png_crc_finish(png_ptr, 0))
{ {
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
purpose[slength] = 0x00; /* null terminate the last string */ png_ptr->chunkdata[slength] = 0x00; /* null terminate the last string */
png_debug(3, "Finding end of pCAL purpose string\n"); png_debug(3, "Finding end of pCAL purpose string\n");
for (buf = purpose; *buf; buf++) for (buf = png_ptr->chunkdata; *buf; buf++)
/* empty loop */ ; /* empty loop */ ;
endptr = purpose + slength; endptr = png_ptr->chunkdata + slength;
/* We need to have at least 12 bytes after the purpose string /* We need to have at least 12 bytes after the purpose string
in order to get the parameter information. */ in order to get the parameter information. */
if (endptr <= buf + 12) if (endptr <= buf + 12)
{ {
png_warning(png_ptr, "Invalid pCAL data"); png_warning(png_ptr, "Invalid pCAL data");
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
@@ -1646,7 +1675,8 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
(type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
{ {
png_warning(png_ptr, "Invalid pCAL parameters for equation type"); png_warning(png_ptr, "Invalid pCAL parameters for equation type");
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
else if (type >= PNG_EQUATION_LAST) else if (type >= PNG_EQUATION_LAST)
@@ -1658,11 +1688,12 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Empty loop to move past the units string. */ ; /* Empty loop to move past the units string. */ ;
png_debug(3, "Allocating pCAL parameters array\n"); png_debug(3, "Allocating pCAL parameters array\n");
params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams params = (png_charpp)png_malloc_warn(png_ptr,
*png_sizeof(png_charp))) ; (png_uint_32)(nparams * png_sizeof(png_charp))) ;
if (params == NULL) if (params == NULL)
{ {
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_warning(png_ptr, "No memory for pCAL params."); png_warning(png_ptr, "No memory for pCAL params.");
return; return;
} }
@@ -1680,16 +1711,18 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (buf > endptr) if (buf > endptr)
{ {
png_warning(png_ptr, "Invalid pCAL data"); png_warning(png_ptr, "Invalid pCAL data");
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_free(png_ptr, params); png_free(png_ptr, params);
return; return;
} }
} }
png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams, png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
units, params); units, params);
png_free(png_ptr, purpose); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_free(png_ptr, params); png_free(png_ptr, params);
} }
#endif #endif
@@ -1699,7 +1732,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void /* PRIVATE */ void /* PRIVATE */
png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_charp buffer, ep; png_charp ep;
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
double width, height; double width, height;
png_charp vp; png_charp vp;
@@ -1729,24 +1762,25 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n", png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
length + 1); length + 1);
buffer = (png_charp)png_malloc_warn(png_ptr, length + 1); png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (buffer == NULL) if (png_ptr->chunkdata == NULL)
{ {
png_warning(png_ptr, "Out of memory while processing sCAL chunk"); png_warning(png_ptr, "Out of memory while processing sCAL chunk");
return; return;
} }
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)buffer, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, 0)) if (png_crc_finish(png_ptr, 0))
{ {
png_free(png_ptr, buffer); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
buffer[slength] = 0x00; /* null terminate the last string */ png_ptr->chunkdata[slength] = 0x00; /* null terminate the last string */
ep = buffer + 1; /* skip unit byte */ ep = png_ptr->chunkdata + 1; /* skip unit byte */
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
width = png_strtod(png_ptr, ep, &vp); width = png_strtod(png_ptr, ep, &vp);
@@ -1767,18 +1801,19 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif #endif
#endif #endif
for (ep = buffer; *ep; ep++) for (ep = png_ptr->chunkdata; *ep; ep++)
/* empty loop */ ; /* empty loop */ ;
ep++; ep++;
if (buffer + slength < ep) if (png_ptr->chunkdata + slength < ep)
{ {
png_warning(png_ptr, "Truncated sCAL chunk"); png_warning(png_ptr, "Truncated sCAL chunk");
#if defined(PNG_FIXED_POINT_SUPPORTED) && \ #if defined(PNG_FIXED_POINT_SUPPORTED) && \
!defined(PNG_FLOATING_POINT_SUPPORTED) !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, swidth); png_free(png_ptr, swidth);
#endif #endif
png_free(png_ptr, buffer); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
@@ -1801,14 +1836,15 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif #endif
#endif #endif
if (buffer + slength < ep if (png_ptr->chunkdata + slength < ep
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
|| width <= 0. || height <= 0. || width <= 0. || height <= 0.
#endif #endif
) )
{ {
png_warning(png_ptr, "Invalid sCAL data"); png_warning(png_ptr, "Invalid sCAL data");
png_free(png_ptr, buffer); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, swidth); png_free(png_ptr, swidth);
png_free(png_ptr, sheight); png_free(png_ptr, sheight);
@@ -1818,14 +1854,15 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height); png_set_sCAL(png_ptr, info_ptr, png_ptr->chunkdata[0], width, height);
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight); png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], swidth, sheight);
#endif #endif
#endif #endif
png_free(png_ptr, buffer); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, swidth); png_free(png_ptr, swidth);
png_free(png_ptr, sheight); png_free(png_ptr, sheight);
@@ -1961,7 +1998,6 @@ void /* PRIVATE */
png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_textp text_ptr; png_textp text_ptr;
png_charp chunkdata;
png_charp text; png_charp text;
int comp_type; int comp_type;
int ret; int ret;
@@ -1985,30 +2021,33 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); png_free(png_ptr,png_ptr->chunkdata);
if (chunkdata == NULL) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (png_ptr->chunkdata == NULL)
{ {
png_warning(png_ptr, "Out of memory processing zTXt chunk."); png_warning(png_ptr, "Out of memory processing zTXt chunk.");
return; return;
} }
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, 0)) if (png_crc_finish(png_ptr, 0))
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
chunkdata[slength] = 0x00; png_ptr->chunkdata[slength] = 0x00;
for (text = chunkdata; *text; text++) for (text = png_ptr->chunkdata; *text; text++)
/* empty loop */ ; /* empty loop */ ;
/* zTXt must have some text after the chunkdataword */ /* zTXt must have some text after the chunkdataword */
if (text >= chunkdata + slength - 2) if (text >= png_ptr->chunkdata + slength - 2)
{ {
png_warning(png_ptr, "Truncated zTXt chunk"); png_warning(png_ptr, "Truncated zTXt chunk");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
else else
@@ -2021,9 +2060,9 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
text++; /* skip the compression_method byte */ text++; /* skip the compression_method byte */
} }
prefix_len = text - chunkdata; prefix_len = text - png_ptr->chunkdata;
chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata, png_decompress_chunk(png_ptr, comp_type,
(png_size_t)length, prefix_len, &data_len); (png_size_t)length, prefix_len, &data_len);
text_ptr = (png_textp)png_malloc_warn(png_ptr, text_ptr = (png_textp)png_malloc_warn(png_ptr,
@@ -2031,23 +2070,25 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text_ptr == NULL) if (text_ptr == NULL)
{ {
png_warning(png_ptr, "Not enough memory to process zTXt chunk."); png_warning(png_ptr, "Not enough memory to process zTXt chunk.");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
text_ptr->compression = comp_type; text_ptr->compression = comp_type;
text_ptr->key = chunkdata; text_ptr->key = png_ptr->chunkdata;
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED
text_ptr->lang = NULL; text_ptr->lang = NULL;
text_ptr->lang_key = NULL; text_ptr->lang_key = NULL;
text_ptr->itxt_length = 0; text_ptr->itxt_length = 0;
#endif #endif
text_ptr->text = chunkdata + prefix_len; text_ptr->text = png_ptr->chunkdata + prefix_len;
text_ptr->text_length = data_len; text_ptr->text_length = data_len;
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr); png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
if (ret) if (ret)
png_error(png_ptr, "Insufficient memory to store zTXt chunk."); png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
} }
@@ -2059,7 +2100,6 @@ void /* PRIVATE */
png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{ {
png_textp text_ptr; png_textp text_ptr;
png_charp chunkdata;
png_charp key, lang, text, lang_key; png_charp key, lang, text, lang_key;
int comp_flag; int comp_flag;
int comp_type = 0; int comp_type = 0;
@@ -2085,23 +2125,25 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#endif #endif
chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); png_free(png_ptr, png_ptr->chunkdata);
if (chunkdata == NULL) png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (png_ptr->chunkdata == NULL)
{ {
png_warning(png_ptr, "No memory to process iTXt chunk."); png_warning(png_ptr, "No memory to process iTXt chunk.");
return; return;
} }
slength = (png_size_t)length; slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength); png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
if (png_crc_finish(png_ptr, 0)) if (png_crc_finish(png_ptr, 0))
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
chunkdata[slength] = 0x00; png_ptr->chunkdata[slength] = 0x00;
for (lang = chunkdata; *lang; lang++) for (lang = png_ptr->chunkdata; *lang; lang++)
/* empty loop */ ; /* empty loop */ ;
lang++; /* skip NUL separator */ lang++; /* skip NUL separator */
@@ -2109,10 +2151,11 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
translated keyword (possibly empty), and possibly some text after the translated keyword (possibly empty), and possibly some text after the
keyword */ keyword */
if (lang >= chunkdata + slength - 3) if (lang >= png_ptr->chunkdata + slength - 3)
{ {
png_warning(png_ptr, "Truncated iTXt chunk"); png_warning(png_ptr, "Truncated iTXt chunk");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
else else
@@ -2125,51 +2168,55 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* empty loop */ ; /* empty loop */ ;
lang_key++; /* skip NUL separator */ lang_key++; /* skip NUL separator */
if (lang_key >= chunkdata + slength) if (lang_key >= png_ptr->chunkdata + slength)
{ {
png_warning(png_ptr, "Truncated iTXt chunk"); png_warning(png_ptr, "Truncated iTXt chunk");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
for (text = lang_key; *text; text++) for (text = lang_key; *text; text++)
/* empty loop */ ; /* empty loop */ ;
text++; /* skip NUL separator */ text++; /* skip NUL separator */
if (text >= chunkdata + slength) if (text >= png_ptr->chunkdata + slength)
{ {
png_warning(png_ptr, "Malformed iTXt chunk"); png_warning(png_ptr, "Malformed iTXt chunk");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
prefix_len = text - chunkdata; prefix_len = text - png_ptr->chunkdata;
key=chunkdata; key=png_ptr->chunkdata;
if (comp_flag) if (comp_flag)
chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata, png_decompress_chunk(png_ptr, comp_type,
(size_t)length, prefix_len, &data_len); (size_t)length, prefix_len, &data_len);
else else
data_len=png_strlen(chunkdata + prefix_len); data_len = png_strlen(png_ptr->chunkdata + prefix_len);
text_ptr = (png_textp)png_malloc_warn(png_ptr, text_ptr = (png_textp)png_malloc_warn(png_ptr,
(png_uint_32)png_sizeof(png_text)); (png_uint_32)png_sizeof(png_text));
if (text_ptr == NULL) if (text_ptr == NULL)
{ {
png_warning(png_ptr, "Not enough memory to process iTXt chunk."); png_warning(png_ptr, "Not enough memory to process iTXt chunk.");
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
return; return;
} }
text_ptr->compression = (int)comp_flag + 1; text_ptr->compression = (int)comp_flag + 1;
text_ptr->lang_key = chunkdata+(lang_key-key); text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
text_ptr->lang = chunkdata+(lang-key); text_ptr->lang = png_ptr->chunkdata + (lang - key);
text_ptr->itxt_length = data_len; text_ptr->itxt_length = data_len;
text_ptr->text_length = 0; text_ptr->text_length = 0;
text_ptr->key = chunkdata; text_ptr->key = png_ptr->chunkdata;
text_ptr->text = chunkdata + prefix_len; text_ptr->text = png_ptr->chunkdata + prefix_len;
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr); png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
if (ret) if (ret)
png_error(png_ptr, "Insufficient memory to store iTXt chunk."); png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
} }
@@ -2196,8 +2243,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->mode |= PNG_AFTER_IDAT;
} }
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
{ {
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
@@ -2227,9 +2272,14 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
(png_charp)png_ptr->chunk_name, (png_charp)png_ptr->chunk_name,
png_sizeof(png_ptr->unknown_chunk.name)); png_sizeof(png_ptr->unknown_chunk.name));
png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0'; png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0';
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_ptr->unknown_chunk.size = (png_size_t)length; png_ptr->unknown_chunk.size = (png_size_t)length;
if (length == 0)
png_ptr->unknown_chunk.data = NULL;
else
{
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
}
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if (png_ptr->read_user_chunk_fn != NULL) if (png_ptr->read_user_chunk_fn != NULL)
{ {
@@ -3001,7 +3051,7 @@ png_read_start_row(png_structp png_ptr)
#endif #endif
int max_pixel_depth; int max_pixel_depth;
png_uint_32 row_bytes; png_size_t row_bytes;
png_debug(1, "in png_read_start_row\n"); png_debug(1, "in png_read_start_row\n");
png_ptr->zstream.avail_in = 0; png_ptr->zstream.avail_in = 0;
@@ -3020,11 +3070,8 @@ png_read_start_row(png_structp png_ptr)
png_pass_start[png_ptr->pass]) / png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass]; png_pass_inc[png_ptr->pass];
row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1; png_ptr->irowbytes =
PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1;
png_ptr->irowbytes = (png_size_t)row_bytes;
if((png_uint_32)png_ptr->irowbytes != row_bytes)
png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
} }
else else
#endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_READ_INTERLACING_SUPPORTED */
@@ -3149,7 +3196,6 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (row_bytes + 64 > png_ptr->old_big_row_buf_size) if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
{ {
if (png_ptr->big_row_buf)
png_free(png_ptr, png_ptr->big_row_buf); png_free(png_ptr, png_ptr->big_row_buf);
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64); png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
png_ptr->row_buf = png_ptr->big_row_buf+32; png_ptr->row_buf = png_ptr->big_row_buf+32;
@@ -3165,7 +3211,6 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (png_ptr->rowbytes+1 > png_ptr->old_prev_row_size) if (png_ptr->rowbytes+1 > png_ptr->old_prev_row_size)
{ {
if (png_ptr->prev_row)
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
png_ptr->rowbytes + 1)); png_ptr->rowbytes + 1));
+74 -34
View File
@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* Last changed in libpng 1.2.25 [February 18, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -15,7 +15,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED) #if defined(PNG_bKGD_SUPPORTED)
@@ -396,7 +395,8 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
return; return;
length = png_strlen(purpose) + 1; length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%lu bytes)\n", length); png_debug1(3, "allocating purpose for info (%lu bytes)\n",
(unsigned long)length);
info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_purpose == NULL) if (info_ptr->pcal_purpose == NULL)
{ {
@@ -412,7 +412,8 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
info_ptr->pcal_nparams = (png_byte)nparams; info_ptr->pcal_nparams = (png_byte)nparams;
length = png_strlen(units) + 1; length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)\n", length); png_debug1(3, "allocating units for info (%lu bytes)\n",
(unsigned long)length);
info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_units == NULL) if (info_ptr->pcal_units == NULL)
{ {
@@ -434,7 +435,8 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
{ {
length = png_strlen(params[i]) + 1; length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length); png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i,
(unsigned long)length);
info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_params[i] == NULL) if (info_ptr->pcal_params[i] == NULL)
{ {
@@ -482,7 +484,8 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
info_ptr->scal_unit = (png_byte)unit; info_ptr->scal_unit = (png_byte)unit;
length = png_strlen(swidth) + 1; length = png_strlen(swidth) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length); png_debug1(3, "allocating unit for info (%u bytes)\n",
(unsigned int)length);
info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->scal_s_width == NULL) if (info_ptr->scal_s_width == NULL)
{ {
@@ -493,11 +496,13 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
length = png_strlen(sheight) + 1; length = png_strlen(sheight) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length); png_debug1(3, "allocating unit for info (%u bytes)\n",
(unsigned int)length);
info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->scal_s_height == NULL) if (info_ptr->scal_s_height == NULL)
{ {
png_free (png_ptr, info_ptr->scal_s_width); png_free (png_ptr, info_ptr->scal_s_width);
info_ptr->scal_s_width = NULL;
png_warning(png_ptr, png_warning(png_ptr,
"Memory allocation failed while processing sCAL."); "Memory allocation failed while processing sCAL.");
return; return;
@@ -700,7 +705,8 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
if (new_iccp_profile == NULL) if (new_iccp_profile == NULL)
{ {
png_free (png_ptr, new_iccp_name); png_free (png_ptr, new_iccp_name);
png_warning(png_ptr, "Insufficient memory to process iCCP profile."); png_warning(png_ptr,
"Insufficient memory to process iCCP profile.");
return; return;
} }
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
@@ -835,11 +841,13 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
} }
textp->key = (png_charp)png_malloc_warn(png_ptr, textp->key = (png_charp)png_malloc_warn(png_ptr,
(png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4)); (png_uint_32)
(key_len + text_length + lang_len + lang_key_len + 4));
if (textp->key == NULL) if (textp->key == NULL)
return(1); return(1);
png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n", png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
(png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4), (png_uint_32)
(key_len + lang_len + lang_key_len + text_length + 4),
(int)textp->key); (int)textp->key);
png_memcpy(textp->key, text_ptr[i].key, png_memcpy(textp->key, text_ptr[i].key,
@@ -921,30 +929,45 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
* we do it for backward compatibility with the way the png_handle_tRNS * we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation. * function used to do the allocation.
*/ */
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif #endif
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
(png_uint_32)PNG_MAX_PALETTE_LENGTH); (png_uint_32)PNG_MAX_PALETTE_LENGTH);
if (num_trans <= PNG_MAX_PALETTE_LENGTH) if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
}
if (trans_values != NULL)
{
int sample_max = (1 << info_ptr->bit_depth);
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
(int)trans_values->gray > sample_max) ||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
((int)trans_values->red > sample_max ||
(int)trans_values->green > sample_max ||
(int)trans_values->blue > sample_max)))
png_warning(png_ptr,
"tRNS chunk has out-of-range samples for bit_depth");
png_memcpy(&(info_ptr->trans_values), trans_values,
png_sizeof(png_color_16));
if (num_trans == 0)
num_trans = 1;
}
info_ptr->num_trans = (png_uint_16)num_trans;
if (num_trans != 0)
{
info_ptr->valid |= PNG_INFO_tRNS;
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS; info_ptr->free_me |= PNG_FREE_TRNS;
#else #else
png_ptr->flags |= PNG_FLAG_FREE_TRNS; png_ptr->flags |= PNG_FLAG_FREE_TRNS;
#endif #endif
} }
if (trans_values != NULL)
{
png_memcpy(&(info_ptr->trans_values), trans_values,
png_sizeof(png_color_16));
if (num_trans == 0)
num_trans = 1;
}
info_ptr->num_trans = (png_uint_16)num_trans;
info_ptr->valid |= PNG_INFO_tRNS;
} }
#endif #endif
@@ -952,6 +975,13 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
void PNGAPI void PNGAPI
png_set_sPLT(png_structp png_ptr, png_set_sPLT(png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries) png_infop info_ptr, png_sPLT_tp entries, int nentries)
/*
* entries - array of png_sPLT_t structures
* to be added to the list of palettes
* in the info structure.
* nentries - number of palette structures to be
* added.
*/
{ {
png_sPLT_tp np; png_sPLT_tp np;
int i; int i;
@@ -960,7 +990,8 @@ png_set_sPLT(png_structp png_ptr,
return; return;
np = (png_sPLT_tp)png_malloc_warn(png_ptr, np = (png_sPLT_tp)png_malloc_warn(png_ptr,
(info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t)); (info_ptr->splt_palettes_num + nentries) *
(png_uint_32)png_sizeof(png_sPLT_t));
if (np == NULL) if (np == NULL)
{ {
png_warning(png_ptr, "No memory for sPLT palettes."); png_warning(png_ptr, "No memory for sPLT palettes.");
@@ -988,7 +1019,7 @@ png_set_sPLT(png_structp png_ptr,
} }
png_memcpy(to->name, from->name, length); png_memcpy(to->name, from->name, length);
to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
from->nentries * png_sizeof(png_sPLT_entry)); (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
if (to->entries == NULL) if (to->entries == NULL)
{ {
png_warning(png_ptr, png_warning(png_ptr,
@@ -1024,8 +1055,8 @@ png_set_unknown_chunks(png_structp png_ptr,
return; return;
np = (png_unknown_chunkp)png_malloc_warn(png_ptr, np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
(info_ptr->unknown_chunks_num + num_unknowns) * (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
png_sizeof(png_unknown_chunk)); png_sizeof(png_unknown_chunk)));
if (np == NULL) if (np == NULL)
{ {
png_warning(png_ptr, png_warning(png_ptr,
@@ -1047,20 +1078,24 @@ png_set_unknown_chunks(png_structp png_ptr,
(png_charp)from->name, (png_charp)from->name,
png_sizeof(from->name)); png_sizeof(from->name));
to->name[png_sizeof(to->name)-1] = '\0'; to->name[png_sizeof(to->name)-1] = '\0';
to->size = from->size;
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
to->data = (png_bytep)png_malloc_warn(png_ptr, from->size); if (from->size == 0)
to->data=NULL;
else
{
to->data = (png_bytep)png_malloc_warn(png_ptr,
(png_uint_32)from->size);
if (to->data == NULL) if (to->data == NULL)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Out of memory while processing unknown chunk."); "Out of memory while processing unknown chunk.");
to->size = 0;
} }
else else
{
png_memcpy(to->data, from->data, from->size); png_memcpy(to->data, from->data, from->size);
to->size = from->size;
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
} }
} }
@@ -1137,7 +1172,8 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
return; return;
old_num_chunks = png_ptr->num_chunk_list; old_num_chunks = png_ptr->num_chunk_list;
new_list=(png_bytep)png_malloc(png_ptr, new_list=(png_bytep)png_malloc(png_ptr,
(png_uint_32)(5*(num_chunks+old_num_chunks))); (png_uint_32)
(5*(num_chunks + old_num_chunks)));
if (png_ptr->chunk_list != NULL) if (png_ptr->chunk_list != NULL)
{ {
png_memcpy(new_list, png_ptr->chunk_list, png_memcpy(new_list, png_ptr->chunk_list,
@@ -1189,11 +1225,11 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
void PNGAPI void PNGAPI
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size) png_set_compression_buffer_size(png_structp png_ptr,
png_uint_32 size)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
if(png_ptr->zbuf)
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size; png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
@@ -1219,6 +1255,7 @@ png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
if (png_ptr != NULL) if (png_ptr != NULL)
png_ptr->asm_flags = 0; png_ptr->asm_flags = 0;
asm_flags = asm_flags; /* Quiet the compiler */
} }
/* this function was added to libpng 1.2.0 */ /* this function was added to libpng 1.2.0 */
@@ -1230,6 +1267,9 @@ png_set_mmx_thresholds (png_structp png_ptr,
/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
/* Quiet the compiler */
mmx_bitdepth_threshold = mmx_bitdepth_threshold;
mmx_rowbytes_threshold = mmx_rowbytes_threshold;
} }
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
+4 -4
View File
@@ -1,17 +1,17 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* Last changed in libpng 1.2.17 May 15, 2007 * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on BGR-to-RGB mapping */ /* turn on BGR-to-RGB mapping */
void PNGAPI void PNGAPI
@@ -652,8 +652,8 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp
png_voidp PNGAPI png_voidp PNGAPI
png_get_user_transform_ptr(png_structp png_ptr) png_get_user_transform_ptr(png_structp png_ptr)
{ {
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (png_ptr == NULL) return (NULL); if (png_ptr == NULL) return (NULL);
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
return ((png_voidp)png_ptr->user_transform_ptr); return ((png_voidp)png_ptr->user_transform_ptr);
#else #else
return (NULL); return (NULL);
+2 -2
View File
@@ -1,9 +1,9 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* Last changed in libpng 1.2.13 November 13, 2006 * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2006 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
+14 -2
View File
@@ -1,7 +1,7 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* Last changed in libpng 1.2.25 [February 18, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -112,6 +112,8 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{ {
if (up->size == 0)
png_warning(png_ptr, "Writing zero-length unknown chunk");
png_write_chunk(png_ptr, up->name, up->data, up->size); png_write_chunk(png_ptr, up->name, up->data, up->size);
} }
} }
@@ -391,6 +393,13 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
/* write end of PNG file */ /* write end of PNG file */
png_write_IEND(png_ptr); png_write_IEND(png_ptr);
/* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
* and restored again in libpng-1.2.30, may cause some applications that
* do not set png_ptr->output_flush_fn to crash. If your application
* experiences this problem, please report the event to
* png-mng-implement at lists.sf.net .
*/
png_flush(png_ptr);
} }
#if defined(PNG_WRITE_tIME_SUPPORTED) #if defined(PNG_WRITE_tIME_SUPPORTED)
@@ -437,6 +446,9 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn) png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_SETJMP_SUPPORTED
volatile
#endif
png_structp png_ptr; png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
@@ -1074,7 +1086,7 @@ png_write_destroy(png_structp png_ptr)
/* free our memory. png_free checks NULL for us. */ /* free our memory. png_free checks NULL for us. */
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf); png_free(png_ptr, png_ptr->row_buf);
#ifndef PNG_NO_WRITE_FILTERING #ifndef PNG_NO_WRITE_FILTER
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->sub_row); png_free(png_ptr, png_ptr->sub_row);
png_free(png_ptr, png_ptr->up_row); png_free(png_ptr, png_ptr->up_row);
+118 -94
View File
@@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file /* pngwutil.c - utilities to write a PNG file
* *
* Last changed in libpng 1.2.26 [April 2, 2008] * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -49,6 +49,24 @@ png_save_uint_16(png_bytep buf, unsigned int i)
buf[1] = (png_byte)(i & 0xff); buf[1] = (png_byte)(i & 0xff);
} }
/* Simple function to write the signature. If we have already written
* the magic bytes of the signature, or more likely, the PNG stream is
* being embedded into another stream and doesn't need its own signature,
* we should call png_set_sig_bytes() to tell libpng how many of the
* bytes have already been written.
*/
void /* PRIVATE */
png_write_sig(png_structp png_ptr)
{
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* write the rest of the 8 byte signature */
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
(png_size_t)(8 - png_ptr->sig_bytes));
if (png_ptr->sig_bytes < 3)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
}
/* Write a PNG chunk all at once. The type is an array of ASCII characters /* Write a PNG chunk all at once. The type is an array of ASCII characters
* representing the chunk name. The array must be at least 4 bytes in * representing the chunk name. The array must be at least 4 bytes in
* length, and does not need to be null terminated. To be safe, pass the * length, and does not need to be null terminated. To be safe, pass the
@@ -64,7 +82,7 @@ png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
{ {
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
png_write_chunk_data(png_ptr, data, length); png_write_chunk_data(png_ptr, data, (png_size_t)length);
png_write_chunk_end(png_ptr); png_write_chunk_end(png_ptr);
} }
@@ -76,16 +94,18 @@ void PNGAPI
png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
png_uint_32 length) png_uint_32 length)
{ {
png_byte buf[4]; png_byte buf[8];
png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
png_debug2(0, "Writing %s chunk, length = %lu\n", chunk_name,
(unsigned long)length);
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
/* write the length */ /* write the length and the chunk name */
png_save_uint_32(buf, length); png_save_uint_32(buf, length);
png_write_data(png_ptr, buf, (png_size_t)4); png_memcpy(buf + 4, chunk_name, 4);
png_write_data(png_ptr, buf, (png_size_t)8);
/* write the chunk name */ /* put the chunk name into png_ptr->chunk_name */
png_write_data(png_ptr, chunk_name, (png_size_t)4); png_memcpy(png_ptr->chunk_name, chunk_name, 4);
/* reset the crc and run it over the chunk name */ /* reset the crc and run it over the chunk name */
png_reset_crc(png_ptr); png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
@@ -103,8 +123,11 @@ png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
if (data != NULL && length > 0) if (data != NULL && length > 0)
{ {
png_calculate_crc(png_ptr, data, length);
png_write_data(png_ptr, data, length); png_write_data(png_ptr, data, length);
/* update the CRC after writing the data,
* in case that the user I/O routine alters it.
*/
png_calculate_crc(png_ptr, data, length);
} }
} }
@@ -116,29 +139,12 @@ png_write_chunk_end(png_structp png_ptr)
if (png_ptr == NULL) return; if (png_ptr == NULL) return;
/* write the crc */ /* write the crc in a single operation */
png_save_uint_32(buf, png_ptr->crc); png_save_uint_32(buf, png_ptr->crc);
png_write_data(png_ptr, buf, (png_size_t)4); png_write_data(png_ptr, buf, (png_size_t)4);
} }
/* Simple function to write the signature. If we have already written
* the magic bytes of the signature, or more likely, the PNG stream is
* being embedded into another stream and doesn't need its own signature,
* we should call png_set_sig_bytes() to tell libpng how many of the
* bytes have already been written.
*/
void /* PRIVATE */
png_write_sig(png_structp png_ptr)
{
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* write the rest of the 8 byte signature */
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
(png_size_t)8 - png_ptr->sig_bytes);
if(png_ptr->sig_bytes < 3)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
}
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
/* /*
* This pair of functions encapsulates the operation of (a) compressing a * This pair of functions encapsulates the operation of (a) compressing a
@@ -239,20 +245,21 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr; old_ptr = comp->output_ptr;
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_uint_32)(comp->max_output_ptr * (png_uint_32)
png_sizeof (png_charpp))); (comp->max_output_ptr * png_sizeof(png_charpp)));
png_memcpy(comp->output_ptr, old_ptr, old_max png_memcpy(comp->output_ptr, old_ptr, old_max
* png_sizeof(png_charp)); * png_sizeof(png_charp));
png_free(png_ptr, old_ptr); png_free(png_ptr, old_ptr);
} }
else else
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_uint_32)(comp->max_output_ptr * (png_uint_32)
png_sizeof (png_charp))); (comp->max_output_ptr * png_sizeof(png_charp)));
} }
/* save the data */ /* save the data */
comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, comp->output_ptr[comp->num_output_ptr] =
(png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size); (png_uint_32)png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size); png_ptr->zbuf_size);
@@ -291,7 +298,7 @@ png_text_compress(png_structp png_ptr,
/* This could be optimized to realloc() */ /* This could be optimized to realloc() */
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_uint_32)(comp->max_output_ptr * (png_uint_32)(comp->max_output_ptr *
png_sizeof (png_charpp))); png_sizeof(png_charp)));
png_memcpy(comp->output_ptr, old_ptr, png_memcpy(comp->output_ptr, old_ptr,
old_max * png_sizeof(png_charp)); old_max * png_sizeof(png_charp));
png_free(png_ptr, old_ptr); png_free(png_ptr, old_ptr);
@@ -304,7 +311,8 @@ png_text_compress(png_structp png_ptr,
/* save off the data */ /* save off the data */
comp->output_ptr[comp->num_output_ptr] = comp->output_ptr[comp->num_output_ptr] =
(png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size); (png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size); png_ptr->zbuf_size);
comp->num_output_ptr++; comp->num_output_ptr++;
@@ -350,7 +358,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
for (i = 0; i < comp->num_output_ptr; i++) for (i = 0; i < comp->num_output_ptr; i++)
{ {
png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
png_ptr->zbuf_size); (png_size_t)png_ptr->zbuf_size);
png_free(png_ptr, comp->output_ptr[i]); png_free(png_ptr, comp->output_ptr[i]);
comp->output_ptr[i]=NULL; comp->output_ptr[i]=NULL;
} }
@@ -360,7 +368,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* write anything left in zbuf */ /* write anything left in zbuf */
if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
png_write_chunk_data(png_ptr, png_ptr->zbuf, png_write_chunk_data(png_ptr, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out); (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
/* reset zlib for another zTXt/iTXt or image data */ /* reset zlib for another zTXt/iTXt or image data */
deflateReset(&png_ptr->zstream); deflateReset(&png_ptr->zstream);
@@ -496,7 +504,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
buf[12] = (png_byte)interlace_type; buf[12] = (png_byte)interlace_type;
/* write the chunk */ /* write the chunk */
png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
/* initialize zlib with PNG info */ /* initialize zlib with PNG info */
png_ptr->zstream.zalloc = png_zalloc; png_ptr->zstream.zalloc = png_zalloc;
@@ -589,7 +597,8 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_ptr->num_palette = (png_uint_16)num_pal; png_ptr->num_palette = (png_uint_16)num_pal;
png_debug1(3, "num_palette = %d\n", png_ptr->num_palette); png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3); png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
(png_uint_32)(num_pal * 3));
#ifndef PNG_NO_POINTER_INDEXING #ifndef PNG_NO_POINTER_INDEXING
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
{ {
@@ -661,7 +670,7 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
"Invalid zlib compression method or flags in IDAT"); "Invalid zlib compression method or flags in IDAT");
} }
png_write_chunk(png_ptr, png_IDAT, data, length); png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->mode |= PNG_HAVE_IDAT;
} }
@@ -673,7 +682,7 @@ png_write_IEND(png_structp png_ptr)
PNG_IEND; PNG_IEND;
#endif #endif
png_debug(1, "in png_write_IEND\n"); png_debug(1, "in png_write_IEND\n");
png_write_chunk(png_ptr, png_IEND, png_bytep_NULL, png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
(png_size_t)0); (png_size_t)0);
png_ptr->mode |= PNG_HAVE_IEND; png_ptr->mode |= PNG_HAVE_IEND;
} }
@@ -694,7 +703,7 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
/* file_gamma is saved in 1/100,000ths */ /* file_gamma is saved in 1/100,000ths */
igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5); igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
png_save_uint_32(buf, igamma); png_save_uint_32(buf, igamma);
png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
} }
#endif #endif
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
@@ -709,7 +718,7 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
png_debug(1, "in png_write_gAMA\n"); png_debug(1, "in png_write_gAMA\n");
/* file_gamma is saved in 1/100,000ths */ /* file_gamma is saved in 1/100,000ths */
png_save_uint_32(buf, (png_uint_32)file_gamma); png_save_uint_32(buf, (png_uint_32)file_gamma);
png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
} }
#endif #endif
#endif #endif
@@ -729,7 +738,7 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
png_warning(png_ptr, png_warning(png_ptr,
"Invalid sRGB rendering intent specified"); "Invalid sRGB rendering intent specified");
buf[0]=(png_byte)srgb_intent; buf[0]=(png_byte)srgb_intent;
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
} }
#endif #endif
@@ -790,14 +799,15 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
} }
if (profile_len) if (profile_len)
profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len, profile_len = png_text_compress(png_ptr, profile,
PNG_COMPRESSION_TYPE_BASE, &comp); (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
/* make sure we include the NULL after the name and the compression type */ /* make sure we include the NULL after the name and the compression type */
png_write_chunk_start(png_ptr, png_iCCP, png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
(png_uint_32)name_len+profile_len+2); (png_uint_32)(name_len + profile_len + 2));
new_name[name_len + 1] = 0x00; new_name[name_len + 1] = 0x00;
png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2); png_write_chunk_data(png_ptr, (png_bytep)new_name,
(png_size_t)(name_len + 2));
if (profile_len) if (profile_len)
png_write_compressed_data_out(png_ptr, &comp); png_write_compressed_data_out(png_ptr, &comp);
@@ -834,10 +844,11 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
} }
/* make sure we include the NULL after the name */ /* make sure we include the NULL after the name */
png_write_chunk_start(png_ptr, png_sPLT, png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
(png_uint_32)(name_len + 2 + palette_size)); (png_uint_32)(name_len + 2 + palette_size));
png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1); png_write_chunk_data(png_ptr, (png_bytep)new_name,
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1); (png_size_t)(name_len + 1));
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
/* loop through each palette entry, writing appropriately */ /* loop through each palette entry, writing appropriately */
#ifndef PNG_NO_POINTER_INDEXING #ifndef PNG_NO_POINTER_INDEXING
@@ -881,7 +892,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
png_save_uint_16(entrybuf + 6, ep[i].alpha); png_save_uint_16(entrybuf + 6, ep[i].alpha);
png_save_uint_16(entrybuf + 8, ep[i].frequency); png_save_uint_16(entrybuf + 8, ep[i].frequency);
} }
png_write_chunk_data(png_ptr, entrybuf, entry_size); png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
} }
#endif #endif
@@ -942,7 +953,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
buf[size++] = sbit->alpha; buf[size++] = sbit->alpha;
} }
png_write_chunk(png_ptr, png_sBIT, buf, size); png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
} }
#endif #endif
@@ -1006,7 +1017,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
itemp = (png_uint_32)(blue_y * 100000.0 + 0.5); itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
png_save_uint_32(buf + 28, itemp); png_save_uint_32(buf + 28, itemp);
png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
} }
#endif #endif
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1027,7 +1038,8 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
{ {
png_warning(png_ptr, "Invalid fixed cHRM white point specified"); png_warning(png_ptr, "Invalid fixed cHRM white point specified");
#if !defined(PNG_NO_CONSOLE_IO) #if !defined(PNG_NO_CONSOLE_IO)
fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y); fprintf(stderr, "white_x=%ld, white_y=%ld\n", (unsigned long)white_x,
(unsigned long)white_y);
#endif #endif
return; return;
} }
@@ -1058,7 +1070,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_save_uint_32(buf + 24, (png_uint_32)blue_x); png_save_uint_32(buf + 24, (png_uint_32)blue_x);
png_save_uint_32(buf + 28, (png_uint_32)blue_y); png_save_uint_32(buf + 28, (png_uint_32)blue_y);
png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
} }
#endif #endif
#endif #endif
@@ -1083,7 +1095,8 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
return; return;
} }
/* write the chunk out as it is */ /* write the chunk out as it is */
png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans); png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
(png_size_t)num_trans);
} }
else if (color_type == PNG_COLOR_TYPE_GRAY) else if (color_type == PNG_COLOR_TYPE_GRAY)
{ {
@@ -1095,7 +1108,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
return; return;
} }
png_save_uint_16(buf, tran->gray); png_save_uint_16(buf, tran->gray);
png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
} }
else if (color_type == PNG_COLOR_TYPE_RGB) else if (color_type == PNG_COLOR_TYPE_RGB)
{ {
@@ -1109,7 +1122,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
"Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
return; return;
} }
png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
} }
else else
{ {
@@ -1142,7 +1155,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
return; return;
} }
buf[0] = back->index; buf[0] = back->index;
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
} }
else if (color_type & PNG_COLOR_MASK_COLOR) else if (color_type & PNG_COLOR_MASK_COLOR)
{ {
@@ -1155,7 +1168,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
"Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
return; return;
} }
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
} }
else else
{ {
@@ -1166,7 +1179,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
return; return;
} }
png_save_uint_16(buf, back->gray); png_save_uint_16(buf, back->gray);
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
} }
} }
#endif #endif
@@ -1191,7 +1204,8 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
return; return;
} }
png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); png_write_chunk_start(png_ptr, (png_bytep)png_hIST,
(png_uint_32)(num_hist * 2));
for (i = 0; i < num_hist; i++) for (i = 0; i < num_hist; i++)
{ {
png_save_uint_16(buf, hist[i]); png_save_uint_16(buf, hist[i]);
@@ -1357,16 +1371,18 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
text_len = png_strlen(text); text_len = png_strlen(text);
/* make sure we include the 0 after the key */ /* make sure we include the 0 after the key */
png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1); png_write_chunk_start(png_ptr, (png_bytep)png_tEXt,
(png_uint_32)(key_len + text_len + 1));
/* /*
* We leave it to the application to meet PNG-1.0 requirements on the * We leave it to the application to meet PNG-1.0 requirements on the
* contents of the text. PNG-1.0 through PNG-1.2 discourage the use of * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
* any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
* The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
*/ */
png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); png_write_chunk_data(png_ptr, (png_bytep)new_key,
(png_size_t)(key_len + 1));
if (text_len) if (text_len)
png_write_chunk_data(png_ptr, (png_bytep)text, text_len); png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len);
png_write_chunk_end(png_ptr); png_write_chunk_end(png_ptr);
png_free(png_ptr, new_key); png_free(png_ptr, new_key);
@@ -1398,6 +1414,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
{ {
png_warning(png_ptr, "Empty keyword in zTXt chunk"); png_warning(png_ptr, "Empty keyword in zTXt chunk");
png_free(png_ptr, new_key);
return; return;
} }
@@ -1415,10 +1432,11 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
&comp); &comp);
/* write start of chunk */ /* write start of chunk */
png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32) png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
(key_len+text_len+2)); (png_uint_32)(key_len+text_len + 2));
/* write key */ /* write key */
png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); png_write_chunk_data(png_ptr, (png_bytep)new_key,
(png_size_t)(key_len + 1));
png_free(png_ptr, new_key); png_free(png_ptr, new_key);
buf[0] = (png_byte)compression; buf[0] = (png_byte)compression;
@@ -1483,7 +1501,7 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
/* make sure we include the compression flag, the compression byte, /* make sure we include the compression flag, the compression byte,
* and the NULs after the key, lang, and lang_key parts */ * and the NULs after the key, lang, and lang_key parts */
png_write_chunk_start(png_ptr, png_iTXt, png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
(png_uint_32)( (png_uint_32)(
5 /* comp byte, comp flag, terminators for key, lang and lang_key */ 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
+ key_len + key_len
@@ -1497,7 +1515,8 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
* any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
* The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
*/ */
png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); png_write_chunk_data(png_ptr, (png_bytep)new_key,
(png_size_t)(key_len + 1));
/* set the compression flag */ /* set the compression flag */
if (compression == PNG_ITXT_COMPRESSION_NONE || \ if (compression == PNG_ITXT_COMPRESSION_NONE || \
@@ -1507,16 +1526,17 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
cbuf[0] = 1; cbuf[0] = 1;
/* set the compression method */ /* set the compression method */
cbuf[1] = 0; cbuf[1] = 0;
png_write_chunk_data(png_ptr, cbuf, 2); png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
cbuf[0] = 0; cbuf[0] = 0;
png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1); png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1); (png_size_t)(lang_len + 1));
png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
(png_size_t)(lang_key_len + 1));
png_write_compressed_data_out(png_ptr, &comp); png_write_compressed_data_out(png_ptr, &comp);
png_write_chunk_end(png_ptr); png_write_chunk_end(png_ptr);
png_free(png_ptr, new_key); png_free(png_ptr, new_key);
if (new_lang)
png_free(png_ptr, new_lang); png_free(png_ptr, new_lang);
} }
#endif #endif
@@ -1540,7 +1560,7 @@ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
png_save_int_32(buf + 4, y_offset); png_save_int_32(buf + 4, y_offset);
buf[8] = (png_byte)unit_type; buf[8] = (png_byte)unit_type;
png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
} }
#endif #endif
#if defined(PNG_WRITE_pCAL_SUPPORTED) #if defined(PNG_WRITE_pCAL_SUPPORTED)
@@ -1568,21 +1588,23 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
png_debug1(3, "pCAL units length = %d\n", (int)units_len); png_debug1(3, "pCAL units length = %d\n", (int)units_len);
total_len = purpose_len + units_len + 10; total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams params_len = (png_uint_32p)png_malloc(png_ptr,
*png_sizeof(png_uint_32))); (png_uint_32)(nparams * png_sizeof(png_uint_32)));
/* Find the length of each parameter, making sure we don't count the /* Find the length of each parameter, making sure we don't count the
null terminator for the last parameter. */ null terminator for the last parameter. */
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
{ {
params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]); png_debug2(3, "pCAL parameter %d length = %lu\n", i,
(unsigned long) params_len[i]);
total_len += (png_size_t)params_len[i]; total_len += (png_size_t)params_len[i];
} }
png_debug1(3, "pCAL total length = %d\n", (int)total_len); png_debug1(3, "pCAL total length = %d\n", (int)total_len);
png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len); png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len); png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
(png_size_t)purpose_len);
png_save_int_32(buf, X0); png_save_int_32(buf, X0);
png_save_int_32(buf + 4, X1); png_save_int_32(buf + 4, X1);
buf[8] = (png_byte)type; buf[8] = (png_byte)type;
@@ -1641,7 +1663,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
#endif #endif
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len); png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
} }
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1671,7 +1693,7 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */ png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
png_write_chunk(png_ptr, png_sCAL, buf, total_len); png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
} }
#endif #endif
#endif #endif
@@ -1697,7 +1719,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
png_save_uint_32(buf + 4, y_pixels_per_unit); png_save_uint_32(buf + 4, y_pixels_per_unit);
buf[8] = (png_byte)unit_type; buf[8] = (png_byte)unit_type;
png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
} }
#endif #endif
@@ -1729,7 +1751,7 @@ png_write_tIME(png_structp png_ptr, png_timep mod_time)
buf[5] = mod_time->minute; buf[5] = mod_time->minute;
buf[6] = mod_time->second; buf[6] = mod_time->second;
png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7); png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
} }
#endif #endif
@@ -1762,15 +1784,16 @@ png_write_start_row(png_structp png_ptr)
png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
/* set up row buffer */ /* set up row buffer */
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
#ifndef PNG_NO_WRITE_FILTERING #ifndef PNG_NO_WRITE_FILTER
/* set up filtering buffer, if using this filter */ /* set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB) if (png_ptr->do_filter & PNG_FILTER_SUB)
{ {
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1)); (png_uint_32)(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
} }
@@ -1778,31 +1801,32 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{ {
/* set up previous row buffer */ /* set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
(png_uint_32)buf_size);
png_memset(png_ptr->prev_row, 0, buf_size); png_memset(png_ptr->prev_row, 0, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP) if (png_ptr->do_filter & PNG_FILTER_UP)
{ {
png_ptr->up_row = (png_bytep)png_malloc(png_ptr, png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1)); (png_uint_32)(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
} }
if (png_ptr->do_filter & PNG_FILTER_AVG) if (png_ptr->do_filter & PNG_FILTER_AVG)
{ {
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1)); (png_uint_32)(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
} }
if (png_ptr->do_filter & PNG_FILTER_PAETH) if (png_ptr->do_filter & PNG_FILTER_PAETH)
{ {
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1)); (png_uint_32)(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
} }
#endif /* PNG_NO_WRITE_FILTERING */
} }
#endif /* PNG_NO_WRITE_FILTER */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED #ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* if interlaced, we need to set up width and height of pass */ /* if interlaced, we need to set up width and height of pass */