summaryrefslogtreecommitdiff
path: root/source/fitz/output-ps.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-06-24 16:37:42 +0800
committerSebastian Rasmussen <sebras@gmail.com>2017-06-27 21:27:14 +0800
commit29af19695090b95cb5dcb77274f7ce68526e74a3 (patch)
treeb14255e752333ff483b7da6022e3a77654d26b92 /source/fitz/output-ps.c
parentfab177c9983802870798ffb9ecb4b37e7523b49d (diff)
downloadmupdf-29af19695090b95cb5dcb77274f7ce68526e74a3.tar.xz
When PS/PNG band writers throw, end the deflate streams if open.
Diffstat (limited to 'source/fitz/output-ps.c')
-rw-r--r--source/fitz/output-ps.c12
1 files changed, 12 insertions, 0 deletions
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);
}