mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[master] Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
Moved reading of file signature into png_read_sig (Cosmin) Fixed atomicity of chunk header serialization (Cosmin) Added test for io_state in pngtest.c (Cosmin) Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts.
This commit is contained in:
parent
d801b3882c
commit
a581556b17
11
ANNOUNCE
11
ANNOUNCE
@ -1,5 +1,5 @@
|
||||
|
||||
Libpng 1.5.0beta55 - November 11, 2010
|
||||
Libpng 1.5.0beta55 - November 21, 2010
|
||||
|
||||
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.
|
||||
@ -226,7 +226,7 @@ version 1.5.0beta24 [May 7, 2010]
|
||||
offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf.
|
||||
Added more blank lines for readability.
|
||||
|
||||
version 1.5.0beta25 [November 11, 2010]
|
||||
version 1.5.0beta25 [November 21, 2010]
|
||||
In pngpread.c: png_push_have_row() add check for new_row > height
|
||||
Removed the now-redundant check for out-of-bounds new_row from example.c
|
||||
|
||||
@ -436,7 +436,12 @@ Version 1.5.0beta54 [November 10, 2010]
|
||||
Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks.
|
||||
Used a consistent structure for the pngget.c functions.
|
||||
|
||||
Version 1.5.0beta55 [November 11, 2010]
|
||||
Version 1.5.0beta55 [November 21, 2010]
|
||||
Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
|
||||
Moved reading of file signature into png_read_sig (Cosmin)
|
||||
Fixed atomicity of chunk header serialization (Cosmin)
|
||||
Added test for io_state in pngtest.c (Cosmin)
|
||||
Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
|
||||
(subscription required; visit
|
||||
|
||||
7
CHANGES
7
CHANGES
@ -3074,7 +3074,12 @@ Version 1.5.0beta54 [November 10, 2010]
|
||||
Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks.
|
||||
Used a consistent structure for the pngget.c functions.
|
||||
|
||||
Version 1.5.0beta55 [November 11, 2010]
|
||||
Version 1.5.0beta55 [November 21, 2010]
|
||||
Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
|
||||
Moved reading of file signature into png_read_sig (Cosmin)
|
||||
Fixed atomicity of chunk header serialization (Cosmin)
|
||||
Added test for io_state in pngtest.c (Cosmin)
|
||||
Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
||||
42
libpngpf.3
42
libpngpf.3
@ -1,4 +1,4 @@
|
||||
.TH LIBPNGPF 3 "November 11, 2010"
|
||||
.TH LIBPNGPF 3 "November 21, 2010"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.5.0beta55
|
||||
(private functions)
|
||||
@ -685,62 +685,38 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.5.0beta55
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBpng_fixed_point png_reciprocal (png_fixed_point \fIa\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBpng_fixed_point png_reciprocal2 (png_fixed_point \fP\fIa\fP\fB, png_fixed_point \fIb\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBint png_set_text_2 (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@ -921,17 +897,7 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.5.0beta55
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fB\fBvoid png_fixed_error (png_structp \fI\fP\fIpng_ptr\fP\fB,
|
||||
|
||||
\fBpng_const_charp \fP\fI\fP\fIname\fP\fB\fP\fB, double \fI\fP\fIvalue\fP\fB\fP\fB);\fP\fP
|
||||
|
||||
\fI\fB\fI\fB
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fI\fB\fI\fB
|
||||
\fBvoid png_fixed_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, double \fIvalue\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
|
||||
4
png.c
4
png.c
@ -556,13 +556,13 @@ png_get_copyright(png_structp png_ptr)
|
||||
#else
|
||||
# ifdef __STDC__
|
||||
return PNG_STRING_NEWLINE \
|
||||
"libpng version 1.5.0beta55 - November 11, 2010" PNG_STRING_NEWLINE \
|
||||
"libpng version 1.5.0beta55 - November 21, 2010" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1998-2010 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.5.0beta55 - November 11, 2010\
|
||||
return "libpng version 1.5.0beta55 - November 21, 2010\
|
||||
Copyright (c) 1998-2010 Glenn Randers-Pehrson\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
|
||||
|
||||
17
png.h
17
png.h
@ -1,7 +1,7 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng version 1.5.0beta55 - November 11, 2010
|
||||
* libpng version 1.5.0beta55 - November 21, 2010
|
||||
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
@ -11,7 +11,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.5.0beta55 - November 11, 2010: Glenn
|
||||
* libpng versions 0.97, January 1998, through 1.5.0beta55 - November 21, 2010: Glenn
|
||||
* See also "Contributing Authors", below.
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
@ -172,7 +172,7 @@
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
*
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.5.0beta55, November 11, 2010, are
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.5.0beta55, November 21, 2010, are
|
||||
* Copyright (c) 2004, 2006-2010 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:
|
||||
@ -284,7 +284,7 @@
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* November 11, 2010
|
||||
* November 21, 2010
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
@ -348,7 +348,7 @@
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.5.0beta55"
|
||||
#define PNG_HEADER_VERSION_STRING \
|
||||
" libpng version 1.5.0beta55 - November 11, 2010\n"
|
||||
" libpng version 1.5.0beta55 - November 21, 2010\n"
|
||||
|
||||
#define PNG_LIBPNG_VER_SONUM 15
|
||||
#define PNG_LIBPNG_VER_DLLNUM 15
|
||||
@ -2044,11 +2044,12 @@ PNG_EXPORT(png_const_bytep,png_get_io_chunk_name,(png_structp png_ptr),,200);
|
||||
((png_uint_32)(*((buf) + 2)) << 8) + \
|
||||
((png_uint_32)(*((buf) + 3))))
|
||||
# define png_get_uint_16(buf) \
|
||||
(((png_uint_32)(*(buf)) << 8) + \
|
||||
((png_uint_32)(*((buf) + 1))))
|
||||
((png_uint_16) \
|
||||
(((unsigned int)(*(buf)) << 8) + \
|
||||
((unsigned int)(*((buf) + 1)))))
|
||||
# define png_get_int_32(buf) \
|
||||
((png_int_32)((*(buf) & 0x80) \
|
||||
? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffff)+1)) \
|
||||
? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
|
||||
: (png_int_32)png_get_uint_32(buf)))
|
||||
#endif
|
||||
|
||||
|
||||
@ -511,6 +511,9 @@ PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
|
||||
PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
|
||||
png_const_bytep data, png_size_t length));
|
||||
|
||||
/* Read and check the PNG file signature */
|
||||
PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
|
||||
|
||||
/* Read the chunk header (length + type name) */
|
||||
PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
|
||||
|
||||
|
||||
28
pngread.c
28
pngread.c
@ -232,32 +232,8 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
/* If we haven't checked all of the PNG signature bytes, do so now. */
|
||||
if (png_ptr->sig_bytes < 8)
|
||||
{
|
||||
png_size_t num_checked = png_ptr->sig_bytes,
|
||||
num_to_check = 8 - num_checked;
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
|
||||
#endif
|
||||
|
||||
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
|
||||
png_ptr->sig_bytes = 8;
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
{
|
||||
if (num_checked < 4 &&
|
||||
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
||||
png_error(png_ptr, "Not a PNG file");
|
||||
|
||||
else
|
||||
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
||||
}
|
||||
|
||||
if (num_checked < 3)
|
||||
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
|
||||
}
|
||||
/* Read and check the PNG file signature. */
|
||||
png_read_sig(png_ptr, info_ptr);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
||||
103
pngrutil.c
103
pngrutil.c
@ -23,12 +23,12 @@
|
||||
png_uint_32 PNGAPI
|
||||
png_get_uint_31(png_structp png_ptr, png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 i = png_get_uint_32(buf);
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
|
||||
if (i > PNG_UINT_31_MAX)
|
||||
if (uval > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "PNG unsigned integer out of range");
|
||||
|
||||
return (i);
|
||||
return (uval);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
|
||||
@ -42,10 +42,10 @@ png_get_uint_31(png_structp png_ptr, png_const_bytep buf)
|
||||
static png_fixed_point /* PRIVATE */
|
||||
png_get_fixed_point(png_structp png_ptr, png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 u = png_get_uint_32(buf);
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
|
||||
if (u <= PNG_UINT_31_MAX)
|
||||
return (png_fixed_point)u; /* known to be in range */
|
||||
if (uval <= PNG_UINT_31_MAX)
|
||||
return (png_fixed_point)uval; /* known to be in range */
|
||||
|
||||
/* The caller can turn off the warning by passing NULL. */
|
||||
if (png_ptr != NULL)
|
||||
@ -58,19 +58,21 @@ png_get_fixed_point(png_structp png_ptr, png_const_bytep buf)
|
||||
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
|
||||
/* NOTE: the read macros will obscure these definitions, so that if
|
||||
* PNG_USE_READ_MACROS is set the library will not use them internally,
|
||||
* but the APIs will still be available externally.
|
||||
* but the APIs will still be available externally. The parentheses
|
||||
* around "PNGAPI function_name" are necessary because ...
|
||||
*/
|
||||
|
||||
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
|
||||
png_uint_32 (PNGAPI
|
||||
png_get_uint_32)(png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 i =
|
||||
png_uint_32 uval =
|
||||
((png_uint_32)(*(buf )) << 24) +
|
||||
((png_uint_32)(*(buf + 1)) << 16) +
|
||||
((png_uint_32)(*(buf + 2)) << 8) +
|
||||
((png_uint_32)(*(buf + 3)) ) ;
|
||||
|
||||
return (i);
|
||||
return uval;
|
||||
}
|
||||
|
||||
/* Grab a signed 32-bit integer from a buffer in big-endian format. The
|
||||
@ -81,26 +83,60 @@ png_get_uint_32)(png_const_bytep buf)
|
||||
png_int_32 (PNGAPI
|
||||
png_get_int_32)(png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 u = png_get_uint_32(buf);
|
||||
if ((u & 0x80000000) == 0) /* non-negative */
|
||||
return u;
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
if ((uval & 0x80000000L) == 0) /* non-negative */
|
||||
return uval;
|
||||
|
||||
u = (u ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
|
||||
return -(png_int_32)u;
|
||||
uval = (uval ^ 0xffffffffL) + 1; /* 2's complement: -x = ~x+1 */
|
||||
return -(png_int_32)uval;
|
||||
}
|
||||
|
||||
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
|
||||
png_uint_16 (PNGAPI
|
||||
png_get_uint_16)(png_const_bytep buf)
|
||||
{
|
||||
png_uint_16 i =
|
||||
((png_uint_32)(*buf) << 8) +
|
||||
((png_uint_32)(*(buf + 1)));
|
||||
unsigned int val =
|
||||
((unsigned int)(*buf) << 8) +
|
||||
((unsigned int)(*(buf + 1)));
|
||||
|
||||
return (i);
|
||||
return (png_uint_16)val;
|
||||
}
|
||||
|
||||
#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */
|
||||
|
||||
/* Read and check the PNG file signature */
|
||||
void /* PRIVATE */
|
||||
png_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_size_t num_checked, num_to_check;
|
||||
|
||||
/* Exit if the user application does not expect a signature. */
|
||||
if (png_ptr->sig_bytes >= 8)
|
||||
return;
|
||||
|
||||
num_checked = png_ptr->sig_bytes;
|
||||
num_to_check = 8 - num_checked;
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
|
||||
#endif
|
||||
|
||||
/* The signature must be serialized in a single I/O call. */
|
||||
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
|
||||
png_ptr->sig_bytes = 8;
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
{
|
||||
if (num_checked < 4 &&
|
||||
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
||||
png_error(png_ptr, "Not a PNG file");
|
||||
else
|
||||
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
||||
}
|
||||
if (num_checked < 3)
|
||||
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
|
||||
}
|
||||
|
||||
/* Read the chunk header (length + type name).
|
||||
* Put the type name into png_ptr->chunk_name, and return the length.
|
||||
*/
|
||||
@ -111,33 +147,29 @@ png_read_chunk_header(png_structp png_ptr)
|
||||
png_uint_32 length;
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that the chunk header is being read.
|
||||
* PNG_IO_CHUNK_HDR requires a single I/O call.
|
||||
*/
|
||||
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
|
||||
#endif
|
||||
|
||||
/* Read the length and the chunk name */
|
||||
/* Read the length and the chunk name.
|
||||
* This must be performed in a single I/O call.
|
||||
*/
|
||||
png_read_data(png_ptr, buf, 8);
|
||||
length = png_get_uint_31(png_ptr, buf);
|
||||
|
||||
/* Put the chunk name into png_ptr->chunk_name */
|
||||
/* 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 = %u",
|
||||
png_ptr->chunk_name, length);
|
||||
|
||||
/* 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_calculate_crc(png_ptr, png_ptr->chunk_name, 4);
|
||||
|
||||
/* Check to see if chunk name is valid */
|
||||
/* Check to see if chunk name is valid. */
|
||||
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that chunk data will (possibly) be read.
|
||||
* PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls.
|
||||
*/
|
||||
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
|
||||
#endif
|
||||
|
||||
@ -222,11 +254,10 @@ png_crc_error(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that the chunk CRC is being read */
|
||||
/* PNG_IO_CHUNK_CRC requires the I/O to be done at once */
|
||||
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
|
||||
#endif
|
||||
|
||||
/* The chunk CRC must be serialized in a single I/O call. */
|
||||
png_read_data(png_ptr, crc_bytes, 4);
|
||||
|
||||
if (need_crc)
|
||||
@ -3284,18 +3315,10 @@ png_read_finish_row(png_structp png_ptr)
|
||||
{
|
||||
while (!png_ptr->idat_size)
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
|
||||
png_read_data(png_ptr, chunk_length, 4);
|
||||
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);
|
||||
|
||||
png_ptr->idat_size = png_read_chunk_header(png_ptr);
|
||||
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
png_error(png_ptr, "Not enough image data");
|
||||
|
||||
}
|
||||
|
||||
png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
|
||||
@ -3307,6 +3330,7 @@ png_read_finish_row(png_structp png_ptr)
|
||||
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
|
||||
png_ptr->idat_size -= png_ptr->zstream.avail_in;
|
||||
}
|
||||
|
||||
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
|
||||
|
||||
if (ret == Z_STREAM_END)
|
||||
@ -3319,6 +3343,7 @@ png_read_finish_row(png_structp png_ptr)
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != Z_OK)
|
||||
png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
|
||||
"Decompression Error");
|
||||
|
||||
62
pngtest.c
62
pngtest.c
@ -299,6 +299,48 @@ static int wrote_question = 0;
|
||||
* than changing the library.
|
||||
*/
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
void
|
||||
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||
png_uint_32 io_op);
|
||||
void
|
||||
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||
png_uint_32 io_op)
|
||||
{
|
||||
png_uint_32 io_state = png_get_io_state(png_ptr);
|
||||
int err = 0;
|
||||
|
||||
/* Check if the current operation (reading / writing) is as expected. */
|
||||
if ((io_state & PNG_IO_MASK_OP) != io_op)
|
||||
png_error(png_ptr, "Incorrect operation in I/O state");
|
||||
|
||||
/* Check if the buffer size specific to the current location
|
||||
* (file signature / header / data / crc) is as expected.
|
||||
*/
|
||||
switch (io_state & PNG_IO_MASK_LOC)
|
||||
{
|
||||
case PNG_IO_SIGNATURE:
|
||||
if (data_length > 8)
|
||||
err = 1;
|
||||
break;
|
||||
case PNG_IO_CHUNK_HDR:
|
||||
if (data_length != 8)
|
||||
err = 1;
|
||||
break;
|
||||
case PNG_IO_CHUNK_DATA:
|
||||
break; /* no restrictions here */
|
||||
case PNG_IO_CHUNK_CRC:
|
||||
if (data_length != 4)
|
||||
err = 1;
|
||||
break;
|
||||
default:
|
||||
err = 1; /* uninitialized */
|
||||
}
|
||||
if (err)
|
||||
png_error(png_ptr, "Bad I/O state or buffer size");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
static void PNGCBAPI
|
||||
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
@ -317,8 +359,12 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Read Error!");
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
/* This is the model-independent version. Since the standard I/O library
|
||||
@ -366,7 +412,11 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
|
||||
if (check != length)
|
||||
png_error(png_ptr, "read Error");
|
||||
png_error(png_ptr, "Read Error");
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
|
||||
#endif
|
||||
}
|
||||
#endif /* USE_FAR_KEYWORD */
|
||||
|
||||
@ -396,6 +446,10 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
/* This is the model-independent version. Since the standard I/O library
|
||||
@ -448,6 +502,10 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
||||
#endif
|
||||
}
|
||||
#endif /* USE_FAR_KEYWORD */
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user