[master] Revised png_push_save_buffer() to do fewer but larger png_mallocs

Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as
png_ptr->png_user_chunk_malloc_max.
This commit is contained in:
Glenn Randers-Pehrson 2010-02-06 12:15:07 -06:00
parent f3c42680db
commit 4bd73b6947
12 changed files with 93 additions and 60 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.4.1beta07 - February 5, 2010
Libpng 1.4.1beta07 - February 6, 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.
@ -59,8 +59,12 @@ version 1.4.1beta06 [January 28, 2010]
Revised png_decompress_chunk() to use a two-pass method suggested by
John Bowler.
version 1.4.1beta07 [February 5, 2010]
version 1.4.1beta07 [February 6, 2010]
Folded some long lines in the source files.
Added defineable PNG_USER_CHUNK_CACHE_MAX and PNG_USER_CHUNK_MALLOC_MAX
Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as
png_ptr->png_user_chunk_malloc_max.
Revised png_push_save_buffer() to do fewer but larger png_malloc() calls.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

10
CHANGES
View File

@ -2491,9 +2491,13 @@ version 1.4.1beta06 [January 28, 2010]
Revised png_decompress_chunk() to use a two-pass method suggested by
John Bowler.
version 1.4.1beta07 [February 5, 2010]
Folded some long lines in png.h
Added defineable PNG_USER_CHUNK_CACHE_MAX and PNG_USER_CHUNK_MALLOC_MAX
version 1.4.1beta07 [February 6, 2010]
Folded some long lines in the source files.
Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX,
and a PNG_USER_LIMITS_SUPPORTED flag.
Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as
png_ptr->png_user_chunk_malloc_max.
Revised png_push_save_buffer() to do fewer but larger png_malloc() calls.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -69,5 +69,7 @@
#define PNG_NO_ERROR_NUMBERS
#define PNG_NO_EASY_ACCESS
#define PNG_NO_PROGRESSIVE_READ
#define PNG_NO_USER_LIMITS
#define PNG_NO_SET_USER_LIMITS
#endif /* MINRDPNGCONF_H */

View File

@ -67,5 +67,7 @@
#define PNG_NO_ZALLOC_ZERO
#define PNG_NO_ERROR_NUMBERS
#define PNG_NO_EASY_ACCESS
#define PNG_NO_USER_LIMITS
#define PNG_NO_SET_USER_LIMITS
#endif /* MINWRPNGCONF_H */

View File

@ -59,5 +59,7 @@
#define PNG_NO_ZALLOC_ZERO
#define PNG_NO_ERROR_NUMBERS
#define PNG_NO_EASY_ACCESS
#define PNG_NO_USER_LIMITS
#define PNG_NO_SET_USER_LIMITS
#endif /* MINPRDPNGCONF_H */

View File

@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng
libpng version 1.4.1beta07 - February 5, 2010
libpng version 1.4.1beta07 - February 6, 2010
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -11,7 +11,7 @@ libpng.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.4.1beta07 - February 5, 2010
libpng versions 0.97, January 1998, through 1.4.1beta07 - February 6, 2010
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -3245,7 +3245,7 @@ Other rules can be inferred by inspecting the libpng source.
XIII. Y2K Compliance in libpng
February 5, 2010
February 6, 2010
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.

View File

@ -1,4 +1,4 @@
.TH LIBPNG 3 "February 5, 2010"
.TH LIBPNG 3 "February 6, 2010"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta07
.SH SYNOPSIS
@ -192,7 +192,7 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta07
\fI\fB
\fBpng_uint_32 png_get_chunk_malloc_max (png_structp \fIpng_ptr\fP\fB);\fP
\fBpng_alloc_size_t png_get_chunk_malloc_max (png_structp \fIpng_ptr\fP\fB);\fP
\fI\fB
@ -542,7 +542,7 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta07
\fI\fB
\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
\fI\fB
@ -785,7 +785,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng
libpng version 1.4.1beta07 - February 5, 2010
libpng version 1.4.1beta07 - February 6, 2010
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -796,7 +796,7 @@ libpng.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.4.1beta07 - February 5, 2010
libpng versions 0.97, January 1998, through 1.4.1beta07 - February 6, 2010
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2009 Glenn Randers-Pehrson
@ -4030,7 +4030,7 @@ Other rules can be inferred by inspecting the libpng source.
.SH XIII. Y2K Compliance in libpng
February 5, 2010
February 6, 2010
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
@ -4211,7 +4211,7 @@ the first widely used release:
1.4.0 14 10400 14.so.14.0[.0]
1.4.1beta01-03 14 10401 14.so.14.1[.0]
1.4.1rc01 14 10401 14.so.14.1[.0]
1.4.1beta04 14 10401 14.so.14.1[.0]
1.4.1beta04-07 14 10401 14.so.14.1[.0]
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
@ -4267,7 +4267,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.4.1beta07 - February 5, 2010:
Libpng version 1.4.1beta07 - February 6, 2010:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@ -4290,7 +4290,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.4.1beta07, February 5, 2010, are
libpng versions 1.2.6, August 15, 2004, through 1.4.1beta07, February 6, 2010, are
Copyright (c) 2004,2006-2007 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
@ -4389,7 +4389,7 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
February 5, 2010
February 6, 2010
.\" end of man page

