[libpng16] Deflate/inflate was reworked to move common zlib calls into single

functions [rw]util.c.  A new shared keyword check routine was also added
and the 'zbuf' is no longer allocated on progressive read.  It is now
possible to call png_inflate() incrementally.
This commit is contained in:
John Bowler
2012-03-09 09:15:18 -06:00
committed by Glenn Randers-Pehrson
parent 6038b80277
commit b5d0051dcb
15 changed files with 1579 additions and 1475 deletions

View File

@@ -1231,26 +1231,51 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
if (png_ptr == NULL)
return;
png_free(png_ptr, png_ptr->zbuf);
if (size == 0 || size > PNG_UINT_31_MAX)
png_error(png_ptr, "invalid compression buffer size");
if (size > ZLIB_IO_MAX)
{
png_warning(png_ptr, "Attempt to set buffer size beyond max ignored");
png_ptr->zbuf_size = ZLIB_IO_MAX;
size = ZLIB_IO_MAX; /* must fit */
}
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
if (png_ptr->mode & PNG_IS_READ_STRUCT)
{
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
return;
}
# endif
else
png_ptr->zbuf_size = (uInt)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
/* The following ensures a relatively safe failure if this gets called while
* the buffer is actually in use.
*/
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = 0;
png_ptr->zstream.avail_in = 0;
# ifdef PNG_WRITE_SUPPORTED
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
{
if (png_ptr->zowner != 0)
{
png_warning(png_ptr,
"Compression buffer size cannot be changed because it is in use");
return;
}
if (size > ZLIB_IO_MAX)
{
png_warning(png_ptr,
"Compression buffer size limited to system maximum");
size = ZLIB_IO_MAX; /* must fit */
}
else if (size < 6)
{
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
* if this is permitted.
*/
png_warning(png_ptr,
"Compression buffer size cannot be reduced below 6");
return;
}
if (png_ptr->zbuffer_size != size)
{
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
png_ptr->zbuffer_size = (uInt)size;
}
}
# endif
}
void PNGAPI