mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[devel] IDAT compression failed if preceded by a compressed text chunk
This was because the attempt to reset the zlib stream in png_write_IDAT happened after the first IDAT chunk had been deflated - much too late. In this change internal functions are added to claim/release the z_stream and, hopefully, make the code more robust. Also deflateEnd checking is added - previously libpng would ignore an error at the end of the stream.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
c559bb58ed
commit
c5bef946b1
@@ -844,8 +844,6 @@ png_write_flush(png_structp png_ptr)
|
||||
{
|
||||
/* Write the IDAT and reset the zlib output buffer */
|
||||
png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
wrote_IDAT = 1;
|
||||
}
|
||||
} while (wrote_IDAT == 1);
|
||||
@@ -856,8 +854,6 @@ png_write_flush(png_structp png_ptr)
|
||||
/* Write the IDAT and reset the zlib output buffer */
|
||||
png_write_IDAT(png_ptr, png_ptr->zbuf,
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
}
|
||||
png_ptr->flush_rows = 0;
|
||||
png_flush(png_ptr);
|
||||
@@ -954,7 +950,8 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_debug(1, "in png_write_destroy");
|
||||
|
||||
/* Free any memory zlib uses */
|
||||
deflateEnd(&png_ptr->zstream);
|
||||
if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
|
||||
deflateEnd(&png_ptr->zstream);
|
||||
|
||||
/* Free our memory. png_free checks NULL for us. */
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
|
||||
Reference in New Issue
Block a user