[master] Revised png_check_IHDR() again

to check info_ptr members instead of the contents of the returned parameters.
This commit is contained in:
Glenn Randers-Pehrson 2009-09-30 23:10:28 -05:00
parent 64ca95e375
commit 5d7fe7a718
6 changed files with 62 additions and 56 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.2.41beta03 - September 30, 2009 Libpng 1.2.41beta03 - October 1, 2009
This is not intended to be a public release. It will be replaced 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. within a few weeks by a public version or by another test version.
@ -51,7 +51,9 @@ version 1.2.41beta01 [September 25, 2009]
version 1.2.41beta02 [September 30, 2009] version 1.2.41beta02 [September 30, 2009]
Revised png_check_IHDR(). Revised png_check_IHDR().
version 1.2.41beta03 [September 30, 2009] version 1.2.41beta03 [October 1, 2009]
Revised png_check_IHDR() again, to check info_ptr members instead of
the contents of the returned parameters.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net

View File

@ -2466,7 +2466,7 @@ version 1.2.40beta01 [August 20, 2009]
version 1.2.40rc01 [September 2, 2009] version 1.2.40rc01 [September 2, 2009]
Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) Various bugfixes and improvements to CMakeLists.txt (Philip Lowman)
version 1.2.40 and 1.0.49 [September 30, 2009] version 1.2.40 and 1.0.49 [October 1, 2009]
No changes. No changes.
version 1.0.50 [September 10, 2009] version 1.0.50 [September 10, 2009]
@ -2481,7 +2481,9 @@ version 1.2.41beta01 [September 25, 2009]
version 1.2.41beta02 [September 30, 2009] version 1.2.41beta02 [September 30, 2009]
Revised png_check_IHDR(). Revised png_check_IHDR().
version 1.2.41beta03 [September 30, 2009] version 1.2.41beta03 [October 1, 2009]
Revised png_check_IHDR() again, to check info_ptr members instead of
the contents of the returned parameters.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng libpng.txt - A description on how to use and modify libpng
libpng version 1.2.41beta03 - September 30, 2009 libpng version 1.2.41beta03 - October 1, 2009
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net> <glennrp at users.sourceforge.net>
Copyright (c) 1998-2009 Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -11,7 +11,7 @@ libpng.txt - A description on how to use and modify libpng
Based on: Based on:
libpng versions 0.97, January 1998, through 1.2.41beta03 - September 30, 2009 libpng versions 0.97, January 1998, through 1.2.41beta03 - October 1, 2009
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2009 Glenn Randers-Pehrson Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -545,10 +545,33 @@ in until png_read_end() has read the chunk data following the image.
for PNG 1.0) for PNG 1.0)
interlace_type - (PNG_INTERLACE_NONE or interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7) PNG_INTERLACE_ADAM7)
Any or all of interlace_type, compression_type, of
Any or all of interlace_type, compression_type, or
filter_method can be NULL if you are filter_method can be NULL if you are
not interested in their values. not interested in their values.
Note that png_get_IHDR() returns 32-bit data into
the application's width and height variables.
This is an unsafe situation if these are 16-bit
variables. In such situations, the
png_get_image_width() and png_get_image_height()
functions described below are safer.
width = png_get_image_width(png_ptr,
info_ptr);
height = png_get_image_height(png_ptr,
info_ptr);
bit_depth = png_get_bit_depth(png_ptr,
info_ptr);
color_type = png_get_color_type(png_ptr,
info_ptr);
filter_method = png_get_filter_type(png_ptr,
info_ptr);
compression_type = png_get_compression_type(png_ptr,
info_ptr);
interlace_type = png_get_interlace_type(png_ptr,
info_ptr);
channels = png_get_channels(png_ptr, info_ptr); channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the channels - number of channels of info for the
color type (valid values are 1 (GRAY, color type (valid values are 1 (GRAY,
@ -568,23 +591,6 @@ in until png_read_end() has read the chunk data following the image.
be in signature[4] through signature[7] be in signature[4] through signature[7]
(see png_set_sig_bytes())). (see png_set_sig_bytes())).
width = png_get_image_width(png_ptr,
info_ptr);
height = png_get_image_height(png_ptr,
info_ptr);
bit_depth = png_get_bit_depth(png_ptr,
info_ptr);
color_type = png_get_color_type(png_ptr,
info_ptr);
filter_method = png_get_filter_type(png_ptr,
info_ptr);
compression_type = png_get_compression_type(png_ptr,
info_ptr);
interlace_type = png_get_interlace_type(png_ptr,
info_ptr);
These are also important, but their validity depends on whether the chunk These are also important, but their validity depends on whether the chunk
has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
@ -2982,6 +2988,15 @@ We use 3-space indentation, except for continued statements which
are usually indented the same as the first line of the statement are usually indented the same as the first line of the statement
plus four more spaces. plus four more spaces.
For macro definitions we use 2-space indentation, always leaving the "#"
in the first column.
#ifndef PNG_NO_FEATURE
# ifndef PNG_FEATURE_SUPPORTED
# define PNG_FEATURE_SUPPORTED
# endif
#endif
Comments appear with the leading "/*" at the same indentation as Comments appear with the leading "/*" at the same indentation as
the statement that follows the comment: the statement that follows the comment:
@ -3058,7 +3073,7 @@ source.
XIII. Y2K Compliance in libpng XIII. Y2K Compliance in libpng
September 30, 2009 October 1, 2009
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.

12
png.c
View File

@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* Last changed in libpng 1.2.41 [September 30, 2009] * Last changed in libpng 1.2.41 [October 1, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -705,7 +705,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.41beta03 - September 30, 2009\n\ return ((png_charp) "\n libpng version 1.2.41beta03 - October 1, 2009\n\
Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\ Copyright (c) 1998-2009 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");
@ -953,14 +953,6 @@ png_check_IHDR(png_structp png_ptr,
#endif #endif
{ {
png_warning(png_ptr, "Image width exceeds user limit in IHDR"); png_warning(png_ptr, "Image width exceeds user limit in IHDR");
if ((width >> 16) == height)
{
/* This is likely to be caused by passing consecutive addresses
* of 16-bit width and height variables to png_get_IHDR(), which
* overflowed when we tried to fill them with 31-bit data.
*/
png_warning(png_ptr, "High bytes of width == low bytes of height");
}
error = 1; error = 1;
} }

View File

@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* Last changed in libpng 1.2.41 [September 30, 2009] * Last changed in libpng 1.2.41 [October 1, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -567,10 +567,6 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
int *color_type, int *interlace_type, int *compression_type, int *color_type, int *interlace_type, int *compression_type,
int *filter_type) int *filter_type)
{ {
int test_interlace_type = 0;
int test_compression_type = 0;
int test_filter_type = 0;
png_debug1(1, "in %s retrieval function", "IHDR"); png_debug1(1, "in %s retrieval function", "IHDR");
if (png_ptr == NULL || info_ptr == NULL || width == NULL || if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
@ -583,25 +579,22 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
*color_type = info_ptr->color_type; *color_type = info_ptr->color_type;
if (compression_type != NULL) if (compression_type != NULL)
{
*compression_type = info_ptr->compression_type; *compression_type = info_ptr->compression_type;
test_compression_type = *compression_type;
}
if (filter_type != NULL) if (filter_type != NULL)
{
*filter_type = info_ptr->filter_type; *filter_type = info_ptr->filter_type;
test_filter_type = *filter_type;
}
if (interlace_type != NULL) if (interlace_type != NULL)
{
*interlace_type = info_ptr->interlace_type; *interlace_type = info_ptr->interlace_type;
test_interlace_type = *interlace_type;
}
png_check_IHDR (png_ptr, *width, *height, *bit_depth, *color_type, /* This is redundant if we can be sure that the info_ptr values were all
test_interlace_type, test_compression_type, test_filter_type); * assigned in png_set_IHDR(). We do the check anyhow in case an
* application has ignored our advice not to mess with the members
* of info_ptr directly.
*/
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
info_ptr->compression_type, info_ptr->filter_type);
return (1); return (1);
} }

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.41 [September 30, 2009] * Last changed in libpng 1.2.41 [October 1, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson * Copyright (c) 1998-2009 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.)
@ -233,16 +233,18 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
png_check_IHDR (png_ptr, width, height, bit_depth, color_type,
interlace_type, compression_type, filter_type);
info_ptr->width = width; info_ptr->width = width;
info_ptr->height = height; info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth; info_ptr->bit_depth = (png_byte)bit_depth;
info_ptr->color_type =(png_byte) color_type; info_ptr->color_type = (png_byte)color_type;
info_ptr->compression_type = (png_byte)compression_type; info_ptr->compression_type = (png_byte)compression_type;
info_ptr->filter_type = (png_byte)filter_type; info_ptr->filter_type = (png_byte)filter_type;
info_ptr->interlace_type = (png_byte)interlace_type; info_ptr->interlace_type = (png_byte)interlace_type;
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
info_ptr->compression_type, info_ptr->filter_type);
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
info_ptr->channels = 1; info_ptr->channels = 1;
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)