summaryrefslogtreecommitdiff
path: root/pngwrite.c
diff options
context:
space:
mode:
authorJohn Bowler <jbowler@acm.org>2011-05-05 17:35:39 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2011-05-05 17:35:39 -0500
commitc5bef946b1c247f22768eded4525cc872976653a (patch)
treec9b07b2ffbe15a7f5f9b469a51993ddf45b9eb63 /pngwrite.c
parentc559bb58ed25ae0d6b732283afeaabb36e4b430f (diff)
downloadlibpng-c5bef946b1c247f22768eded4525cc872976653a.tar.gz
[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.
Diffstat (limited to 'pngwrite.c')
-rw-r--r--pngwrite.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/pngwrite.c b/pngwrite.c
index 1eb360b23..1a9ecb76f 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -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);