diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-09-05 15:37:42 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-09-05 15:43:44 +0100 |
commit | 796be86b078c59bed0d67c4322072317a9fafb06 (patch) | |
tree | 1aa7abe3aaf8d45aca7543ea34522dbd463ae94e /source/pdf/pdf-write.c | |
parent | fff28aaa5166eb984b24fd7dbeb097dad6c8bd65 (diff) | |
download | mupdf-796be86b078c59bed0d67c4322072317a9fafb06.tar.xz |
mutool clean: Fixes seen as part of bug 697092 investigation.
Firstly, we avoid compressing streams if they get bigger.
Secondly, we ensure that we always update the Length field.
Seen as part of the investigation into bug 697092, though not the
actual cause. Thanks to Tor for the latter part of the fix.
Diffstat (limited to 'source/pdf/pdf-write.c')
-rw-r--r-- | source/pdf/pdf-write.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index 84e64450..2dead828 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -1637,11 +1637,18 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts if (do_deflate && !pdf_dict_get(ctx, obj, PDF_NAME_Filter)) { - pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); - tmp = deflatebuf(ctx, buf->data, buf->len); - fz_drop_buffer(ctx, buf); - buf = tmp; + if (tmp->len >= buf->len) + { + /* Don't bother compressing, as we gain nothing. */ + fz_drop_buffer(ctx, tmp); + } + else + { + pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); + fz_drop_buffer(ctx, buf); + buf = tmp; + } } if (opts->do_ascii && isbinarystream(buf)) @@ -1651,12 +1658,12 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts buf = tmp; addhexfilter(ctx, doc, obj); - - newlen = pdf_new_int(ctx, doc, (int)buf->len); - pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); - pdf_drop_obj(ctx, newlen); } + newlen = pdf_new_int(ctx, doc, (int)buf->len); + pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); + pdf_drop_obj(ctx, newlen); + fz_printf(ctx, opts->out, "%d %d obj\n", num, gen); pdf_print_obj(ctx, opts->out, obj, opts->do_tight); fz_puts(ctx, opts->out, "\nstream\n"); @@ -1686,11 +1693,18 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *op if (do_deflate) { - pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); - tmp = deflatebuf(ctx, buf->data, buf->len); - fz_drop_buffer(ctx, buf); - buf = tmp; + if (tmp->len >= buf->len) + { + /* Don't bother compressing, as we gain nothing. */ + fz_drop_buffer(ctx, tmp); + } + else + { + pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); + fz_drop_buffer(ctx, buf); + buf = tmp; + } } if (opts->do_ascii && isbinarystream(buf)) |