summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-06-08 16:15:59 +0100
committerRobin Watts <robin.watts@artifex.com>2016-06-13 13:09:09 +0100
commit4766b28647c77a9695d0daa7efde8ba3d23c6b06 (patch)
treefb8eb2ca886256455429bdd664877ba2b6e20b5a /source/pdf
parent2777fb92d7f4a6617ba5d83868d8597b7bac3465 (diff)
downloadmupdf-4766b28647c77a9695d0daa7efde8ba3d23c6b06.tar.xz
Bug 696822: Refuse to save a pdf file incrementally if it would break.
If a file cannot be saved incrementally, then don't accept that as an option. In practise this means if someone asks to save a file incrementally, and it was repaired, or it uses encryption then throw an error. Add a new function to ask if it's safe to save a file incrementally, and use that in the appropriate places.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-write.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index ade277ce..87c31926 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -2804,6 +2804,15 @@ void pdf_parse_write_options(fz_context *ctx, pdf_write_options *opts, const cha
}
}
+int pdf_can_be_saved_incrementally(fz_context *ctx, pdf_document *doc)
+{
+ if (doc->repair_attempted)
+ return 0;
+ if (doc->crypt != NULL)
+ return 0;
+ return 1;
+}
+
void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename, pdf_write_options *in_opts)
{
pdf_write_options opts_defaults = { 0 };
@@ -2819,6 +2828,8 @@ void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename,
if (!in_opts)
in_opts = &opts_defaults;
+ if (in_opts->do_incremental && doc->repair_attempted)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes on a repaired file");
if (in_opts->do_incremental && in_opts->do_garbage)
fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes with garbage collection");
if (in_opts->do_incremental && in_opts->do_linear)