[master] Imported from libpng-1.4.1beta04.tar

This commit is contained in:
Glenn Randers-Pehrson 2010-01-22 19:30:23 -06:00
parent fb3a1da4bb
commit 86f6c04d84
12 changed files with 152 additions and 38 deletions

View File

@ -44,7 +44,13 @@ version 1.4.1beta02 [January 9, 2010]
version 1.4.1beta03 [January 10, 2010] version 1.4.1beta03 [January 10, 2010]
Removed png_set_premultiply_alpha() from scripts/*.def Removed png_set_premultiply_alpha() from scripts/*.def
version 1.4.1rc01 [January 16, 2010]
No changes.
version 1.4.1beta04 [January 23, 2010] version 1.4.1beta04 [January 23, 2010]
Revised png_decompress_chunk() to improve speed and memory usage when
decoding large chunks.
Added png_set|get_chunk_malloc_max() function and PNG_CHUNK_MALLOC_MAX macro.
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

@ -2476,7 +2476,13 @@ version 1.4.1beta02 [January 9, 2010]
version 1.4.1beta03 [January 10, 2010] version 1.4.1beta03 [January 10, 2010]
Removed png_set_premultiply_alpha() from scripts/*.def Removed png_set_premultiply_alpha() from scripts/*.def
version 1.4.1rc01 [January 16, 2010]
No changes.
version 1.4.1beta04 [January 23, 2010] version 1.4.1beta04 [January 23, 2010]
Revised png_decompress_chunk() to improve speed and memory usage when
decoding large chunks.
Added png_set|get_chunk_malloc_max() function and PNG_CHUNK_MALLOC_MAX macro.
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

@ -432,6 +432,18 @@ where 0x7fffffffL means unlimited. You can retrieve this limit with
This limit also applies to the number of buffers that can be allocated This limit also applies to the number of buffers that can be allocated
by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
You can also set a limit on the amount of memory that a compressed chunk
other than IDAT can occupy, with
png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
and you can retrieve the limit with
chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
Any chunks that would cause either of these limits to be exceeded will
be ignored.
The high-level read interface The high-level read interface
At this point there are two ways to proceed; through the high-level At this point there are two ways to proceed; through the high-level

View File

@ -192,6 +192,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta04
\fI\fB \fI\fB
\fBpng_uint_32 png_get_chunk_malloc_max (png_structp \fIpng_ptr\fP\fB);\fP
\fI\fB
\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP \fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
\fI\fB \fI\fB
@ -538,6 +542,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.4.1beta04
\fI\fB \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
\fI\fB
\fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP \fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
\fI\fB \fI\fB
@ -1209,6 +1217,18 @@ where 0x7fffffffL means unlimited. You can retrieve this limit with
This limit also applies to the number of buffers that can be allocated This limit also applies to the number of buffers that can be allocated
by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
You can also set a limit on the amount of memory that a compressed chunk
other than IDAT can occupy, with
png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
and you can retrieve the limit with
chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
Any chunks that would cause either of these limits to be exceeded will
be ignored.
.SS The high-level read interface .SS The high-level read interface
At this point there are two ways to proceed; through the high-level At this point there are two ways to proceed; through the high-level

15
png.h
View File

@ -1336,10 +1336,18 @@ struct png_struct_def
/* New member added in libpng-1.2.30 */ /* New member added in libpng-1.2.30 */
png_charp chunkdata PNG_DEPSTRUCT; /* buffer for reading chunk data */ png_charp chunkdata PNG_DEPSTRUCT; /* buffer for reading chunk data */
/* New member added in libpng-1.4.0 */
#ifdef PNG_IO_STATE_SUPPORTED #ifdef PNG_IO_STATE_SUPPORTED
/* New member added in libpng-1.4.0 */
png_uint_32 io_state PNG_DEPSTRUCT; png_uint_32 io_state PNG_DEPSTRUCT;
#endif #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.
*/
png_uint_32 user_chunk_malloc_max PNG_DEPSTRUCT;
#endif
}; };
@ -2396,6 +2404,11 @@ extern PNG_EXPORT(void,png_set_chunk_cache_max) PNGARG((png_structp
png_ptr, png_uint_32 user_chunk_cache_max)); png_ptr, png_uint_32 user_chunk_cache_max));
extern PNG_EXPORT(png_uint_32,png_get_chunk_cache_max) extern PNG_EXPORT(png_uint_32,png_get_chunk_cache_max)
PNGARG((png_structp png_ptr)); 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)
PNGARG((png_structp png_ptr));
#endif #endif
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)

