mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng17] Check (png_uint_16) casts for overflow. Also removed png_muldiv_warn,
added RELEASE/!RELEASE convenience macros. png_muldiv_warn was used in only one place, and the overflow condition is a genuine warning not an internal error. Four macros allow code or function parameters to be condition on RELEASE (or not) builds and tidy up the #ifdef handling of functions.
This commit is contained in:
parent
36562c1032
commit
53097f5bbb
10
ANNOUNCE
10
ANNOUNCE
@ -1,5 +1,5 @@
|
||||
|
||||
Libpng 1.7.0beta58 - March 22, 2015
|
||||
Libpng 1.7.0beta58 - March 23, 2015
|
||||
|
||||
This is not intended to be a public release. It will be replaced
|
||||
within a few weeks by a public version or by another test version.
|
||||
@ -757,7 +757,7 @@ Version 1.7.0beta57 [March 16, 2015]
|
||||
in libpng-1.6.17beta01 (John Bowler).
|
||||
Revert change to png_default_read_data() made in libpng-1.7.0beta55.
|
||||
|
||||
Version 1.7.0beta58 [March 22, 2015]
|
||||
Version 1.7.0beta58 [March 23, 2015]
|
||||
Implemented affirm() support and usage.
|
||||
Remove pnglibconf.dfn and pnglibconf.pre with "make clean".
|
||||
Added byte, short and other overflow checking
|
||||
@ -772,6 +772,12 @@ Version 1.7.0beta58 [March 22, 2015]
|
||||
macros/affirm functions so that beta builds will abort on overflow and
|
||||
release builds will quietly ignore it. This avoids release builds
|
||||
producing warnings that are of no use to end users.
|
||||
Check (png_uint_16) casts for overflow. Also removed png_muldiv_warn,
|
||||
added RELEASE/!RELEASE convenience macros. png_muldiv_warn was used in
|
||||
only one place, and the overflow condition is a genuine warning not
|
||||
an internal error. Four macros allow code or function parameters to be
|
||||
condition on RELEASE (or not) builds and tidy up the #ifdef handling of
|
||||
functions.
|
||||
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
|
||||
8
CHANGES
8
CHANGES
@ -5047,7 +5047,7 @@ Version 1.7.0beta57 [March 16, 2015]
|
||||
in libpng-1.6.17beta01 (John Bowler).
|
||||
Revert change to png_default_read_data() made in libpng-1.7.0beta55.
|
||||
|
||||
Version 1.7.0beta58 [March 22, 2015]
|
||||
Version 1.7.0beta58 [March 23, 2015]
|
||||
Implemented affirm() support and usage.
|
||||
Remove pnglibconf.dfn and pnglibconf.pre with "make clean".
|
||||
Added byte, short and other overflow checking
|
||||
@ -5062,6 +5062,12 @@ Version 1.7.0beta58 [March 22, 2015]
|
||||
macros/affirm functions so that beta builds will abort on overflow and
|
||||
release builds will quietly ignore it. This avoids release builds
|
||||
producing warnings that are of no use to end users.
|
||||
Check (png_uint_16) casts for overflow. Also removed png_muldiv_warn,
|
||||
added RELEASE/!RELEASE convenience macros. png_muldiv_warn was used in
|
||||
only one place, and the overflow condition is a genuine warning not
|
||||
an internal error. Four macros allow code or function parameters to be
|
||||
condition on RELEASE (or not) builds and tidy up the #ifdef handling of
|
||||
functions.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
||||
35
png.c
35
png.c
@ -689,13 +689,13 @@ png_get_copyright(png_const_structrp png_ptr)
|
||||
#else
|
||||
# ifdef __STDC__
|
||||
return PNG_STRING_NEWLINE \
|
||||
"libpng version 1.7.0beta58 - March 22, 2015" PNG_STRING_NEWLINE \
|
||||
"libpng version 1.7.0beta58 - March 23, 2015" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
|
||||
PNG_STRING_NEWLINE;
|
||||
# else
|
||||
return "libpng version 1.7.0beta58 - March 22, 2015\
|
||||
return "libpng version 1.7.0beta58 - March 23, 2015\
|
||||
Copyright (c) 1998-2015 Glenn Randers-Pehrson\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
|
||||
@ -1798,7 +1798,7 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
2/*from sRGB*/);
|
||||
|
||||
/* intent: bugs in GCC force 'int' to be used as the parameter type. */
|
||||
colorspace->rendering_intent = (png_uint_16)intent;
|
||||
colorspace->rendering_intent = png_check_u16(png_ptr, intent);
|
||||
colorspace->flags |= PNG_COLORSPACE_HAVE_INTENT;
|
||||
|
||||
/* endpoints */
|
||||
@ -2342,8 +2342,8 @@ png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
|
||||
|
||||
else
|
||||
{
|
||||
png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r;
|
||||
png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g;
|
||||
png_ptr->rgb_to_gray_red_coeff = png_check_u16(png_ptr, r);
|
||||
png_ptr->rgb_to_gray_green_coeff = png_check_u16(png_ptr, g);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3259,25 +3259,6 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
|
||||
}
|
||||
#endif /* READ_GAMMA || INCH_CONVERSIONS */
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
|
||||
/* The following is for when the caller doesn't much care about the
|
||||
* result.
|
||||
*/
|
||||
png_fixed_point
|
||||
png_muldiv_warn(png_const_structrp png_ptr, png_fixed_point a, png_int_32 times,
|
||||
png_int_32 divisor)
|
||||
{
|
||||
png_fixed_point result;
|
||||
|
||||
if (png_muldiv(&result, a, times, divisor) != 0)
|
||||
return result;
|
||||
|
||||
handled("fixed point overflow");
|
||||
return 0;
|
||||
PNG_UNUSED(png_ptr) /* Only used in non-release builds */
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_GAMMA_SUPPORTED /* more fixed point functions for gamma */
|
||||
/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */
|
||||
png_fixed_point
|
||||
@ -3642,8 +3623,8 @@ png_exp16bit(png_const_structrp png_ptr, png_fixed_point lg2)
|
||||
|
||||
/* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */
|
||||
x -= x >> 16;
|
||||
return (png_uint_16)((x + 32767U) >> 16);
|
||||
PNG_UNUSED(png_ptr)
|
||||
return png_check_u16(png_ptr, (x + 32767U) >> 16);
|
||||
PNG_UNUSEDRC(png_ptr)
|
||||
}
|
||||
#endif /* FLOATING_ARITHMETIC */
|
||||
|
||||
@ -3811,7 +3792,7 @@ write_gamma_table(png_const_structrp png_ptr, const gamma_table_data *data,
|
||||
png_uint_16p table16 = png_voidcast(png_uint_16p, data->table);
|
||||
|
||||
while (++lo < hi)
|
||||
table16[lo] = (png_uint_16)loval;
|
||||
table16[lo] = png_check_u16(png_ptr, loval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
png.h
14
png.h
@ -1,7 +1,7 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng version 1.7.0beta58, March 17, 2015
|
||||
* libpng version 1.7.0beta58, March 23, 2015
|
||||
*
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
@ -12,7 +12,7 @@
|
||||
* Authors and maintainers:
|
||||
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
|
||||
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
|
||||
* libpng versions 0.97, January 1998, through 1.7.0beta58, March 17, 2015: Glenn
|
||||
* libpng versions 0.97, January 1998, through 1.7.0beta58, March 23, 2015: Glenn
|
||||
* See also "Contributing Authors", below.
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
@ -248,7 +248,7 @@
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
*
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.7.0beta58, March 17, 2015, are
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.7.0beta58, March 23, 2015, are
|
||||
* Copyright (c) 2004, 2006-2015 Glenn Randers-Pehrson, and are
|
||||
* distributed according to the same disclaimer and license as libpng-1.2.5
|
||||
* with the following individual added to the list of Contributing Authors:
|
||||
@ -360,7 +360,7 @@
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* March 17, 2015
|
||||
* March 23, 2015
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
@ -430,7 +430,7 @@
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.7.0beta58"
|
||||
#define PNG_HEADER_VERSION_STRING \
|
||||
" libpng version 1.7.0beta58 - March 17, 2015\n"
|
||||
" libpng version 1.7.0beta58 - March 23, 2015\n"
|
||||
|
||||
#define PNG_LIBPNG_VER_SONUM 17
|
||||
#define PNG_LIBPNG_VER_DLLNUM 17
|
||||
@ -557,9 +557,9 @@
|
||||
*/
|
||||
#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
|
||||
|
||||
#define PNG_U16(b1, b2) ((png_uint_16)PNG_u2(b1, b2))
|
||||
#define PNG_U16(b1, b2) ((png_uint_16)/*SAFE*/PNG_u2(b1, b2))
|
||||
#define PNG_U32(b1, b2, b3, b4)\
|
||||
(((png_uint_32)PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
|
||||
(((png_uint_32)/*SAFE*/PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
|
||||
|
||||
/* ISO-PNG states that signed 32-bit values are stored in two's complement
|
||||
* format. There is no guarantee that (png_int_32) is exactly 32 bits, so the
|
||||
|
||||
61
pngerror.c
61
pngerror.c
@ -1029,28 +1029,13 @@ png_affirm_number(png_charp buffer, size_t bufsize, size_t pos,
|
||||
# define affirm_number(a,b,c,d,e) png_affirm_number(a,b,c,d)
|
||||
#endif /* !HAVE_FORMAT_NUMBER */
|
||||
|
||||
#if PNG_RELEASE_BUILD
|
||||
# define affirm_text(b, c, p)\
|
||||
do {\
|
||||
(affirm_text)(b, sizeof b, (p));\
|
||||
} while (0)
|
||||
|
||||
static void
|
||||
(affirm_text)(png_charp buffer, size_t bufsize, unsigned int position)
|
||||
#else
|
||||
# define affirm_text(b, c, p)\
|
||||
do {\
|
||||
(affirm_text)(b, sizeof b, (c), (p));\
|
||||
} while (0)
|
||||
|
||||
static void
|
||||
(affirm_text)(png_charp buffer, size_t bufsize, png_const_charp condition,
|
||||
unsigned int position)
|
||||
#endif
|
||||
affirm_text(png_charp buffer, size_t bufsize,
|
||||
param_deb(png_const_charp condition) unsigned int position)
|
||||
{
|
||||
/* Format the 'position' number and output:
|
||||
*
|
||||
* "<file>, <line>: affirm 'condition' failed\n"
|
||||
* "<file> <line>: affirm 'condition' failed\n"
|
||||
* " libpng version <version> - <date>\n"
|
||||
* " translated __DATE__ __TIME__"
|
||||
*
|
||||
@ -1099,7 +1084,7 @@ static void
|
||||
# undef nfiles
|
||||
|
||||
pos = png_safecat(buffer, bufsize, pos, filename);
|
||||
pos = png_safecat(buffer, bufsize, pos, ".c, ");
|
||||
pos = png_safecat(buffer, bufsize, pos, ".c ");
|
||||
pos = affirm_number(buffer, bufsize, pos, position,
|
||||
PNG_NUMBER_FORMAT_u);
|
||||
}
|
||||
@ -1111,17 +1096,18 @@ static void
|
||||
|
||||
pos = png_safecat(buffer, bufsize, pos, PNG_HEADER_VERSION_STRING);
|
||||
pos = png_safecat(buffer, bufsize, pos,
|
||||
" translated " __DATE__ " " __TIME__);
|
||||
" translated " __DATE__ " " __TIME__);
|
||||
}
|
||||
|
||||
#define affirm_text(b, c, p)\
|
||||
do {\
|
||||
(affirm_text)(b, sizeof b, param_deb(c) (p));\
|
||||
} while (0)
|
||||
|
||||
#endif /* AFFIRM_TEXT */
|
||||
|
||||
#if PNG_RELEASE_BUILD
|
||||
PNG_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,
|
||||
unsigned int position), PNG_NORETURN)
|
||||
#else
|
||||
PNG_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,
|
||||
png_const_charp condition, unsigned int position), PNG_NORETURN)
|
||||
#endif
|
||||
param_deb(png_const_charp condition) unsigned int position), PNG_NORETURN)
|
||||
{
|
||||
# if PNG_AFFIRM_TEXT
|
||||
char buffer[512];
|
||||
@ -1165,7 +1151,7 @@ PNG_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,
|
||||
}
|
||||
|
||||
#ifdef PNG_RANGE_CHECK_SUPPORTED
|
||||
/* The character/byte checking APIs, these do their own calls to png_assert
|
||||
/* The character/byte checking APIs. These do their own calls to png_assert
|
||||
* because the caller provides the position.
|
||||
*/
|
||||
char /* PRIVATE */
|
||||
@ -1174,12 +1160,7 @@ png_char_affirm(png_const_structrp png_ptr, unsigned int position, int c)
|
||||
if (c >= CHAR_MIN && c <= CHAR_MAX)
|
||||
return (char)/*SAFE*/c;
|
||||
|
||||
# if PNG_RELEASE_BUILD
|
||||
/* testing in RC: no condition */
|
||||
png_affirm(png_ptr, position);
|
||||
# else
|
||||
png_affirm(png_ptr, "(char) range", position);
|
||||
# endif
|
||||
png_affirm(png_ptr, param_deb("(char) range") position);
|
||||
}
|
||||
|
||||
png_byte /* PRIVATE */
|
||||
@ -1191,12 +1172,7 @@ png_byte_affirm(png_const_structrp png_ptr, unsigned int position, int b)
|
||||
if (b >= 0 && b <= 255)
|
||||
return (png_byte)/*SAFE*/b;
|
||||
|
||||
# if PNG_RELEASE_BUILD
|
||||
/* testing in RC: no condition */
|
||||
png_affirm(png_ptr, position);
|
||||
# else
|
||||
png_affirm(png_ptr, "PNG byte range", position);
|
||||
# endif
|
||||
png_affirm(png_ptr, param_deb("PNG byte range") position);
|
||||
}
|
||||
|
||||
#if INT_MAX >= 65535
|
||||
@ -1207,12 +1183,7 @@ png_u16_affirm(png_const_structrp png_ptr, unsigned int position, int b)
|
||||
if (b >= 0 && b <= 65535)
|
||||
return (png_uint_16)/*SAFE*/b;
|
||||
|
||||
# if PNG_RELEASE_BUILD
|
||||
/* testing in RC: no condition */
|
||||
png_affirm(png_ptr, position);
|
||||
# else
|
||||
png_affirm(png_ptr, "PNG 16-bit range", position);
|
||||
# endif
|
||||
png_affirm(png_ptr, param_deb("PNG 16-bit range") position);
|
||||
}
|
||||
#endif /* INT_MAX >= 65535 */
|
||||
|
||||
|
||||
19
pngget.c
19
pngget.c
@ -366,14 +366,25 @@ png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
static png_fixed_point
|
||||
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
|
||||
png_fixed_inches_from_microns(png_const_structrp png_ptr,
|
||||
png_int_32 microns)
|
||||
{
|
||||
/* Convert from metres * 1,000,000 to inches * 100,000, meters to
|
||||
* inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
|
||||
* Notice that this can overflow - a warning is output and 0 is
|
||||
* returned.
|
||||
*/
|
||||
return png_muldiv_warn(png_ptr, microns, 500, 127);
|
||||
png_fixed_point result;
|
||||
|
||||
if (png_muldiv(&result, microns, 500, 127) != 0)
|
||||
return result;
|
||||
|
||||
/* TODO: review this, png_error might be better. */
|
||||
png_warning(png_ptr, "inch to microns overflow");
|
||||
return 0;
|
||||
# ifndef PNG_WARNINGS_SUPPORTED
|
||||
PNG_UNUSED(png_ptr)
|
||||
# endif
|
||||
}
|
||||
|
||||
png_fixed_point PNGAPI
|
||||
@ -383,9 +394,7 @@ png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
return png_fixed_inches_from_microns(png_ptr,
|
||||
png_get_x_offset_microns(png_ptr, info_ptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_fixed_point PNGAPI
|
||||
png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr)
|
||||
@ -393,7 +402,7 @@ png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
return png_fixed_inches_from_microns(png_ptr,
|
||||
png_get_y_offset_microns(png_ptr, info_ptr));
|
||||
}
|
||||
#endif
|
||||
#endif /* FIXED_POINT */
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float PNGAPI
|
||||
|
||||
69
pngpriv.h
69
pngpriv.h
@ -335,12 +335,32 @@
|
||||
/* This is a global switch to set the compilation for an installed system
|
||||
* (a release build). It can be set for testing debug builds to ensure that
|
||||
* they will compile when the build type is switched to RC or STABLE, the
|
||||
* default is just to use PNG_LIBPNG_BUILD_BASE_TYPE.
|
||||
* default is just to use PNG_LIBPNG_BUILD_BASE_TYPE. Set this in CPPFLAGS
|
||||
* with either:
|
||||
*
|
||||
* -DPNG_RELEASE_BUILD Turns on the release compile path
|
||||
* -DPNG_RELEASE_BUILD=0 Turns it off
|
||||
*/
|
||||
#ifndef PNG_RELEASE_BUILD
|
||||
# define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)
|
||||
#endif
|
||||
|
||||
/* General purpose macros avoid the need to out #if PNG_RELEASE_BUILD
|
||||
* macro blocks around function declarations and definitions when the
|
||||
* parameter number varies. Using these results in slightly cleaner code.
|
||||
*/
|
||||
#if PNG_RELEASE_BUILD
|
||||
# define only_rel(text) text
|
||||
# define only_deb(text)
|
||||
# define param_rel(param) param,
|
||||
# define param_deb(param)
|
||||
#else
|
||||
# define only_rel(text)
|
||||
# define only_deb(text) text
|
||||
# define param_rel(param)
|
||||
# define param_deb(param) param,
|
||||
#endif
|
||||
|
||||
/* The affirm mechanism results in a minimal png_error in released versions
|
||||
* ('STABLE' versions) and a more descriptive abort in all other cases.
|
||||
* The macros rely on the naming convention throughout this code - png_ptr
|
||||
@ -354,8 +374,8 @@
|
||||
*
|
||||
* PNG_SRC_LINE is the position of the affirm macro. There are currently 15
|
||||
* main source files (4 bits) and the biggest (pngrtran.c) has more than 4095
|
||||
* lines (12 bits), but to ensure the number will fit into 16-bits in the
|
||||
* future and to allow hardware files to use affirm the encoding is a bit-wise
|
||||
* lines (12 bits). However, to ensure the number will fit into 16-bits in the
|
||||
* future and to allow hardware files to use affirm, the encoding is a bit-wise
|
||||
* encoding based on the current number of lines.
|
||||
*
|
||||
* The following works out the value for two numeric #defines:
|
||||
@ -489,6 +509,9 @@
|
||||
* true libpng is almost certainly going to produce errors; it has never been
|
||||
* tested on such a system. For the moment pngconf.h ensures that this will
|
||||
* not happen.
|
||||
*
|
||||
* PNG_UINT_16 does the same thing for a 16-bit value passed in an (int) or
|
||||
* (png_uint_32) (where checking is not expected.)
|
||||
*/
|
||||
#if !PNG_RELEASE_BUILD
|
||||
# ifndef PNG_NO_RANGE_CHECK /* Turn off even in pre-release */
|
||||
@ -531,11 +554,7 @@
|
||||
/* This is a convenience for parameters which are not used in release
|
||||
* builds.
|
||||
*/
|
||||
#if PNG_RELEASE_BUILD
|
||||
# define PNG_UNUSEDRC(param) (void)param;
|
||||
#else
|
||||
# define PNG_UNUSEDRC(param)
|
||||
#endif
|
||||
#define PNG_UNUSEDRC(param) only_rel(PNG_UNUSED(param))
|
||||
|
||||
/* Just a little check that someone hasn't tried to define something
|
||||
* contradictory.
|
||||
@ -893,13 +912,8 @@ extern "C" {
|
||||
* All of these functions must be declared with PNG_INTERNAL_FUNCTION.
|
||||
*/
|
||||
/* Assert handling */
|
||||
#if PNG_RELEASE_BUILD
|
||||
PNG_INTERNAL_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,
|
||||
unsigned int position), PNG_NORETURN);
|
||||
#else
|
||||
PNG_INTERNAL_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,
|
||||
png_const_charp condition, unsigned int position), PNG_NORETURN);
|
||||
#endif
|
||||
param_deb(png_const_charp condition) unsigned int position), PNG_NORETURN);
|
||||
|
||||
/* Character/byte range checking. */
|
||||
#ifdef PNG_RANGE_CHECK_SUPPORTED
|
||||
@ -928,28 +942,32 @@ PNG_INTERNAL_FUNCTION(png_uint_16, png_u16_affirm,(png_const_structrp png_ptr,
|
||||
|
||||
# define png_check_char(pp, c) (png_char_affirm((pp), PNG_SRC_LINE, (c)))
|
||||
# define png_check_byte(pp, b) (png_byte_affirm((pp), PNG_SRC_LINE, (b)))
|
||||
# define PNG_BYTE(b) ((png_byte)((b) & 0xff))
|
||||
# define png_handled(pp, m) (png_handled_affirm((pp), (m), PNG_SRC_LINE))
|
||||
# define PNG_BYTE(b) ((png_byte)((b) & 0xff))
|
||||
# define PNG_UINT_16(u) ((png_uint_16)((u) & 0xffff))
|
||||
# define png_handled(pp, m) (png_handled_affirm((pp), (m), PNG_SRC_LINE))
|
||||
#elif !(defined PNG_REMOVE_CASTS)
|
||||
# define png_check_char(pp, c) ((char)(c))
|
||||
# define png_check_byte(pp, b) ((png_byte)(b))
|
||||
# define png_check_u16(pp, u) ((png_uint_16)(u))
|
||||
# define png_handled(pp, m) ((void)0)
|
||||
# define PNG_BYTE(b) ((png_byte)((b) & 0xff))
|
||||
# define png_handled(pp, m) ((void)0)
|
||||
# define PNG_BYTE(b) ((png_byte)((b) & 0xff))
|
||||
# define PNG_UINT_16(u) ((png_uint_16)((u) & 0xffff))
|
||||
#else
|
||||
/* This is somewhat trust-me-it-works: if PNG_REMOVE_CASTS is defined then
|
||||
* the casts, which might otherwise change the values, are completely
|
||||
* removed. Use this to test your compiler to see if it makes *any*
|
||||
* difference (code size or speed.) Currently NOT SUPPORTED.
|
||||
*
|
||||
* It also makes the png_byte macro not do anything either (fine if UCHAR_MAX
|
||||
* is exactly 255.)
|
||||
* It also makes the PNG_BYTE and PNG_UINT_16 macros do nothing either
|
||||
* NOTE: this seems safe at present but might lead to unexpected results
|
||||
* if someone writes code to depend on the truncation.
|
||||
*/
|
||||
# define png_check_char(pp, c) (c)
|
||||
# define png_check_byte(pp, b) (b)
|
||||
# define png_check_u16(pp, u) (u)
|
||||
# define png_handled(pp, m) ((void)0)
|
||||
# define PNG_BYTE(b) (b)
|
||||
# define png_handled(pp, m) ((void)0)
|
||||
# define PNG_BYTE(b) (b)
|
||||
# define PNG_UINT_16(b) (u)
|
||||
#endif
|
||||
|
||||
/* Utility macro to mark a handled error condition ; when control reaches this
|
||||
@ -1909,13 +1927,6 @@ PNG_INTERNAL_FUNCTION(int,png_muldiv,(png_fixed_point_p res, png_fixed_point a,
|
||||
png_int_32 multiplied_by, png_int_32 divided_by),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
|
||||
/* Same deal, but issue a warning on overflow and return 0. */
|
||||
PNG_INTERNAL_FUNCTION(png_fixed_point,png_muldiv_warn,
|
||||
(png_const_structrp png_ptr, png_fixed_point a, png_int_32 multiplied_by,
|
||||
png_int_32 divided_by),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_GAMMA_SUPPORTED
|
||||
/* Calculate a reciprocal - used for gamma values. This returns
|
||||
* 0 if the argument is 0 in order to maintain an undefined value;
|
||||
|
||||
121
pngread.c
121
pngread.c
@ -1739,13 +1739,14 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
png_uint_32 alpha, int encoding)
|
||||
{
|
||||
png_imagep image = display->image;
|
||||
# define png_ptr image->opaque->png_ptr /* for error messages */
|
||||
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
|
||||
P_LINEAR : P_sRGB;
|
||||
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
|
||||
(red != green || green != blue);
|
||||
|
||||
if (ip > 255)
|
||||
png_error(image->opaque->png_ptr, "color-map index out of range");
|
||||
png_error(png_ptr, "color-map index out of range");
|
||||
|
||||
/* Update the cache with whether the file gamma is significantly different
|
||||
* from sRGB.
|
||||
@ -1765,9 +1766,9 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
{
|
||||
png_fixed_point g = display->gamma_to_linear;
|
||||
|
||||
red = png_gamma_16bit_correct(image->opaque->png_ptr, red*257, g);
|
||||
green = png_gamma_16bit_correct(image->opaque->png_ptr, green*257, g);
|
||||
blue = png_gamma_16bit_correct(image->opaque->png_ptr, blue*257, g);
|
||||
red = png_gamma_16bit_correct(png_ptr, red*257, g);
|
||||
green = png_gamma_16bit_correct(png_ptr, green*257, g);
|
||||
blue = png_gamma_16bit_correct(png_ptr, blue*257, g);
|
||||
|
||||
if (convert_to_Y != 0 || output_encoding == P_LINEAR)
|
||||
{
|
||||
@ -1777,9 +1778,9 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
|
||||
else
|
||||
{
|
||||
red = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, blue * 255);
|
||||
red = PNG_sRGB_FROM_LINEAR(png_ptr, red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(png_ptr, green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(png_ptr, blue * 255);
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
}
|
||||
@ -1825,7 +1826,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
/* y is scaled by 32768, we need it scaled by 255: */
|
||||
y = (y + 128) >> 8;
|
||||
y *= 255;
|
||||
y = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, (y + 64) >> 7);
|
||||
y = PNG_sRGB_FROM_LINEAR(png_ptr, (y + 64) >> 7);
|
||||
alpha = PNG_DIV257(alpha);
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
@ -1835,17 +1836,16 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
|
||||
else if (output_encoding == P_sRGB)
|
||||
{
|
||||
red = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr,
|
||||
blue * 255);
|
||||
red = PNG_sRGB_FROM_LINEAR(png_ptr, red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(png_ptr, green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(png_ptr, blue * 255);
|
||||
alpha = PNG_DIV257(alpha);
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding != output_encoding)
|
||||
png_impossiblepp(image->opaque->png_ptr, "bad encoding");
|
||||
png_impossiblepp(png_ptr, "bad encoding");
|
||||
|
||||
/* Store the value. */
|
||||
{
|
||||
@ -1874,8 +1874,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))
|
||||
{
|
||||
case 4:
|
||||
entry[afirst ? 0 : 3] = png_check_u16(image->opaque->png_ptr,
|
||||
alpha);
|
||||
entry[afirst ? 0 : 3] = png_check_u16(png_ptr, alpha);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case 3:
|
||||
@ -1891,14 +1890,13 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
else
|
||||
red = green = blue = 0;
|
||||
}
|
||||
entry[afirst + (2 ^ bgr)] = png_check_u16(image->opaque->png_ptr,
|
||||
blue);
|
||||
entry[afirst + 1] = png_check_u16(image->opaque->png_ptr, green);
|
||||
entry[afirst + bgr] = png_check_u16(image->opaque->png_ptr, red);
|
||||
entry[afirst + (2 ^ bgr)] = png_check_u16(png_ptr, blue);
|
||||
entry[afirst + 1] = png_check_u16(png_ptr, green);
|
||||
entry[afirst + bgr] = png_check_u16(png_ptr, red);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
entry[1 ^ afirst] = png_check_u16(image->opaque->png_ptr, alpha);
|
||||
entry[1 ^ afirst] = png_check_u16(png_ptr, alpha);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case 1:
|
||||
@ -1910,7 +1908,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
else
|
||||
green = 0;
|
||||
}
|
||||
entry[afirst] = png_check_u16(image->opaque->png_ptr, green);
|
||||
entry[afirst] = png_check_u16(png_ptr, green);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1924,29 +1922,24 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
|
||||
entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format);
|
||||
|
||||
png_affirmpp(image->opaque->png_ptr, output_encoding == P_sRGB);
|
||||
png_affirmpp(png_ptr, output_encoding == P_sRGB);
|
||||
|
||||
switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))
|
||||
{
|
||||
case 4:
|
||||
entry[afirst ? 0 : 3] = png_check_byte(image->opaque->png_ptr,
|
||||
alpha);
|
||||
entry[afirst ? 0 : 3] = png_check_byte(png_ptr, alpha);
|
||||
|
||||
case 3:
|
||||
entry[afirst + (2 ^ bgr)] = png_check_byte(
|
||||
image->opaque->png_ptr, blue);
|
||||
entry[afirst + 1] = png_check_byte(image->opaque->png_ptr,
|
||||
green);
|
||||
entry[afirst + bgr] = png_check_byte(image->opaque->png_ptr,
|
||||
red);
|
||||
entry[afirst + (2 ^ bgr)] = png_check_byte(png_ptr, blue);
|
||||
entry[afirst + 1] = png_check_byte(png_ptr, green);
|
||||
entry[afirst + bgr] = png_check_byte(png_ptr, red);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
entry[1 ^ afirst] = png_check_byte(image->opaque->png_ptr,
|
||||
alpha);
|
||||
entry[1 ^ afirst] = png_check_byte(png_ptr, alpha);
|
||||
|
||||
case 1:
|
||||
entry[afirst] = png_check_byte(image->opaque->png_ptr, green);
|
||||
entry[afirst] = png_check_byte(png_ptr, green);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1961,6 +1954,8 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
# undef bgr
|
||||
# endif
|
||||
}
|
||||
|
||||
# undef png_ptr
|
||||
}
|
||||
|
||||
static int
|
||||
@ -2276,7 +2271,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, gray * 255);
|
||||
gray = PNG_sRGB_FROM_LINEAR(png_ptr, gray * 255);
|
||||
|
||||
/* And make sure the corresponding palette entry
|
||||
* matches.
|
||||
@ -2289,7 +2284,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
* sRGB value.
|
||||
*/
|
||||
c.index = 0; /*unused*/
|
||||
c.gray = c.red = c.green = c.blue = (png_uint_16)gray;
|
||||
c.gray = c.red = c.green = c.blue =
|
||||
png_check_u16(png_ptr, gray);
|
||||
|
||||
/* NOTE: does this work without expanding tRNS to alpha?
|
||||
* It should be the color->gray case below apparently
|
||||
@ -2391,7 +2387,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, gray * 255);
|
||||
gray = PNG_sRGB_FROM_LINEAR(png_ptr, gray * 255);
|
||||
|
||||
/* And make sure the corresponding palette entry matches. */
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
@ -2402,7 +2398,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* value.
|
||||
*/
|
||||
c.index = 0; /*unused*/
|
||||
c.gray = c.red = c.green = c.blue = (png_uint_16)gray;
|
||||
c.gray = c.red = c.green = c.blue = png_check_u16(png_ptr, gray);
|
||||
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
@ -2479,9 +2475,10 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_uint_32 gray = png_sRGB_table[g*51] * alpha;
|
||||
|
||||
png_create_colormap_entry(display, i++,
|
||||
PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, gray + back_rx),
|
||||
PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, gray + back_gx),
|
||||
PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, gray + back_bx), 255, P_sRGB);
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, gray + back_rx),
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, gray + back_gx),
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, gray + back_bx),
|
||||
255, P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2582,8 +2579,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
if (output_encoding == P_sRGB)
|
||||
gray = png_sRGB_table[gray]; /* now P_LINEAR */
|
||||
|
||||
gray = PNG_DIV257(png_gamma_16bit_correct(
|
||||
image->opaque->png_ptr, gray,
|
||||
gray = PNG_DIV257(png_gamma_16bit_correct(png_ptr, gray,
|
||||
png_ptr->colorspace.gamma)); /* now P_FILE */
|
||||
|
||||
/* And make sure the corresponding palette entry contains
|
||||
@ -2595,7 +2591,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
else if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(image->opaque->png_ptr, gray * 255);
|
||||
gray = PNG_sRGB_FROM_LINEAR(png_ptr, gray * 255);
|
||||
|
||||
/* And make sure the corresponding palette entry matches.
|
||||
*/
|
||||
@ -2607,7 +2603,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
* output (normally sRGB) value.
|
||||
*/
|
||||
c.index = 0; /*unused*/
|
||||
c.gray = c.red = c.green = c.blue = (png_uint_16)gray;
|
||||
c.gray = c.red = c.green = c.blue =
|
||||
png_check_u16(png_ptr, gray);
|
||||
|
||||
/* NOTE: the following is apparently a bug in libpng. Without
|
||||
* it the transparent color recognition in
|
||||
@ -2702,9 +2699,9 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
r = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, back_r * 255);
|
||||
g = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, back_g * 255);
|
||||
b = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, back_b * 255);
|
||||
r = PNG_sRGB_FROM_LINEAR(png_ptr, back_r * 255);
|
||||
g = PNG_sRGB_FROM_LINEAR(png_ptr, back_g * 255);
|
||||
b = PNG_sRGB_FROM_LINEAR(png_ptr, back_b * 255);
|
||||
}
|
||||
|
||||
else
|
||||
@ -2759,9 +2756,9 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_color_16 c;
|
||||
|
||||
c.index = 0; /*unused*/
|
||||
c.red = (png_uint_16)back_r;
|
||||
c.gray = c.green = (png_uint_16)back_g;
|
||||
c.blue = (png_uint_16)back_b;
|
||||
c.red = png_check_u16(png_ptr, back_r);
|
||||
c.gray = c.green = png_check_u16(png_ptr, back_g);
|
||||
c.blue = png_check_u16(png_ptr, back_b);
|
||||
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
@ -3025,7 +3022,7 @@ png_image_read_and_map(png_voidp argument)
|
||||
entry = 226 + 6 * PNG_DIV51(alpha) + PNG_DIV51(gray);
|
||||
}
|
||||
|
||||
*outrow = png_check_byte(image->opaque->png_ptr, entry);
|
||||
*outrow = png_check_byte(png_ptr, entry);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -3097,7 +3094,7 @@ png_image_read_and_map(png_voidp argument)
|
||||
if (inrow[0] & 0x80) back_i += 1; /* blue */
|
||||
if (inrow[0] & 0x40) back_i += 1;
|
||||
|
||||
*outrow = png_check_byte(image->opaque->png_ptr, back_i);
|
||||
*outrow = png_check_byte(png_ptr, back_i);
|
||||
}
|
||||
|
||||
inrow += 4;
|
||||
@ -3345,10 +3342,11 @@ png_image_read_composite(png_voidp argument)
|
||||
* therefore appropriate for the sRGB to linear
|
||||
* conversion table.
|
||||
*/
|
||||
component = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, component);
|
||||
component =
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, component);
|
||||
}
|
||||
|
||||
outrow[c] = png_check_byte(image->opaque->png_ptr, component);
|
||||
outrow[c] = png_check_byte(png_ptr, component);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3497,11 +3495,11 @@ png_image_read_background(png_voidp argument)
|
||||
component = png_sRGB_table[component] * alpha;
|
||||
component += png_sRGB_table[outrow[0]] *
|
||||
(255-alpha);
|
||||
component = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, component);
|
||||
component =
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, component);
|
||||
}
|
||||
|
||||
outrow[0] = png_check_byte(image->opaque->png_ptr,
|
||||
component);
|
||||
outrow[0] = png_check_byte(png_ptr, component);
|
||||
}
|
||||
|
||||
inrow += 2; /* gray and alpha channel */
|
||||
@ -3538,11 +3536,11 @@ png_image_read_background(png_voidp argument)
|
||||
{
|
||||
component = png_sRGB_table[component] * alpha;
|
||||
component += background * (255-alpha);
|
||||
component = PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr, component);
|
||||
component =
|
||||
PNG_sRGB_FROM_LINEAR(png_ptr, component);
|
||||
}
|
||||
|
||||
outrow[0] = png_check_byte(image->opaque->png_ptr,
|
||||
component);
|
||||
outrow[0] = png_check_byte(png_ptr, component);
|
||||
}
|
||||
|
||||
else
|
||||
@ -3639,7 +3637,8 @@ png_image_read_background(png_voidp argument)
|
||||
else
|
||||
component = 0;
|
||||
|
||||
outrow[swap_alpha] = (png_uint_16)component;
|
||||
outrow[swap_alpha] =
|
||||
png_check_u16(png_ptr, component);
|
||||
if (preserve_alpha != 0)
|
||||
outrow[1 ^ swap_alpha] = alpha;
|
||||
|
||||
|
||||
119
pngrtran.c
119
pngrtran.c
@ -730,7 +730,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
|
||||
{
|
||||
png_ptr->palette = palette;
|
||||
}
|
||||
png_ptr->num_palette = (png_uint_16)num_palette;
|
||||
png_ptr->num_palette = png_check_u16(png_ptr, num_palette);
|
||||
|
||||
if (full_quantize != 0)
|
||||
{
|
||||
@ -1004,8 +1004,10 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
* overwrites the coefficients, regardless of whether they have been
|
||||
* defaulted or set already.
|
||||
*/
|
||||
red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);
|
||||
green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);
|
||||
red_int = png_check_u16(png_ptr,
|
||||
((png_uint_32)/*SAFE*/red*32768)/100000);
|
||||
green_int = png_check_u16(png_ptr,
|
||||
((png_uint_32)/*SAFE*/green*32768)/100000);
|
||||
|
||||
png_ptr->rgb_to_gray_red_coeff = red_int;
|
||||
png_ptr->rgb_to_gray_green_coeff = green_int;
|
||||
@ -1110,7 +1112,7 @@ gamma_correct_background(png_const_structrp png_ptr,
|
||||
gamma_correct);
|
||||
|
||||
else
|
||||
*backgroundp = (png_uint_16)value;
|
||||
*backgroundp = png_check_u16(png_ptr, value);
|
||||
|
||||
if (gamma_to_1 != PNG_FP_1)
|
||||
*background_1p = png_gamma_16bit_correct(png_ptr, value*257,
|
||||
@ -1267,7 +1269,7 @@ png_init_background_transformations(png_structrp png_ptr)
|
||||
gamma_correct, gamma_to_1);\
|
||||
if (bit_depth > required_bit_depth)\
|
||||
png_ptr->background.c =\
|
||||
(png_uint_16)PNG_DIV257(png_ptr->background.c)
|
||||
png_check_u16(png_ptr, PNG_DIV257(png_ptr->background.c))
|
||||
|
||||
/* The multiplier 'mult' scales the values to 'required_depth',
|
||||
* 'bit_depth' is the depth of the resultant values.
|
||||
@ -2979,7 +2981,8 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
if (red != green || red != blue)
|
||||
{
|
||||
rgb_error |= 1;
|
||||
*(dp++) = png_check_byte(png_ptr, (rc*red+gc*green+bc*blue+16384)>>15);
|
||||
*(dp++) = png_check_byte(png_ptr,
|
||||
(rc*red+gc*green+bc*blue+16384)>>15);
|
||||
}
|
||||
|
||||
else
|
||||
@ -3006,9 +3009,14 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
png_uint_16 red, green, blue, w;
|
||||
png_byte hi,lo;
|
||||
|
||||
hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
red = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
green = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
blue = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
|
||||
if (red == green && red == blue)
|
||||
{
|
||||
@ -3027,8 +3035,8 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
>> shift];
|
||||
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue+add)
|
||||
>> shift];
|
||||
png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
|
||||
+ bc*blue_1 + 16384)>>15);
|
||||
png_uint_16 gray16 = png_check_u16(png_ptr,
|
||||
(rc*red_1 + gc*green_1 + bc*blue_1 + 16384)>>15);
|
||||
w = png_ptr->gamma_16_from_1[(gray16+add) >> shift];
|
||||
rgb_error |= 1;
|
||||
}
|
||||
@ -3055,9 +3063,12 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
png_uint_16 red, green, blue, gray16;
|
||||
png_byte hi,lo;
|
||||
|
||||
hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
red = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
green = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
hi=*(sp)++; lo=*(sp)++;
|
||||
blue = png_check_u16(png_ptr, (hi << 8) | (lo));
|
||||
|
||||
if (red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
@ -3066,7 +3077,8 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
* in the 'fast' case - this is because this is where the code
|
||||
* ends up when handling linear 16 bit data.
|
||||
*/
|
||||
gray16 = (png_uint_16)((rc*red+gc*green+bc*blue+16384) >> 15);
|
||||
gray16 = png_check_u16(png_ptr,
|
||||
(rc*red+gc*green+bc*blue+16384) >> 15);
|
||||
*(dp++) = png_check_byte(png_ptr, gray16>>8);
|
||||
*(dp++) = PNG_BYTE(gray16);
|
||||
|
||||
@ -3128,8 +3140,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> bit_shift) & 0x01)
|
||||
== png_ptr->trans_color.gray)
|
||||
if (((*sp >> bit_shift) & 0x01) ==
|
||||
png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x7f7f >> (7 - bit_shift));
|
||||
tmp |= png_ptr->background.gray << bit_shift;
|
||||
@ -3157,8 +3169,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> bit_shift) & 0x03)
|
||||
== png_ptr->trans_color.gray)
|
||||
if (((*sp >> bit_shift) & 0x03) ==
|
||||
png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x3f3f >> (6 - bit_shift));
|
||||
tmp |= png_ptr->background.gray << bit_shift;
|
||||
@ -3193,8 +3205,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> bit_shift) & 0x03)
|
||||
== png_ptr->trans_color.gray)
|
||||
if (((*sp >> bit_shift) & 0x03) ==
|
||||
png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0x3f3f >> (6 - bit_shift));
|
||||
tmp |= png_ptr->background.gray << bit_shift;
|
||||
@ -3223,8 +3235,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> bit_shift) & 0x0f)
|
||||
== png_ptr->trans_color.gray)
|
||||
if (((*sp >> bit_shift) & 0x0f) ==
|
||||
png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0xf0f >> (4 - bit_shift));
|
||||
tmp |= png_ptr->background.gray << bit_shift;
|
||||
@ -3259,8 +3271,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> bit_shift) & 0x0f)
|
||||
== png_ptr->trans_color.gray)
|
||||
if (((*sp >> bit_shift) & 0x0f) ==
|
||||
png_ptr->trans_color.gray)
|
||||
{
|
||||
unsigned int tmp = *sp & (0xf0f >> (4 - bit_shift));
|
||||
tmp |= png_ptr->background.gray << bit_shift;
|
||||
@ -3316,7 +3328,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
v = png_check_u16(png_ptr, ((*sp) << 8) + *(sp + 1));
|
||||
|
||||
if (v == png_ptr->trans_color.gray)
|
||||
{
|
||||
@ -3341,7 +3353,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
v = png_check_u16(png_ptr, ((*sp) << 8) + *(sp + 1));
|
||||
|
||||
if (v == png_ptr->trans_color.gray)
|
||||
{
|
||||
@ -3411,13 +3423,14 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 6)
|
||||
{
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 r = png_check_u16(png_ptr,
|
||||
((*sp) << 8) + *(sp + 1));
|
||||
|
||||
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 g = png_check_u16(png_ptr,
|
||||
((*(sp + 2)) << 8) + *(sp + 3));
|
||||
|
||||
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
|
||||
+ *(sp + 5));
|
||||
png_uint_16 b = png_check_u16(png_ptr,
|
||||
((*(sp + 4)) << 8) + *(sp + 5));
|
||||
|
||||
if (r == png_ptr->trans_color.red &&
|
||||
g == png_ptr->trans_color.green &&
|
||||
@ -3457,13 +3470,14 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 6)
|
||||
{
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 r = png_check_u16(png_ptr,
|
||||
((*sp) << 8) + *(sp + 1));
|
||||
|
||||
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 g = png_check_u16(png_ptr,
|
||||
((*(sp + 2)) << 8) + *(sp + 3));
|
||||
|
||||
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
|
||||
+ *(sp + 5));
|
||||
png_uint_16 b = png_check_u16(png_ptr,
|
||||
((*(sp + 4)) << 8) + *(sp + 5));
|
||||
|
||||
if (r == png_ptr->trans_color.red &&
|
||||
g == png_ptr->trans_color.green &&
|
||||
@ -3549,10 +3563,10 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 4)
|
||||
{
|
||||
png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 a = png_check_u16(png_ptr,
|
||||
((*(sp + 2)) << 8) + *(sp + 3));
|
||||
|
||||
if (a == (png_uint_16)0xffff)
|
||||
if (a == 65535)
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
@ -3593,8 +3607,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 4)
|
||||
{
|
||||
png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 a = png_check_u16(png_ptr,
|
||||
((*(sp + 2)) << 8) + *(sp + 3));
|
||||
|
||||
if (a == 0)
|
||||
{
|
||||
@ -3729,10 +3743,10 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 8)
|
||||
{
|
||||
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
|
||||
<< 8) + (png_uint_16)(*(sp + 7)));
|
||||
png_uint_16 a = png_check_u16(png_ptr,
|
||||
((*(sp + 6)) << 8) + *(sp + 7));
|
||||
|
||||
if (a == (png_uint_16)0xffff)
|
||||
if (a == 65535)
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
@ -3801,8 +3815,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 8)
|
||||
{
|
||||
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
|
||||
<< 8) + (png_uint_16)(*(sp + 7)));
|
||||
png_uint_16 a = png_check_u16(png_ptr,
|
||||
((*(sp + 6)) << 8) + *(sp + 7));
|
||||
|
||||
if (a == 0)
|
||||
{
|
||||
@ -3821,11 +3835,12 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
|
||||
+ *(sp + 5));
|
||||
png_uint_16 r = png_check_u16(png_ptr,
|
||||
((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 g = png_check_u16(png_ptr,
|
||||
((*(sp + 2)) << 8) + *(sp + 3));
|
||||
png_uint_16 b = png_check_u16(png_ptr,
|
||||
((*(sp + 4)) << 8) + *(sp + 5));
|
||||
|
||||
png_composite_16(v, r, a, png_ptr->background.red);
|
||||
*sp = png_check_byte(png_ptr, v >> 8);
|
||||
|
||||
10
pngrutil.c
10
pngrutil.c
@ -1812,7 +1812,7 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, readbuf, length);
|
||||
png_ptr->num_trans = (png_uint_16)length;
|
||||
png_ptr->num_trans = png_check_u16(png_ptr, length);
|
||||
}
|
||||
|
||||
else
|
||||
@ -1907,9 +1907,11 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
return;
|
||||
}
|
||||
|
||||
background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
|
||||
background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
|
||||
background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
|
||||
background.red = png_check_u16(png_ptr, png_ptr->palette[buf[0]].red);
|
||||
background.green =
|
||||
png_check_u16(png_ptr, png_ptr->palette[buf[0]].green);
|
||||
background.blue =
|
||||
png_check_u16(png_ptr, png_ptr->palette[buf[0]].blue);
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
5
pngset.c
5
pngset.c
@ -563,7 +563,8 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
||||
if (num_palette > 0)
|
||||
memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
|
||||
info_ptr->palette = png_ptr->palette;
|
||||
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
|
||||
info_ptr->num_palette = png_ptr->num_palette =
|
||||
png_check_u16(png_ptr, num_palette);
|
||||
|
||||
info_ptr->free_me |= PNG_FREE_PLTE;
|
||||
|
||||
@ -988,7 +989,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
memcpy(info_ptr->trans_alpha, trans_alpha,
|
||||
(unsigned)/*SAFE*/num_trans);
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
info_ptr->num_trans = (png_uint_16)num_trans; /* SAFE */
|
||||
info_ptr->num_trans = png_check_u16(png_ptr, num_trans);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
* NOTE: usr_channels is not used by the read code! (This has led to
|
||||
* confusion in the past.) The filler is only used in the read code.
|
||||
*/
|
||||
png_ptr->filler = (png_uint_16)filler;
|
||||
png_ptr->filler = PNG_UINT_16(filler); /* Max bit depth is 16 */
|
||||
# else
|
||||
png_app_error(png_ptr, "png_set_filler not supported on read");
|
||||
PNG_UNUSED(filler) /* not used in the write case */
|
||||
|
||||
39
pngwrite.c
39
pngwrite.c
@ -461,7 +461,7 @@ png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime)
|
||||
{
|
||||
png_debug(1, "in png_convert_from_struct_tm");
|
||||
|
||||
ptime->year = (png_uint_16)(1900 + ttime->tm_year);
|
||||
ptime->year = png_check_u16(0/*TODO: fixme*/, 1900 + ttime->tm_year);
|
||||
ptime->month = png_check_byte(0/*TODO: fixme*/, ttime->tm_mon + 1);
|
||||
ptime->day = png_check_byte(0/*TODO: fixme*/, ttime->tm_mday);
|
||||
ptime->hour = png_check_byte(0/*TODO: fixme*/, ttime->tm_hour);
|
||||
@ -1231,6 +1231,20 @@ png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method,
|
||||
|
||||
/* Provide floating and fixed point APIs */
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
static png_uint_16
|
||||
u16_from_fp(png_const_structrp png_ptr, int position, double fp)
|
||||
{
|
||||
/* Utility: given a double make sure it fits into a PNG 16-bit unsigned
|
||||
* value.
|
||||
*/
|
||||
if (fp >= 0 && fp < 65536)
|
||||
return (png_uint_16)/*SAFE*/fp;
|
||||
|
||||
png_affirm(png_ptr, param_deb("fp to u16 overflow") position);
|
||||
}
|
||||
|
||||
#define u16_from_fp(pp, fp) (u16_from_fp((pp), PNG_SRC_LINE, (fp)))
|
||||
|
||||
void PNGAPI
|
||||
png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method,
|
||||
int num_weights, png_const_doublep filter_weights,
|
||||
@ -1259,10 +1273,10 @@ png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method,
|
||||
else
|
||||
{
|
||||
png_ptr->inv_filter_weights[i] =
|
||||
(png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
|
||||
u16_from_fp(png_ptr, PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
|
||||
|
||||
png_ptr->filter_weights[i] =
|
||||
(png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
|
||||
u16_from_fp(png_ptr, PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1276,10 +1290,10 @@ png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method,
|
||||
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0)
|
||||
{
|
||||
png_ptr->inv_filter_costs[i] =
|
||||
(png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5);
|
||||
u16_from_fp(png_ptr, PNG_COST_FACTOR / filter_costs[i] + .5);
|
||||
|
||||
png_ptr->filter_costs[i] =
|
||||
(png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5);
|
||||
u16_from_fp(png_ptr, PNG_COST_FACTOR * filter_costs[i] + .5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1313,11 +1327,12 @@ png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method,
|
||||
|
||||
else
|
||||
{
|
||||
png_ptr->inv_filter_weights[i] = (png_uint_16)
|
||||
((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
|
||||
png_ptr->inv_filter_weights[i] = png_check_u16(png_ptr,
|
||||
(PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
|
||||
|
||||
png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR*
|
||||
PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]);
|
||||
png_ptr->filter_weights[i] = png_check_u16(png_ptr,
|
||||
(PNG_WEIGHT_FACTOR*PNG_FP_1+(filter_weights[i]/2))/
|
||||
filter_weights[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1340,12 +1355,12 @@ png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method,
|
||||
tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2);
|
||||
tmp /= filter_costs[i];
|
||||
|
||||
png_ptr->inv_filter_costs[i] = (png_uint_16)tmp;
|
||||
png_ptr->inv_filter_costs[i] = png_check_u16(png_ptr, tmp);
|
||||
|
||||
tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF;
|
||||
tmp /= PNG_FP_1;
|
||||
|
||||
png_ptr->filter_costs[i] = (png_uint_16)tmp;
|
||||
png_ptr->filter_costs[i] = png_check_u16(png_ptr, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1803,7 +1818,7 @@ png_write_image_16bit(png_voidp argument)
|
||||
{
|
||||
png_uint_32 calc = component * reciprocal;
|
||||
calc += 16384; /* round to nearest */
|
||||
component = (png_uint_16)(calc >> 15);
|
||||
component = png_check_u16(png_ptr, calc >> 15);
|
||||
}
|
||||
|
||||
*out_ptr++ = component;
|
||||
|
||||
@ -957,7 +957,7 @@ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,
|
||||
return;
|
||||
}
|
||||
|
||||
png_ptr->num_palette = (png_uint_16)num_pal;
|
||||
png_ptr->num_palette = png_check_u16(png_ptr, num_pal);
|
||||
png_debug1(3, "num_palette = %d", png_ptr->num_palette);
|
||||
|
||||
png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user