View File

@ -1,4 +1,4 @@
.TH LIBPNGPF 3 "February 5, 2010"
.TH LIBPNGPF 3 "February 6, 2010"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta07
(private functions)

47
png.h
View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.4.1beta07 - February 5, 2010
* libpng version 1.4.1beta07 - February 6, 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.4.1beta07 - February 5, 2010: Glenn
* libpng versions 0.97, January 1998, through 1.4.1beta07 - February 6, 2010: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@ -136,7 +136,7 @@
* 1.4.0 14 10400 14.so.14.0[.0]
* 1.4.1beta01-03 14 10401 14.so.14.1[.0]
* 1.4.1rc01 14 10401 14.so.14.1[.0]
* 1.4.1beta04 14 10401 14.so.14.1[.0]
* 1.4.1beta04-07 14 10401 14.so.14.1[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@ -168,7 +168,7 @@
*
* This code is released under the libpng license.
*
* libpng versions 1.2.6, August 15, 2004, through 1.4.1beta07, February 5, 2010, are
* libpng versions 1.2.6, August 15, 2004, through 1.4.1beta07, February 6, 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:
@ -280,7 +280,7 @@
* Y2K compliance in libpng:
* =========================
*
* February 5, 2010
* February 6, 2010
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
@ -344,7 +344,7 @@
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.4.1beta07"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.4.1beta07 - February 5, 2010\n"
" libpng version 1.4.1beta07 - February 6, 2010\n"
#define PNG_LIBPNG_VER_SONUM 14
#define PNG_LIBPNG_VER_DLLNUM 14
@ -1095,7 +1095,8 @@ struct png_struct_def
#endif
png_error_ptr error_fn PNG_DEPSTRUCT; /* function for printing
errors and aborting */
png_error_ptr warning_fn PNG_DEPSTRUCT; /* function for printing warnings */
png_error_ptr warning_fn PNG_DEPSTRUCT; /* function for printing
warnings */
png_voidp error_ptr PNG_DEPSTRUCT; /* user supplied struct for
error functions */
png_rw_ptr write_data_fn PNG_DEPSTRUCT; /* function for writing
@ -1107,12 +1108,12 @@ struct png_struct_def
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
png_user_transform_ptr read_user_transform_fn PNG_DEPSTRUCT; /* user read
transform */
transform */
#endif
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
png_user_transform_ptr write_user_transform_fn PNG_DEPSTRUCT; /* user write
transform */
transform */
#endif
/* These were added in libpng-1.0.2 */
@ -1153,8 +1154,18 @@ struct png_struct_def
png_uint_32 num_rows PNG_DEPSTRUCT; /* number of rows in current pass */
png_uint_32 usr_width PNG_DEPSTRUCT; /* width of row at start of write */
png_size_t rowbytes PNG_DEPSTRUCT; /* size of row in bytes */
png_size_t irowbytes PNG_DEPSTRUCT; /* size of current interlaced row
in bytes */
#if 0 /* Replaced with the following in libpng-1.4.1 */
png_size_t irowbytes PNG_DEPSTRUCT;
#endif
/* Added in libpng-1.4.1 */
#ifdef PNG_USER_LIMITS_SUPPORTED
/* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
* can occupy when decompressed. 0 means unlimited.
* We will change the typedef from png_size_t to png_alloc_size_t
* in libpng-1.5.0
*/
png_size_t user_chunk_malloc_max PNG_DEPSTRUCT;
#endif
png_uint_32 iwidth PNG_DEPSTRUCT; /* width of current interlaced
row in pixels */
png_uint_32 row_number PNG_DEPSTRUCT; /* current row in interlace pass */
@ -1427,7 +1438,7 @@ struct png_struct_def
/* New members added in libpng-1.0.16 and 1.2.6 */
png_byte compression_type PNG_DEPSTRUCT;
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
#ifdef PNG_USER_LIMITS_SUPPORTED
png_uint_32 user_width_max PNG_DEPSTRUCT;
png_uint_32 user_height_max PNG_DEPSTRUCT;
/* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
@ -1453,14 +1464,6 @@ struct png_struct_def
/* New member added in libpng-1.4.0 */
png_uint_32 io_state PNG_DEPSTRUCT;
#endif
/* Added in libpng-1.4.1 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
* can occupy when decompressed. 0 means unlimited.
*/
png_uint_32 user_chunk_malloc_max PNG_DEPSTRUCT;
#endif
};
@ -2525,8 +2528,8 @@ extern PNG_EXPORT(png_uint_32,png_get_chunk_cache_max)
PNGARG((png_structp png_ptr));
/* Added in libpng-1.4.1 */
extern PNG_EXPORT(void,png_set_chunk_malloc_max) PNGARG((png_structp
png_ptr, png_uint_32 user_chunk_cache_max));
extern PNG_EXPORT(png_uint_32,png_get_chunk_malloc_max)
png_ptr, png_alloc_size_t user_chunk_cache_max));
extern PNG_EXPORT(png_alloc_size_t,png_get_chunk_malloc_max)
PNGARG((png_structp png_ptr));
#endif