View File

@ -675,6 +675,10 @@
#ifndef PNG_SET_USER_LIMITS_SUPPORTED #ifndef PNG_SET_USER_LIMITS_SUPPORTED
# ifndef PNG_NO_SET_USER_LIMITS # ifndef PNG_NO_SET_USER_LIMITS
# define PNG_SET_USER_LIMITS_SUPPORTED # define PNG_SET_USER_LIMITS_SUPPORTED
/* Feature added at libpng-1.4.0, this flag added at 1.4.1 */
# define PNG_CHUNK_CACHE_LIMIT_SUPPORTED
/* Feature added at libpng-1.4.1, this flag added at 1.4.1 */
# define PNG_CHUNK_MALLOC_LIMIT_SUPPORTED
# endif # endif
#endif #endif

View File

@ -895,8 +895,14 @@ png_get_user_height_max (png_structp png_ptr)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_chunk_cache_max (png_structp png_ptr) png_get_chunk_cache_max (png_structp png_ptr)
{ {
return (png_ptr? png_ptr->user_chunk_cache_max? 0x7fffffffL : return (png_ptr? (png_ptr->user_chunk_cache_max? 0x7fffffffL :
png_ptr->user_chunk_cache_max - 1 : 0); png_ptr->user_chunk_cache_max - 1) : 0);
}
/* This function was added to libpng 1.4.1 */
png_uint_32 PNGAPI
png_get_chunk_malloc_max (png_structp png_ptr)
{
return (png_ptr? png_ptr->user_chunk_cache_max : 0);
} }
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */

View File

