summaryrefslogtreecommitdiff
path: root/source/fitz
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
parentfab177c9983802870798ffb9ecb4b37e7523b49d (diff)
downloadmupdf-29af19695090b95cb5dcb77274f7ce68526e74a3.tar.xz
When PS/PNG band writers throw, end the deflate streams if open.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/output-png.c9
-rw-r--r--source/fitz/output-ps.c12
2 files changed, 21 insertions, 0 deletions
diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c
index 4a325959..87c69428 100644
--- a/source/fitz/output-png.c
+++ b/source/fitz/output-png.c
@@ -79,6 +79,7 @@ typedef struct png_band_writer_s
unsigned char *cdata;
uLong usize, csize;
z_stream stream;
+ int stream_ended;
} png_band_writer;
static void
@@ -262,6 +263,7 @@ png_write_trailer(fz_context *ctx, fz_band_writer *writer_)
unsigned char block[1];
int err;
+ writer->stream_ended = 1;
err = deflateEnd(&writer->stream);
if (err != Z_OK)
fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err);
@@ -274,6 +276,13 @@ png_drop_band_writer(fz_context *ctx, fz_band_writer *writer_)
{
png_band_writer *writer = (png_band_writer *)(void *)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->cdata);
fz_free(ctx, writer->udata);
}
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);
}