From 29af19695090b95cb5dcb77274f7ce68526e74a3 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 24 Jun 2017 16:37:42 +0800 Subject: When PS/PNG band writers throw, end the deflate streams if open. --- source/fitz/output-ps.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/fitz/output-ps.c') diff --git a/source/fitz/output-ps.c b/source/fitz/output-ps.c index d3ff0ec3..126c54ff 100644 --- a/source/fitz/output-ps.c +++ b/source/fitz/output-ps.c @@ -6,6 +6,7 @@ typedef struct ps_band_writer_s { fz_band_writer super; z_stream stream; + int stream_ended; int input_size; unsigned char *input; int output_size; @@ -120,6 +121,10 @@ ps_write_trailer(fz_context *ctx, fz_band_writer *writer_) err = deflate(&writer->stream, Z_FINISH); if (err != Z_STREAM_END) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); + writer->stream_ended = 1; + err = deflateEnd(&writer->stream); + if (err != Z_OK) + fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); fz_write_data(ctx, out, writer->output, writer->output_size - writer->stream.avail_out); fz_write_string(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n"); @@ -130,6 +135,13 @@ ps_drop_band_writer(fz_context *ctx, fz_band_writer *writer_) { ps_band_writer *writer = (ps_band_writer *)writer_; + if (!writer->stream_ended) + { + int err = deflateEnd(&writer->stream); + if (err != Z_OK) + fz_warn(ctx, "ignoring compression error %d", err); + } + fz_free(ctx, writer->input); fz_free(ctx, writer->output); } -- cgit v1.2.3