@ -278,63 +278,90 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text = (png_charp)png_malloc_warn(png_ptr, text_size + 1); text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_error(png_ptr, png_error(png_ptr,
"Not enough memory to decompress chunk"); "Not enough memory to decompress chunk");
text_size = 0;
break;
} }
png_memcpy(text, png_ptr->chunkdata, prefix_size);
png_memcpy(text + prefix_size, png_ptr->zbuf, png_memcpy(text + prefix_size, png_ptr->zbuf,
text_size - prefix_size); text_size - prefix_size);
png_memcpy(text, png_ptr->chunkdata, prefix_size);
*(text + text_size) = 0x00; *(text + text_size) = 0x00;
buffer_size = text_size; buffer_size = text_size;
} }
else /* Enlarge the decompression buffer */ else /* Enlarge the decompression buffer */
{ {
png_charp tmp; png_charp tmp = text;
png_size_t new_text_size;
tmp = text; new_text_size = text_size + png_ptr->zbuf_size -
#ifdef PNG_CHUNK_MALLOC_LIMIT_SUPPORTED png_ptr->zstream.avail_out;
if ((png_ptr->user_chunk_cache_max != 0) &&
(--png_ptr->user_chunk_cache_max == 0)) if (new_text_size > buffer_size)
{ {
png_warning(png_ptr, "No space in chunk cache"); if (png_ptr->zstream.avail_out)
buffer_size = new_text_size;
else
buffer_size += buffer_size;
}
#ifdef PNG_CHUNK_MALLOC_LIMIT_SUPPORTED
if (png_ptr->user_chunk_malloc_max <= buffer_size)
{
png_free(png_ptr, tmp);
png_warning(png_ptr, "No space for decompressed chunk");
text = NULL; text = NULL;
} }
else else
{
#endif
text = (png_charp)png_malloc_warn(png_ptr, text = (png_charp)png_malloc_warn(png_ptr,
(png_size_t)(text_size + buffer_size + 1);
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); #else
#ifdef PNG_CHUNK_MALLOC_LIMIT_SUPPORTED text = (png_charp)png_malloc_warn(png_ptr,
} buffer_size + 1);
#endif #endif
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr, tmp); png_warning(png_ptr,
png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL;
png_error(png_ptr,
"Not enough memory to decompress chunk"); "Not enough memory to decompress chunk");
break;
} }
png_memcpy(text, tmp, text_size); png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp); png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
*(text + text_size) = 0x00;
}
if (ret == Z_STREAM_END)
break;
else
{
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
} }
} }
if (ret == Z_STREAM_END)
break;
else
{
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}
} }
if (text != NULL && buffer_size > text_size)
{
/* Reduce text allocation to actual size */
png_charp tmp;
tmp = text;
text = (png_charp)png_malloc_warn(png_ptr,
text_size);
if (text == NULL)
text = tmp;
else
{
png_memcpy(text, tmp, text_size + 1);
png_free(png_ptr, tmp);
}
}
if (ret != Z_STREAM_END) if (ret != Z_STREAM_END)
{ {
#ifdef PNG_STDIO_SUPPORTED #ifdef PNG_STDIO_SUPPORTED
@ -365,11 +392,11 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
{ {
text = (png_charp)png_malloc_warn(png_ptr, text_size+1); text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
if (text == NULL) if (text == NULL)
{ {
png_free(png_ptr, png_ptr->chunkdata); png_free(png_ptr, png_ptr->chunkdata);
png_ptr->chunkdata = NULL; png_ptr->chunkdata = NULL;
png_error(png_ptr, "Not enough memory for text"); png_error(png_ptr, "Not enough memory for text");
} }
png_memcpy(text, png_ptr->chunkdata, prefix_size); png_memcpy(text, png_ptr->chunkdata, prefix_size);
} }
*(text + text_size) = 0x00; *(text + text_size) = 0x00;

View File

@ -1130,6 +1130,7 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
png_ptr->user_width_max = user_width_max; png_ptr->user_width_max = user_width_max;
png_ptr->user_height_max = user_height_max; png_ptr->user_height_max = user_height_max;
} }
/* This function was added to libpng 1.4.0 */ /* This function was added to libpng 1.4.0 */
void PNGAPI void PNGAPI
png_set_chunk_cache_max (png_structp png_ptr, png_set_chunk_cache_max (png_structp png_ptr,
@ -1143,6 +1144,16 @@ png_set_chunk_cache_max (png_structp png_ptr,
else else
png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1; png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1;
} }
/* This function was added to libpng 1.4.1 */
void PNGAPI
png_set_chunk_malloc_max (png_structp png_ptr,
png_uint_32 user_chunk_malloc_max)
{
if (png_ptr == NULL)
return;
png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
}
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */

View File

@ -254,3 +254,6 @@ EXPORTS
png_check_cHRM_fixed @217 png_check_cHRM_fixed @217
png_calloc @218 png_calloc @218
png_set_longjmp_fn @219 png_set_longjmp_fn @219
; Added at version 1.4.1
png_get_chunk_malloc_max @220
png_set_chunk_malloc_max @221

View File

@ -214,6 +214,9 @@ EXPORTS
png_check_cHRM_fixed png_check_cHRM_fixed
png_calloc png_calloc
png_set_longjmp_fn png_set_longjmp_fn
; Added at version 1.4.1
png_get_chunk_malloc_max
png_set_chunk_malloc_max
; These are not present when libpng is compiled with PNG_NO_GLOBAL_ARRAYS ; These are not present when libpng is compiled with PNG_NO_GLOBAL_ARRAYS
png_libpng_ver png_libpng_ver

View File

@ -209,3 +209,6 @@ EXPORTS
png_check_cHRM_fixed png_check_cHRM_fixed
png_calloc png_calloc
png_set_longjmp_fn png_set_longjmp_fn
; Added at version 1.4.1
png_get_chunk_malloc_max
png_set_chunk_malloc_max