View File

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.4.1beta07 - February 5, 2010
* libpng version 1.4.1beta07 - February 6, 2010
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -684,10 +684,17 @@
# endif
#endif
/* Added at libpng-1.2.43 */
#ifndef PNG_USER_LIMITS_SUPPORTED
# ifndef PNG_NO_USER_LIMITS
# define PNG_USER_LIMITS_SUPPORTED
# endif
#endif
/* Added at libpng-1.2.43 */
/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGs no matter
* how large, set these limits to 0x7fffffffL
* how large, set these two limits to 0x7fffffffL
*/
#ifndef PNG_USER_WIDTH_MAX
# define PNG_USER_WIDTH_MAX 1000000L
@ -696,14 +703,16 @@
# define PNG_USER_HEIGHT_MAX 1000000L
#endif
/* Added at libpng-1.2.43 */
/* Added at libpng-1.2.43. To accept all valid PNGs no matter
* how large, set these two limits to 0.
*/
#ifndef PNG_USER_CHUNK_CACHE_MAX
# define PNG_USER_CHUNK_CACHE_MAX 0x7fffffffL
# define PNG_USER_CHUNK_CACHE_MAX 0
#endif
/* Added at libpng-1.2.43 */
#ifndef PNG_USER_CHUNK_MALLOC_MAX
# define PNG_USER_CHUNK_MALLOC_MAX 0x7fffffffL
# define PNG_USER_CHUNK_MALLOC_MAX 0
#endif
/* Added at libpng-1.4.0 */

View File

@ -329,7 +329,9 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_ptr->mode |= PNG_HAVE_IDAT;
png_ptr->process_mode = PNG_READ_IDAT_MODE;
png_push_have_info(png_ptr, info_ptr);
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
png_ptr->zstream.avail_out =
(uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
png_ptr->iwidth) + 1;
png_ptr->zstream.next_out = png_ptr->row_buf;
return;
}
@ -684,19 +686,25 @@ png_push_save_buffer(png_structp png_ptr)
}
}
}
if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
png_ptr->save_buffer_max)
if (png_ptr->save_buffer_size >
(png_ptr->save_buffer_max - png_ptr->current_buffer_size))
{
png_size_t new_max;
png_bytep old_buffer;
if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
(png_ptr->current_buffer_size + 256))
{
png_error(png_ptr, "Potential overflow of save_buffer");
}
if (png_ptr->save_buffer_size == PNG_SIZE_MAX)
png_error(png_ptr, "Overflow of save_buffer");
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
(png_ptr->current_buffer_size +
(png_ptr->save_buffer_size >> 3) + 256))
new_max = PNG_SIZE_MAX;
else
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size +
(png_ptr->save_buffer_size >> 3) + 256;
old_buffer = png_ptr->save_buffer;
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
(png_size_t)new_max);
@ -869,7 +877,9 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
break;
}
png_push_process_row(png_ptr);
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
png_ptr->zstream.avail_out =
(uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
png_ptr->iwidth) + 1;
png_ptr->zstream.next_out = png_ptr->row_buf;
}
@ -1134,9 +1144,6 @@ png_read_push_finish_row(png_structp png_ptr)
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
png_ptr->iwidth) + 1;
if (png_ptr->transformations & PNG_INTERLACE)
break;

View File

@ -1,7 +1,7 @@
/* pngpriv.h - private declarations for use inside libpng
*
* libpng version 1.4.1beta07 - February 5, 2010
* libpng version 1.4.1beta07 - February 6, 2010
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)