[libpng16] Added an option to force maximum window size for inflating.
For inflate, reverted previous fixes. Added fixitxt and pngdeflate to the built programs and removed warnings from the source code and timepng that are revealed as a result. Fixed fixitxt when the chunk length is more than 65535 (untested, no test case).
This commit is contained in:
parent
db67cba8d4
commit
0c7ac064d3
9
ANNOUNCE
9
ANNOUNCE
@ -1,5 +1,5 @@
|
||||
|
||||
Libpng 1.6.3beta05 - May 7, 2013
|
||||
Libpng 1.6.3beta05 - May 8, 2013
|
||||
|
||||
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.
|
||||
@ -45,7 +45,7 @@ Version 1.6.3beta04 [May 6, 2013]
|
||||
Calculate our own zlib windowBits when decoding rather than trusting the
|
||||
CMF bytes in the PNG datastream.
|
||||
|
||||
Version 1.6.3beta05 [May 7, 2013]
|
||||
Version 1.6.3beta05 [May 8, 2013]
|
||||
Choose to use windowBits==15 or the zlib header setting via the
|
||||
benign-errors setting. If benign errors are allowed, then ignore
|
||||
the windowBits setting in the zlib header.
|
||||
@ -53,6 +53,11 @@ Version 1.6.3beta05 [May 7, 2013]
|
||||
undid the improvement in beta04.
|
||||
Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart).
|
||||
Ignore "#" delimited comments in input file to pnm2png.c.
|
||||
Added an option to force maximum window size for inflating. For inflate,
|
||||
reverted previous fixes.
|
||||
Added fixitxt and pngdeflate to the built programs and removed warnings
|
||||
from the source code and timepng that are revealed as a result. Fixed
|
||||
fixitxt when the chunk length is more than 65535 (untested, no test case).
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
7
CHANGES
7
CHANGES
@ -4528,7 +4528,7 @@ Version 1.6.3beta04 [May 6, 2013]
|
||||
Calculate our own zlib windowBits when decoding rather than trusting the
|
||||
CMF bytes in the PNG datastream.
|
||||
|
||||
Version 1.6.3beta05 [May 7, 2013]
|
||||
Version 1.6.3beta05 [May 8, 2013]
|
||||
Choose to use windowBits==15 or the zlib header setting via the
|
||||
benign-errors setting. If benign errors are allowed, then ignore
|
||||
the windowBits setting in the zlib header.
|
||||
@ -4536,6 +4536,11 @@ Version 1.6.3beta05 [May 7, 2013]
|
||||
undid the improvement in beta04.
|
||||
Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart).
|
||||
Ignore "#" delimited comments in input file to pnm2png.c.
|
||||
Added an option to force maximum window size for inflating. For inflate,
|
||||
reverted previous fixes.
|
||||
Added fixitxt and pngdeflate to the built programs and removed warnings
|
||||
from the source code and timepng that are revealed as a result. Fixed
|
||||
fixitxt when the chunk length is more than 65535 (untested, no test case).
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
11
Makefile.am
11
Makefile.am
@ -9,6 +9,9 @@ ACLOCAL_AMFLAGS = -I scripts
|
||||
# test programs - run on make check, make distcheck
|
||||
check_PROGRAMS= pngtest pngunknown pngstest pngvalid
|
||||
|
||||
# Utilities - installed
|
||||
bin_PROGRAMS= pngdeflate fixitxt
|
||||
|
||||
pngtest_SOURCES = pngtest.c
|
||||
pngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
@ -21,6 +24,11 @@ pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
pngunknown_SOURCES = contrib/libtests/pngunknown.c
|
||||
pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngdeflate_SOURCES = contrib/tools/pngdeflate.c
|
||||
pngdeflate_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
fixitxt_SOURCES = contrib/tools/fixitxt.c
|
||||
|
||||
# Generally these are single line shell scripts to run a test with a particular
|
||||
# set of parameters:
|
||||
TESTS =\
|
||||
@ -187,7 +195,8 @@ $(srcdir)/scripts/pnglibconf.h.prebuilt:
|
||||
# an installed one (this can happen immediately after on a clean system if
|
||||
# 'make test' is the first thing the user does.)
|
||||
contrib/libtests/pngstest.o contrib/libtests/pngvalid.o pngtest.o: pnglibconf.h
|
||||
contrib/libtests/pngunknown.o: pnglibconf.h
|
||||
contrib/libtests/pngunknown.o contrib/libtests/timepng.o: pnglibconf.h
|
||||
contrib/libtests/pngdeflate.o contrib/libtests/fixitxt.o: pnglibconf.h
|
||||
|
||||
# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually
|
||||
# be built with PNG_USE_READ_MACROS; this prevents the read macros from
|
||||
|
@ -24,18 +24,20 @@
|
||||
*
|
||||
* gcc -O -o fixitxt fixitxt.c -lz
|
||||
*/
|
||||
#include <zlib.h>
|
||||
|
||||
#define MAX_LENGTH 500000
|
||||
|
||||
#define GETBREAK c=getchar(); if (c == EOF) break;
|
||||
#include <zlib.h>
|
||||
#define GETBREAK ((unsigned char)(inchar=getchar())); if (inchar == EOF) break
|
||||
|
||||
main()
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char buf[MAX_LENGTH];
|
||||
unsigned long crc;
|
||||
unsigned int c;
|
||||
unsigned char c;
|
||||
int inchar;
|
||||
|
||||
/* Skip 8-byte signature */
|
||||
for (i=8; i; i--)
|
||||
@ -44,17 +46,16 @@ main()
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (c != EOF)
|
||||
if (inchar != EOF)
|
||||
for (;;)
|
||||
{
|
||||
/* Read the length */
|
||||
unsigned long length;
|
||||
c=GETBREAK; buf[0] = c;
|
||||
c=GETBREAK; buf[1] = c;
|
||||
c=GETBREAK; buf[2] = c;
|
||||
c=GETBREAK; buf[3] = c;
|
||||
unsigned long length; /* must be 32 bits! */
|
||||
c=GETBREAK; buf[0] = c; length = c; length <<= 8;
|
||||
c=GETBREAK; buf[1] = c; length += c; length <<= 8;
|
||||
c=GETBREAK; buf[2] = c; length += c; length <<= 8;
|
||||
c=GETBREAK; buf[3] = c; length += c;
|
||||
|
||||
length=((((unsigned long) buf[0]<<8 + buf[1]<<16) + buf[2] << 8) + buf[3]);
|
||||
/* Read the chunkname */
|
||||
c=GETBREAK; buf[4] = c;
|
||||
c=GETBREAK; buf[5] = c;
|
||||
@ -125,7 +126,7 @@ for (;;)
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (c == EOF)
|
||||
if (inchar == EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -135,10 +136,12 @@ for (;;)
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == EOF)
|
||||
if (inchar == EOF)
|
||||
break;
|
||||
|
||||
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1147
contrib/tools/pngdeflate.c
Normal file
1147
contrib/tools/pngdeflate.c
Normal file
File diff suppressed because it is too large
Load Diff
13
png.h
13
png.h
@ -1,7 +1,7 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng version 1.6.3beta05 - May 6, 2013
|
||||
* libpng version 1.6.3beta05 - May 8, 2013
|
||||
* Copyright (c) 1998-2013 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.6.3beta05 - May 6, 2013: Glenn
|
||||
* libpng versions 0.97, January 1998, through 1.6.3beta05 - May 8, 2013: Glenn
|
||||
* See also "Contributing Authors", below.
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
@ -207,7 +207,7 @@
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
*
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.6.3beta05, May 6, 2013, are
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.6.3beta05, May 8, 2013, are
|
||||
* Copyright (c) 2004, 2006-2013 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:
|
||||
@ -319,7 +319,7 @@
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* May 6, 2013
|
||||
* May 8, 2013
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
@ -387,7 +387,7 @@
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.6.3beta05"
|
||||
#define PNG_HEADER_VERSION_STRING \
|
||||
" libpng version 1.6.3beta05 - May 6, 2013\n"
|
||||
" libpng version 1.6.3beta05 - May 8, 2013\n"
|
||||
|
||||
#define PNG_LIBPNG_VER_SONUM 16
|
||||
#define PNG_LIBPNG_VER_DLLNUM 16
|
||||
@ -3268,7 +3268,8 @@ PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr,
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */
|
||||
#endif
|
||||
#define PNG_OPTION_NEXT 2 /* Next option - numbers must be even */
|
||||
#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */
|
||||
#define PNG_OPTION_NEXT 4 /* Next option - numbers must be even */
|
||||
|
||||
/* Return values: NOTE: there are four values and 'off' is *not* zero */
|
||||
#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */
|
||||
|
142
pngrutil.c
142
pngrutil.c
@ -332,7 +332,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
|
||||
* chunk apparently owns the stream. Prior to release it does a png_error.
|
||||
*/
|
||||
static int
|
||||
png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
||||
{
|
||||
if (png_ptr->zowner != 0)
|
||||
{
|
||||
@ -367,6 +367,21 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
*/
|
||||
{
|
||||
int ret; /* zlib return code */
|
||||
# if ZLIB_VERNUM >= 0x1240
|
||||
|
||||
# ifdef PNG_SET_OPTION_SUPPORTED
|
||||
int window_bits;
|
||||
|
||||
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
|
||||
PNG_OPTION_ON)
|
||||
window_bits = 15;
|
||||
|
||||
else
|
||||
window_bits = 0;
|
||||
# else
|
||||
# define window_bits 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Set this for safety, just in case the previous owner left pointers to
|
||||
* memory allocations.
|
||||
@ -379,7 +394,6 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED)
|
||||
{
|
||||
# if ZLIB_VERNUM < 0x1240
|
||||
PNG_UNUSED(window_bits)
|
||||
ret = inflateReset(&png_ptr->zstream);
|
||||
# else
|
||||
ret = inflateReset2(&png_ptr->zstream, window_bits);
|
||||
@ -406,6 +420,10 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
# ifdef window_bits
|
||||
# undef window_bits
|
||||
# endif
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
|
||||
@ -578,14 +596,8 @@ png_decompress_chunk(png_structrp png_ptr,
|
||||
if (limit < *newlength)
|
||||
*newlength = limit;
|
||||
|
||||
/* Now try to claim the stream; the 'warn' setting causes zlib to be told
|
||||
* to use the maximum window size during inflate; this hides errors in the
|
||||
* deflate header window bits value which is used if '0' is passed. In
|
||||
* fact this only has an effect with zlib versions 1.2.4 and later - see
|
||||
* the comments in png_inflate_claim above.
|
||||
*/
|
||||
ret = png_inflate_claim(png_ptr, png_ptr->chunk_name,
|
||||
png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0);
|
||||
/* Now try to claim the stream. */
|
||||
ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
|
||||
|
||||
if (ret == Z_OK)
|
||||
{
|
||||
@ -1355,8 +1367,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
{
|
||||
read_length -= keyword_length+2;
|
||||
|
||||
if (png_inflate_claim(png_ptr, png_iCCP,
|
||||
png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0) == Z_OK)
|
||||
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
|
||||
{
|
||||
Byte profile_header[132];
|
||||
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
|
||||
@ -4163,77 +4174,6 @@ png_read_finish_row(png_structrp png_ptr)
|
||||
}
|
||||
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
|
||||
|
||||
#ifdef PNG_READ_OPTIMIZE_WINDOWBITS_SUPPORTED
|
||||
#if ZLIB_VERNUM > 0x1280
|
||||
/* This is the code to to select a windowBits value to match the smallest
|
||||
* possible sliding window needed to contain the entire uncompressed image.
|
||||
*/
|
||||
static unsigned int
|
||||
required_window_bits(png_alloc_size_t data_size)
|
||||
{
|
||||
unsigned int windowBits = 15;
|
||||
if (data_size <= 16384) /* else windowBits must be 15 */
|
||||
{
|
||||
unsigned int half_z_window_size = 1U << (windowBits-1); /* 16384 */
|
||||
|
||||
do
|
||||
{
|
||||
half_z_window_size >>= 1;
|
||||
--windowBits;
|
||||
}
|
||||
while (windowBits > 8 && data_size <= half_z_window_size);
|
||||
}
|
||||
return windowBits;
|
||||
}
|
||||
/* This is used below to find the size of an image to pass to png_deflate_claim,
|
||||
* so it only needs to be accurate if the size is less than 16384 bytes (the
|
||||
* point at which a lower LZ window size can be used.)
|
||||
*
|
||||
* To do: merge this with png_image_size() in pngwutil.c and put the result
|
||||
* in png.c as a PNG_INTERNAL_FUNCTION.
|
||||
*/
|
||||
static png_alloc_size_t
|
||||
png_read_image_size(png_structrp png_ptr)
|
||||
{
|
||||
/* Only return sizes up to the maximum of a png_uint_32, do this by limiting
|
||||
* the width and height used to 15 bits.
|
||||
*/
|
||||
png_uint_32 h = png_ptr->height;
|
||||
|
||||
if (png_ptr->rowbytes < 32768 && h < 32768)
|
||||
{
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
/* Interlacing makes the image larger because of the replication of
|
||||
* both the filter byte and the padding to a byte boundary.
|
||||
*/
|
||||
png_uint_32 w = png_ptr->width;
|
||||
unsigned int pd = png_ptr->pixel_depth;
|
||||
png_alloc_size_t cb_base;
|
||||
int pass;
|
||||
|
||||
for (cb_base=0, pass=0; pass<=6; ++pass)
|
||||
{
|
||||
png_uint_32 pw = PNG_PASS_COLS(w, pass);
|
||||
|
||||
if (pw > 0)
|
||||
cb_base += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass);
|
||||
}
|
||||
|
||||
return cb_base;
|
||||
}
|
||||
|
||||
else
|
||||
return (png_ptr->rowbytes+1) * h;
|
||||
}
|
||||
|
||||
else
|
||||
return 0xffffffffU;
|
||||
}
|
||||
|
||||
#endif /* ZLIB_VERNUM */
|
||||
#endif /* PNG_READ_OPTIMIZE_WINDOWBITS_SUPPORTED */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_read_start_row(png_structrp png_ptr)
|
||||
{
|
||||
@ -4518,37 +4458,13 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_free(png_ptr, buffer);
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_OPTIMIZE_WINDOWBITS_SUPPORTED
|
||||
/* To do in libpng17: get windowBits from the CMF bytes and select the
|
||||
* smaller of that and the required_window_bits. Requires a one-byte
|
||||
* lookahead into the first IDAT chunk data, and requires actually
|
||||
* injecting the revised CMF bytes into the datastream before reading.
|
||||
/* Finally claim the zstream for the inflate of the IDAT data, use the bits
|
||||
* value from the stream (note that this will result in a fatal error if the
|
||||
* IDAT stream has a bogus deflate header window_bits value, but this should
|
||||
* not be happening any longer!)
|
||||
*/
|
||||
{
|
||||
#if ZLIB_VERNUM < 0x1290
|
||||
unsigned int windowBits;
|
||||
#endif /* ZLIB_VERNUM */
|
||||
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
{
|
||||
#if ZLIB_VERNUM < 0x1290
|
||||
windowBits=15;
|
||||
#else
|
||||
/* Compute required windowBits from the image size, pixel size, and
|
||||
* interlacing setting.
|
||||
*/
|
||||
windowBits=required_window_bits(png_read_image_size(png_ptr));
|
||||
#endif /* ZLIB_VERNUM */
|
||||
}
|
||||
|
||||
else
|
||||
#endif
|
||||
windowBits=0; /* Use the setting from the zlib CMF bytes */
|
||||
|
||||
/* Finally claim the zstream for the inflate of the IDAT data */
|
||||
if (png_inflate_claim(png_ptr, png_IDAT, windowBits) != Z_OK)
|
||||
png_error(png_ptr, png_ptr->zstream.msg);
|
||||
}
|
||||
if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK)
|
||||
png_error(png_ptr, png_ptr->zstream.msg);
|
||||
|
||||
png_ptr->flags |= PNG_FLAG_ROW_INIT;
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ option SAFE_LIMITS enables USER_LIMITS disabled
|
||||
# to libpng 1.6; the new interfaces in 1.6 will take several years to become
|
||||
# popular.
|
||||
|
||||
option READ enables READ_INTERLACING
|
||||
option READ enables READ_INTERLACING SET_OPTION
|
||||
|
||||
# Disabling READ_16BIT does not disable reading 16-bit PNG files, but it
|
||||
# forces them to be chopped down to 8-bit, and disables any 16-bit
|
||||
@ -826,9 +826,6 @@ option GET_PALETTE_MAX enables READ_GET_PALETTE_MAX WRITE_GET_PALETTE_MAX
|
||||
option READ_GET_PALETTE_MAX requires READ_CHECK_FOR_INVALID_INDEX disabled
|
||||
option WRITE_GET_PALETTE_MAX requires WRITE_CHECK_FOR_INVALID_INDEX disabled
|
||||
|
||||
# added at libpng-1.6.3
|
||||
option READ_OPTIMIZE_WINDOWBITS requires READ
|
||||
|
||||
# Simplified API options (added at libpng-1.6.0)
|
||||
# Read:
|
||||
option SIMPLIFIED_READ,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* pnglibconf.h - library build configuration */
|
||||
|
||||
/* Libpng version 1.6.3beta05 - May 6, 2013 */
|
||||
/* Libpng version 1.6.3beta05 - May 8, 2013 */
|
||||
|
||||
/* Copyright (c) 1998-2013 Glenn Randers-Pehrson */
|
||||
|
||||
@ -105,10 +105,9 @@
|
||||
#define PNG_SETJMP_SUPPORTED
|
||||
#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
|
||||
#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
|
||||
/*#undef PNG_SET_OPTION_SUPPORTED*/
|
||||
#define PNG_SET_OPTION_SUPPORTED
|
||||
#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
#define PNG_SET_USER_LIMITS_SUPPORTED
|
||||
#define PNG_READ_OPTIMIZE_WINDOWBITS_SUPPORTED
|
||||
#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
|
||||
#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
|
||||
#define PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
|
Loading…
Reference in New Issue
Block a user