From e964faf9c2b4d327971969a589932a9b2572b5a7 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 30 Jul 2012 00:04:57 +0200 Subject: Always rebuild static libraries in unix, instead of updating them The u modifier to to the ar replace command tells ar to only insert those object files into a static library that are newer than those already in the library (both having the same name). Moreover ar only stores timestamps down to second accuracy. This may cause situations where the object file already inside the library is considered equal to a newly built object file (which might include a new function) because their timestamps differ only in the sub-second part. One of the apps might have an object file that references this new function. Since the static library retains the old object file there will be a linking error when linking the app. Even re-running make will not fix the issue since the static library will have its modification time updated to a timestamp later than the newly built object file, which means that ar will not be run again. The only option is to make nuke and rebuild from scratch. From now on, the u modifier to the ar replace command is removed. This means that ar will rebuild static libraries without taking timestamps of object files into account, to make sure that the build never ends up in the situation described above. --- Makefile | 2 +- ios/build_libs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 082556ca..05bb4e8b 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ QUIET_MKDIR = @ echo ' ' ' ' MKDIR $@ ; endif CC_CMD = $(QUIET_CC) $(CC) $(CFLAGS) -o $@ -c $< -AR_CMD = $(QUIET_AR) $(AR) cru $@ $^ +AR_CMD = $(QUIET_AR) $(AR) cr $@ $^ LINK_CMD = $(QUIET_LINK) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) MKDIR_CMD = $(QUIET_MKDIR) mkdir -p $@ diff --git a/ios/build_libs.sh b/ios/build_libs.sh index 72c07ce0..836601d1 100644 --- a/ios/build_libs.sh +++ b/ios/build_libs.sh @@ -27,7 +27,7 @@ make -C .. libs || exit 1 echo Assembling final library in $TARGET_BUILD_DIR/. mkdir -p "$TARGET_BUILD_DIR" rm -f $TARGET_BUILD_DIR/libLibraries.a -ar cru $TARGET_BUILD_DIR/libLibraries.a ../$OUT/*.o +ar cr $TARGET_BUILD_DIR/libLibraries.a ../$OUT/*.o ranlib $TARGET_BUILD_DIR/libLibraries.a echo Done. -- cgit v1.2.3 From 171deea598ec88f370e31b0d1b58d841277eceb1 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 13:03:05 +0200 Subject: Fix typo in PDF function code This is just a lexical change, no semantic change as the MAXN and MAXM constants are equal. --- pdf/pdf_function.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index eab7bedf..18c16669 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -1422,7 +1422,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) /* required for all */ obj = pdf_dict_gets(dict, "Domain"); - func->m = fz_clampi(pdf_array_len(obj) / 2, 1, MAXN); + func->m = fz_clampi(pdf_array_len(obj) / 2, 1, MAXM); for (i = 0; i < func->m; i++) { func->domain[i][0] = pdf_to_real(pdf_array_get(obj, i * 2 + 0)); @@ -1498,7 +1498,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in_, int inlen, float *out_, int outlen) { - float fakein[MAXN]; + float fakein[MAXM]; float fakeout[MAXN]; float *in = in_; float *out = out_; -- cgit v1.2.3 From f919270b6a732ff45c3ba2d0c105e2b39e9c9bc9 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 14:11:20 +0200 Subject: Handle invalid obj/gen numbers when repairing pdfs Out of range object numbers cause the repaired object to be ignored. Out of range generation numbers are clamped to the permitted range. --- pdf/pdf_repair.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index 0874c2f8..df8d81f9 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -3,6 +3,9 @@ /* Scan file for objects and reconstruct xref table */ +/* Define in PDF 1.7 to be 8388607, but mupdf is more lenient. */ +#define MAX_OBJECT_NUMBER (10 << 20) + struct entry { int num; @@ -170,6 +173,16 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen) fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen); n = buf.i; + if (n < 0) + { + fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); + continue; + } + else if (n > MAX_OBJECT_NUMBER) + { + fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); + continue; + } if (n >= xref->len) pdf_resize_xref(xref, n + 1); @@ -299,6 +312,19 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) break; } + if (num < 0) + { + fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); + continue; + } + else if (num > MAX_OBJECT_NUMBER) + { + fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); + continue; + } + + gen = fz_clampi(gen, 0, 65535); + if (listlen + 1 == listcap) { listcap = (listcap * 3) / 2; -- cgit v1.2.3 From 16628b1419a260874f92b71263cc179c419f33b6 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 16:34:11 +0200 Subject: Only warn once about ignoring rendering errors --- pdf/pdf_interpret.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index ab55ee66..efc007e4 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -2540,6 +2540,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) fz_context *ctx = csi->dev->ctx; int tok = PDF_TOK_ERROR; int in_array; + int ignoring_errors = 0; /* make sure we have a clean slate if we come here from flush_text */ pdf_clear_stack(csi); @@ -2680,7 +2681,11 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) /* Swallow the error */ if (csi->cookie) csi->cookie->errors++; - fz_warn(ctx, "Ignoring error during rendering"); + if (!ignoring_errors) + { + fz_warn(ctx, "Ignoring errors during rendering"); + ignoring_errors = 1; + } /* If we do catch an error, then reset ourselves to a * base lexing state */ in_array = 0; -- cgit v1.2.3 From 966ae9dc4ca3edce4ff592028baeb69fcebddeb7 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 16:35:09 +0200 Subject: Fix bug where too many content stream operands cause eternal loop Once enough operands were push on top of the operand stack an exception would be thrown. The exception handling ignored the exception, printed a warning and continued processing the content stream. Unfortunately the token was never consumed, so once the interpreter retried parsing the stream it encountered the same token again, causing the loop and thus a stack overflow. Now, make sure each token is consumed before throwing a new exception thereby breaking the eternal loop and letting pdfs with excessive operands be rendered, albeit with both errors and a warning. --- pdf/pdf_interpret.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index efc007e4..0ecb7893 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -2561,9 +2561,6 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) { do { - if (csi->top == nelem(csi->stack) - 1) - fz_throw(ctx, "stack overflow"); - /* Check the cookie */ if (csi->cookie) { @@ -2640,13 +2637,21 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) break; case PDF_TOK_INT: - csi->stack[csi->top] = buf->i; - csi->top ++; + if (csi->top < nelem(csi->stack)) { + csi->stack[csi->top] = buf->i; + csi->top ++; + } + else + fz_throw(ctx, "stack overflow"); break; case PDF_TOK_REAL: - csi->stack[csi->top] = buf->f; - csi->top ++; + if (csi->top < nelem(csi->stack)) { + csi->stack[csi->top] = buf->f; + csi->top ++; + } + else + fz_throw(ctx, "stack overflow"); break; case PDF_TOK_STRING: -- cgit v1.2.3 From 4c00e74b4124474a736678e5554f9d8057c78de8 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 19:31:53 +0200 Subject: Handle exceptions better in mupdfclean pdf_write_document() may throw an exception and this was uncaught up until now. --- apps/mupdfclean.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c index 6b185668..fdf9b412 100644 --- a/apps/mupdfclean.c +++ b/apps/mupdfclean.c @@ -161,6 +161,7 @@ int pdfclean_main(int argc, char **argv) int c; int subset; fz_write_options opts; + int write_failed = 0; opts.do_garbage = 0; opts.do_expand = 0; @@ -204,18 +205,29 @@ int pdfclean_main(int argc, char **argv) exit(1); } - xref = pdf_open_document_no_run(ctx, infile); - if (pdf_needs_password(xref)) - if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_try(ctx) + { + xref = pdf_open_document_no_run(ctx, infile); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s", infile); - /* Only retain the specified subset of the pages */ - if (subset) - retainpages(argc, argv); + /* Only retain the specified subset of the pages */ + if (subset) + retainpages(argc, argv); - pdf_write_document(xref, outfile, &opts); + pdf_write_document(xref, outfile, &opts); + } + fz_always(ctx) + { + pdf_close_document(xref); + } + fz_catch(ctx) + { + write_failed = 1; + } - pdf_close_document(xref); fz_free_context(ctx); - return 0; + + return write_failed ? 1 : 0; } -- cgit v1.2.3 From 0df1f84bd59e94798a09b55aac1d7cba40be60d0 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 19:34:09 +0200 Subject: No need to check for NULL before dropping objects --- pdf/pdf_annot.c | 3 +-- pdf/pdf_crypt.c | 4 ++-- pdf/pdf_interpret.c | 3 +-- pdf/pdf_object.c | 12 ++++-------- pdf/pdf_page.c | 6 ++---- pdf/pdf_repair.c | 27 +++++++++++---------------- pdf/pdf_write.c | 9 +++------ pdf/pdf_xobject.c | 6 ++---- pdf/pdf_xref.c | 12 ++++-------- 9 files changed, 30 insertions(+), 52 deletions(-) diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index f6c70f90..d6b5096e 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -320,8 +320,7 @@ pdf_free_annot(fz_context *ctx, pdf_annot *annot) next = annot->next; if (annot->ap) pdf_drop_xobject(ctx, annot->ap); - if (annot->obj) - pdf_drop_obj(annot->obj); + pdf_drop_obj(annot->obj); fz_free(ctx, annot); annot = next; } diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index a8f92823..4fc34ea8 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -255,8 +255,8 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt) { - if (crypt->id) pdf_drop_obj(crypt->id); - if (crypt->cf) pdf_drop_obj(crypt->cf); + pdf_drop_obj(crypt->id); + pdf_drop_obj(crypt->cf); fz_free(ctx, crypt); } diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 0ecb7893..d8b8b9bc 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -996,8 +996,7 @@ pdf_clear_stack(pdf_csi *csi) { int i; - if (csi->obj) - pdf_drop_obj(csi->obj); + pdf_drop_obj(csi->obj); csi->obj = NULL; csi->name[0] = 0; diff --git a/pdf/pdf_object.c b/pdf/pdf_object.c index 7021fa5d..955cd5cf 100644 --- a/pdf/pdf_object.c +++ b/pdf/pdf_object.c @@ -512,8 +512,7 @@ pdf_array_put(pdf_obj *obj, int i, pdf_obj *item) fz_warn(obj->ctx, "assert: index %d > length %d", i, obj->u.a.len); else { - if (obj->u.a.items[i]) - pdf_drop_obj(obj->u.a.items[i]); + pdf_drop_obj(obj->u.a.items[i]); obj->u.a.items[i] = pdf_keep_obj(item); } } @@ -1090,8 +1089,7 @@ pdf_free_array(pdf_obj *obj) int i; for (i = 0; i < obj->u.a.len; i++) - if (obj->u.a.items[i]) - pdf_drop_obj(obj->u.a.items[i]); + pdf_drop_obj(obj->u.a.items[i]); fz_free(obj->ctx, obj->u.a.items); fz_free(obj->ctx, obj); @@ -1103,10 +1101,8 @@ pdf_free_dict(pdf_obj *obj) int i; for (i = 0; i < obj->u.d.len; i++) { - if (obj->u.d.items[i].k) - pdf_drop_obj(obj->u.d.items[i].k); - if (obj->u.d.items[i].v) - pdf_drop_obj(obj->u.d.items[i].v); + pdf_drop_obj(obj->u.d.items[i].k); + pdf_drop_obj(obj->u.d.items[i].v); } fz_free(obj->ctx, obj->u.d.items); diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 28be312d..4aa0a893 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -404,10 +404,8 @@ pdf_load_links(pdf_document *xref, pdf_page *page) void pdf_free_page(pdf_document *xref, pdf_page *page) { - if (page->resources) - pdf_drop_obj(page->resources); - if (page->contents) - pdf_drop_obj(page->contents); + pdf_drop_obj(page->resources); + pdf_drop_obj(page->contents); if (page->links) fz_drop_link(xref->ctx, page->links); if (page->annots) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index df8d81f9..bbe70a2a 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -54,16 +54,14 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf obj = pdf_dict_gets(dict, "Encrypt"); if (obj) { - if (*encrypt) - pdf_drop_obj(*encrypt); + pdf_drop_obj(*encrypt); *encrypt = pdf_keep_obj(obj); } obj = pdf_dict_gets(dict, "ID"); if (obj) { - if (*id) - pdf_drop_obj(*id); + pdf_drop_obj(*id); *id = pdf_keep_obj(obj); } } @@ -363,32 +361,28 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) obj = pdf_dict_gets(dict, "Encrypt"); if (obj) { - if (encrypt) - pdf_drop_obj(encrypt); + pdf_drop_obj(encrypt); encrypt = pdf_keep_obj(obj); } obj = pdf_dict_gets(dict, "ID"); if (obj) { - if (id) - pdf_drop_obj(id); + pdf_drop_obj(id); id = pdf_keep_obj(obj); } obj = pdf_dict_gets(dict, "Root"); if (obj) { - if (root) - pdf_drop_obj(root); + pdf_drop_obj(root); root = pdf_keep_obj(obj); } obj = pdf_dict_gets(dict, "Info"); if (obj) { - if (info) - pdf_drop_obj(info); + pdf_drop_obj(info); info = pdf_keep_obj(obj); } @@ -490,16 +484,17 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) } pdf_dict_puts(xref->trailer, "ID", id); pdf_drop_obj(id); + id = NULL; } fz_free(ctx, list); } fz_catch(ctx) { - if (encrypt) pdf_drop_obj(encrypt); - if (id) pdf_drop_obj(id); - if (root) pdf_drop_obj(root); - if (info) pdf_drop_obj(info); + pdf_drop_obj(encrypt); + pdf_drop_obj(id); + pdf_drop_obj(root); + pdf_drop_obj(info); fz_free(ctx, list); fz_rethrow(ctx); } diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c index 76f19748..3dce3838 100644 --- a/pdf/pdf_write.c +++ b/pdf/pdf_write.c @@ -735,8 +735,7 @@ static void renumberobjs(pdf_document *xref, pdf_write_options *opts) } else { - if (oldxref[num].obj) - pdf_drop_obj(oldxref[num].obj); + pdf_drop_obj(oldxref[num].obj); } } } @@ -1435,10 +1434,8 @@ static void addhexfilter(pdf_document *xref, pdf_obj *dict) pdf_drop_obj(ahx); pdf_drop_obj(nullobj); - if (newf) - pdf_drop_obj(newf); - if (newdp) - pdf_drop_obj(newdp); + pdf_drop_obj(newf); + pdf_drop_obj(newdp); } static void copystream(pdf_document *xref, pdf_write_options *opts, pdf_obj *obj_orig, int num, int gen) diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index f21ecaf6..c5fc2a83 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -20,10 +20,8 @@ pdf_free_xobject_imp(fz_context *ctx, fz_storable *xobj_) if (xobj->colorspace) fz_drop_colorspace(ctx, xobj->colorspace); - if (xobj->resources) - pdf_drop_obj(xobj->resources); - if (xobj->contents) - pdf_drop_obj(xobj->contents); + pdf_drop_obj(xobj->resources); + pdf_drop_obj(xobj->contents); pdf_drop_obj(xobj->me); fz_free(ctx, xobj); } diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index 6a7585bd..4d3c32b8 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -551,8 +551,7 @@ pdf_ocg_set_config(pdf_document *xref, int config) fz_throw(xref->ctx, "Illegal OCG config"); } - if (desc->intent) - pdf_drop_obj(desc->intent); + pdf_drop_obj(desc->intent); desc->intent = pdf_dict_gets(cobj, "Intent"); if (desc->intent) pdf_keep_obj(desc->intent); @@ -677,8 +676,7 @@ pdf_free_ocg(fz_context *ctx, pdf_ocg_descriptor *desc) if (!desc) return; - if (desc->intent) - pdf_drop_obj(desc->intent); + pdf_drop_obj(desc->intent); fz_free(ctx, desc->ocgs); fz_free(ctx, desc); } @@ -845,8 +843,7 @@ pdf_close_document(pdf_document *xref) if (xref->file) fz_close(xref->file); - if (xref->trailer) - pdf_drop_obj(xref->trailer); + pdf_drop_obj(xref->trailer); if (xref->crypt) pdf_free_crypt(ctx, xref->crypt); @@ -1154,8 +1151,7 @@ pdf_update_object(pdf_document *xref, int num, pdf_obj *newobj) x = &xref->table[num]; - if (x->obj) - pdf_drop_obj(x->obj); + pdf_drop_obj(x->obj); x->type = 'n'; x->ofs = 0; -- cgit v1.2.3 From d44c98001b404a18ccc9d219976b9f32c28922c3 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 19:34:44 +0200 Subject: Set refs to NULL in pdf repair so object are not freed --- pdf/pdf_repair.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index bbe70a2a..e892bc52 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -453,11 +453,13 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) { pdf_dict_puts(xref->trailer, "Root", root); pdf_drop_obj(root); + root = NULL; } if (info) { pdf_dict_puts(xref->trailer, "Info", info); pdf_drop_obj(info); + info = NULL; } if (encrypt) @@ -471,6 +473,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) } pdf_dict_puts(xref->trailer, "Encrypt", encrypt); pdf_drop_obj(encrypt); + encrypt = NULL; } if (id) -- cgit v1.2.3 From ffb37aaa386095d61846419c860eb46b587b6b1d Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 19:35:39 +0200 Subject: Make use of fz_always instead of repeating code for error and normal path --- apps/mudraw.c | 8 +++++--- pdf/pdf_interpret.c | 40 ++++++++++++++++++++++++---------------- pdf/pdf_outline.c | 8 ++++---- pdf/pdf_page.c | 12 ++++++++---- xps/xps_image.c | 6 ++++-- xps/xps_outline.c | 12 ++++++++---- xps/xps_zip.c | 6 ++++-- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/apps/mudraw.c b/apps/mudraw.c index dcd7dafd..0f11a7a1 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -130,15 +130,17 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) dev = fz_new_list_device(ctx, list); fz_run_page(doc, page, dev, fz_identity, &cookie); } - fz_catch(ctx) + fz_always(ctx) { fz_free_device(dev); + dev = NULL; + } + fz_catch(ctx) + { fz_free_display_list(ctx, list); fz_free_page(doc, page); fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename); } - fz_free_device(dev); - dev = NULL; } if (showxml) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index d8b8b9bc..03e09587 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -539,12 +539,14 @@ pdf_show_path(pdf_csi *csi, int doclose, int dofill, int dostroke, int even_odd) if (dofill || dostroke) pdf_end_group(csi); } - fz_catch(ctx) + fz_always(ctx) { fz_free_path(ctx, path); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - fz_free_path(ctx, path); } /* @@ -658,13 +660,14 @@ pdf_flush_text(pdf_csi *csi) pdf_end_group(csi); } - fz_catch(ctx) + fz_always(ctx) { fz_free_text(ctx, text); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - - fz_free_text(ctx, text); } static void @@ -1311,17 +1314,17 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what) { pdf_run_contents_object(csi, pat->resources, pat->contents); } - fz_catch(ctx) + fz_always(ctx) { pdf_grestore(csi); while (oldtop < csi->gtop) pdf_grestore(csi); + } + fz_catch(ctx) + { csi->top_ctm = oldtopctm; fz_throw(ctx, "cannot render pattern tile"); } - pdf_grestore(csi); - while (oldtop < csi->gtop) - pdf_grestore(csi); } } } @@ -1786,13 +1789,14 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) { pdf_run_xobject(csi, xobj->resources, xobj, fz_identity); } - fz_catch(ctx) + fz_always(ctx) { pdf_drop_xobject(ctx, xobj); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } - - pdf_drop_xobject(ctx, xobj); } else if (!strcmp(pdf_to_name(subtype), "Image")) @@ -2317,12 +2321,14 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb) { pdf_show_shade(csi, shd); } - fz_catch(ctx) + fz_always(ctx) { fz_drop_shade(ctx, shd); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - fz_drop_shade(ctx, shd); } } @@ -2872,10 +2878,12 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de { pdf_run_contents_buffer(csi, resources, contents); } - fz_catch(ctx) + fz_always(ctx) { pdf_free_csi(csi); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot parse glyph content stream"); } - pdf_free_csi(csi); } diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index d4bea75a..8f93f5cb 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -43,16 +43,16 @@ pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict) dict = pdf_dict_gets(dict, "Next"); } } - fz_catch(ctx) + fz_always(ctx) { for (dict = odict; dict && pdf_dict_marked(dict); dict = pdf_dict_gets(dict, "Next")) pdf_dict_unmark(dict); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - for (dict = odict; dict && pdf_dict_marked(dict); dict = pdf_dict_gets(dict, "Next")) - pdf_dict_unmark(dict); - return first; } diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 4aa0a893..0733da2f 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -19,12 +19,14 @@ put_marker_bool(fz_context *ctx, pdf_obj *rdb, char *marker, int val) { pdf_dict_puts(rdb, marker, tmp); } - fz_catch(ctx) + fz_always(ctx) { pdf_drop_obj(tmp); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - pdf_drop_obj(tmp); } typedef struct pdf_page_load_s pdf_page_load; @@ -270,12 +272,14 @@ found: useBM = 1; } } - fz_catch(ctx) + fz_always(ctx) { pdf_dict_unmark(rdb); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - pdf_dict_unmark(rdb); put_marker_bool(ctx, rdb, ".useBM", useBM); return useBM; diff --git a/xps/xps_image.c b/xps/xps_image.c index 1f46a756..1a6a8573 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -160,13 +160,15 @@ xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, { image = xps_load_image(doc->ctx, part->data, part->size); } + fz_always(doc->ctx) + { + xps_free_part(doc, part); + } fz_catch(doc->ctx) { fz_warn(doc->ctx, "cannot decode image resource"); - xps_free_part(doc, part); return; } - xps_free_part(doc, part); xps_parse_tiling_brush(doc, ctm, area, base_uri, dict, root, xps_paint_image_brush, image); diff --git a/xps/xps_outline.c b/xps/xps_outline.c index 0feb7b24..21dc0710 100644 --- a/xps/xps_outline.c +++ b/xps/xps_outline.c @@ -88,12 +88,14 @@ xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) { root = xml_parse_document(doc->ctx, part->data, part->size); } - fz_catch(doc->ctx) + fz_always(doc->ctx) { xps_free_part(doc, part); + } + fz_catch(doc->ctx) + { fz_rethrow(doc->ctx); } - xps_free_part(doc, part); if (!root) return NULL; @@ -101,12 +103,14 @@ xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) { outline = xps_parse_document_structure(doc, root); } - fz_catch(doc->ctx) + fz_always(doc->ctx) { xml_free_element(doc->ctx, root); + } + fz_catch(doc->ctx) + { fz_rethrow(doc->ctx); } - xml_free_element(doc->ctx, root); return outline; } diff --git a/xps/xps_zip.c b/xps/xps_zip.c index 17523f10..e7756f89 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -626,12 +626,14 @@ xps_open_document(fz_context *ctx, char *filename) { doc = xps_open_document_with_stream(file); } - fz_catch(ctx) + fz_always(ctx) { fz_close(file); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot load document '%s'", filename); } - fz_close(file); return doc; } -- cgit v1.2.3 From cbfdbd9463ca131f37aded2de7fd52b46e47eb8f Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 4 Aug 2012 19:36:30 +0200 Subject: No need to drop object for which no reference has been kept --- pdf/pdf_xref.c | 1 - 1 file changed, 1 deletion(-) diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index 4d3c32b8..c701d5f0 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -388,7 +388,6 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf) fz_catch(ctx) { pdf_drop_obj(trailer); - pdf_drop_obj(index); fz_rethrow(ctx); } -- cgit v1.2.3 From 6832c5c251608461b3fcba58bd8c6fa2b1a57639 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 13:54:08 +0200 Subject: Free decoded jpx image upon error Thanks to Zeniko for pointing out this fix. --- fitz/image_jpx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c index af5ef263..04bcfecd 100644 --- a/fitz/image_jpx.c +++ b/fitz/image_jpx.c @@ -70,11 +70,20 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs for (k = 1; k < jpx->numcomps; k++) { if (jpx->comps[k].w != jpx->comps[0].w) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different width"); + } if (jpx->comps[k].h != jpx->comps[0].h) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different height"); + } if (jpx->comps[k].prec != jpx->comps[0].prec) + { + opj_image_destroy(jpx); fz_throw(ctx, "image components have different precision"); + } } n = jpx->numcomps; -- cgit v1.2.3 From d4285dea2ccad65678bca52af003860f20b14b63 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 14:36:30 +0200 Subject: Add a make target for measuring code coverage --- Makerules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makerules b/Makerules index 26eab3c3..3e036f61 100644 --- a/Makerules +++ b/Makerules @@ -12,6 +12,9 @@ CFLAGS += -pipe -O2 -DNDEBUG -pg LDFLAGS += -pg else ifeq "$(build)" "release" CFLAGS += -pipe -O2 -DNDEBUG -fomit-frame-pointer +else ifeq "$(build)" "coverage" +CFLAGS += -pipe -g -DDEBUG -pg -fprofile-arcs -ftest-coverage +LIBS += -lgcov else ifeq "$(build)" "native" CFLAGS += -pipe -O2 -DNDEBUG -fomit-frame-pointer -march=native -mfpmath=sse else ifeq "$(build)" "memento" -- cgit v1.2.3 From 0a19ed89da833569e014a05e2077a0819a91e5aa Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 15:12:03 +0200 Subject: Make sure images are freed upon loading error There was a call to fz_drop_image() in the error handling code, however the fz_storable freeing function was not yet set which meant that the image was not freed. Instead call pdf_free_image() to free the image. --- pdf/pdf_image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 58a17ed0..873aeb08 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -456,7 +456,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c } fz_catch(ctx) { - fz_drop_image(ctx, &image->base); + pdf_free_image(ctx, (fz_storable *) image); fz_rethrow(ctx); } return image; -- cgit v1.2.3 From 0fda4705b3194d2158f4dd3998981884cb3e8570 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 15:37:56 +0200 Subject: Upon parse error when repairing, make sure object stream is freed Previously, during repair of a pdf, an object stream was loaded and an attempt was made at repairing the objects stored inside the object stream. Failure to repair the stream caused an exception which was not handled by the code loading the object stream, it was just passed on. This meant that the loaded object stream caused a memory leak. Now we catch that exception, free the object stream and rethrow the exception. --- pdf/pdf_repair.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index e892bc52..8250ebf4 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -506,6 +506,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) void pdf_repair_obj_stms(pdf_document *xref) { + fz_context *ctx = xref->ctx; pdf_obj *dict; int i; @@ -514,9 +515,19 @@ pdf_repair_obj_stms(pdf_document *xref) if (xref->table[i].stm_ofs) { dict = pdf_load_object(xref, i, 0); - if (!strcmp(pdf_to_name(pdf_dict_gets(dict, "Type")), "ObjStm")) - pdf_repair_obj_stm(xref, i, 0); - pdf_drop_obj(dict); + fz_try(ctx) + { + if (!strcmp(pdf_to_name(pdf_dict_gets(dict, "Type")), "ObjStm")) + pdf_repair_obj_stm(xref, i, 0); + } + fz_always(ctx) + { + pdf_drop_obj(dict); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } } } -- cgit v1.2.3 From 697c3cfb34d0b6fe315fc4d303340275ab80c121 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 20:01:04 +0200 Subject: Fix comparison of cmap table length against maximum value The cmap table length counts how many entries there are currently in the table. The table length was previously tested against USHRT_MAX which is 65535. However, the desired value to compare with was 65536 which would be the maximum number of entries allowed in a cmap table. All comparisons of the cmap table length are now using USHRT_MAX + 1. --- pdf/pdf_cmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdf/pdf_cmap.c b/pdf/pdf_cmap.c index cd0d6385..d6cb3103 100644 --- a/pdf/pdf_cmap.c +++ b/pdf/pdf_cmap.c @@ -184,7 +184,7 @@ pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, int low, int high, int n) static void add_table(fz_context *ctx, pdf_cmap *cmap, int value) { - if (cmap->tlen == USHRT_MAX) + if (cmap->tlen >= USHRT_MAX + 1) { fz_warn(ctx, "cmap table is full; ignoring additional entries"); return; @@ -233,7 +233,7 @@ pdf_map_range_to_table(fz_context *ctx, pdf_cmap *cmap, int low, int *table, int int i; int high = low + len; int offset = cmap->tlen; - if (cmap->tlen + len >= USHRT_MAX) + if (cmap->tlen + len >= USHRT_MAX + 1) fz_warn(ctx, "cannot map range to table; table is full"); else { @@ -280,7 +280,7 @@ pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, int low, int *values, int l return; } - if (cmap->tlen + len + 1 >= USHRT_MAX) + if (cmap->tlen + len + 1 >= USHRT_MAX + 1) fz_warn(ctx, "cannot map one to many; table is full"); else { @@ -314,7 +314,7 @@ pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap) qsort(cmap->ranges, cmap->rlen, sizeof(pdf_range), cmprange); - if (cmap->tlen == USHRT_MAX) + if (cmap->tlen >= USHRT_MAX + 1) { fz_warn(ctx, "cmap table is full; will not combine ranges"); return; -- cgit v1.2.3 From 30cea356bb6b5038e7eee642eccb8cf185945a40 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 20:39:00 +0200 Subject: Only warn on stitching function's sub function with wrong arity Sub functions that make up a stitching function can be evaluated with the wrong number of inputs/outputs, so it is not necessary to throw an exception if the number of inputs/outputs do not match when loading sub functions. --- pdf/pdf_function.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 18c16669..590ca626 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -1256,16 +1256,17 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) sub = pdf_array_get(obj, i); funcs[i] = pdf_load_function(xref, sub, 1, func->n); /* RJW: "cannot load sub function %d (%d %d R)", i, pdf_to_num(sub), pdf_to_gen(sub) */ - if (funcs[i]->m != 1 || funcs[i]->n != funcs[0]->n) - fz_throw(ctx, "sub function %d /Domain or /Range mismatch", i); func->size += pdf_function_size(funcs[i]); func->u.st.k ++; - } - if (func->n != funcs[0]->n) - fz_throw(ctx, "sub function /Domain or /Range mismatch"); + if (funcs[i]->m != func->m) + fz_warn(ctx, "sub function %d has too few/many inputs", i); + if (funcs[i]->n != func->n) + fz_warn(ctx, "sub function %d has too few/many outputs", i); + } } + obj = pdf_dict_gets(dict, "Bounds"); if (!pdf_is_array(obj)) fz_throw(ctx, "stitching function has no bounds"); -- cgit v1.2.3 From 8f1909597745d2c881f1cacfff7e0a72eb233438 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 00:13:41 +0200 Subject: Throw exception on too deeply nested arrays/dicts Previously we would run out of error stacks in the context and fail abruptly. Now, throw an exception and hope for the best. At least this plugs any memory leaks. --- fitz/base_error.c | 6 ++++++ fitz/fitz.h | 1 + pdf/pdf_parse.c | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/fitz/base_error.c b/fitz/base_error.c index 71a32a2e..606e9c2a 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -43,6 +43,12 @@ void fz_warn(fz_context *ctx, char *fmt, ...) /* Error context */ +int fz_too_deeply_nested(fz_context *ctx) +{ + fz_error_context *ex = ctx->error; + return ex->top + 1 >= nelem(ex->stack); +} + static void throw(fz_error_context *ex) { if (ex->top >= 0) { diff --git a/fitz/fitz.h b/fitz/fitz.h index 266ec549..63278cb1 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -255,6 +255,7 @@ void fz_push_try(fz_error_context *ex); void fz_throw(fz_context *, char *, ...) __printflike(2, 3); void fz_rethrow(fz_context *); void fz_warn(fz_context *ctx, char *fmt, ...) __printflike(2, 3); +int fz_too_deeply_nested(fz_context *ctx); /* fz_flush_warnings: Flush any repeated warnings. diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index 0ba6b0a4..4ed6b6f1 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -244,6 +244,9 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; case PDF_TOK_OPEN_ARRAY: + if (fz_too_deeply_nested(ctx)) + fz_throw(ctx, "nested too deep, not parsing array"); + obj = pdf_parse_array(xref, file, buf); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -251,6 +254,9 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; case PDF_TOK_OPEN_DICT: + if (fz_too_deeply_nested(ctx)) + fz_throw(ctx, "nested too deep, not parsing dict"); + obj = pdf_parse_dict(xref, file, buf); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -348,10 +354,16 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) switch (tok) { case PDF_TOK_OPEN_ARRAY: + if (fz_too_deeply_nested(ctx)) + fz_throw(ctx, "nested too deep, not parsing array"); + val = pdf_parse_array(xref, file, buf); break; case PDF_TOK_OPEN_DICT: + if (fz_too_deeply_nested(ctx)) + fz_throw(ctx, "nested too deep, not parsing array"); + val = pdf_parse_dict(xref, file, buf); break; -- cgit v1.2.3 From e3e89a4b73a956ffb74d7a49d80f2d58235b7292 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 00:27:42 +0200 Subject: Free inline image dictionary upon error parsing image --- pdf/pdf_interpret.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 03e09587..8c1e40e6 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -1643,9 +1643,19 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) if (fz_peek_byte(file) == '\n') fz_read_byte(file); - img = pdf_load_inline_image(csi->xref, rdb, obj, file); - pdf_drop_obj(obj); - /* RJW: "cannot load inline image" */ + fz_try(ctx) + { + img = pdf_load_inline_image(csi->xref, rdb, obj, file); + } + fz_always(ctx) + { + pdf_drop_obj(obj); + } + fz_catch(ctx) + { + /* RJW: "cannot load inline image" */ + fz_rethrow(ctx); + } pdf_show_image(csi, img); -- cgit v1.2.3 From 5c4eb97b3e89c22278e33480d929e2b2de29fe4d Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:19:26 +0200 Subject: Free old stroke state when initing graphics state from another state Thanks to Zeniko for pointing out this fix. --- pdf/pdf_interpret.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 8c1e40e6..ad4a6cac 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -929,6 +929,8 @@ copy_state(fz_context *ctx, pdf_gstate *gs, pdf_gstate *old) gs->fill = old->fill; gs->font = old->font; gs->softmask = old->softmask; + + fz_drop_stroke_state(ctx, gs->stroke_state); gs->stroke_state = fz_keep_stroke_state(ctx, old->stroke_state); pdf_keep_material(ctx, &gs->stroke); -- cgit v1.2.3 From d8fa625712055f7210e0d2c6d0221f43b6071531 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:33:18 +0200 Subject: Expose both PDF encryption version and revision Thanks to Zeniko for pointing out that version as missing. --- pdf/mupdf-internal.h | 1 + pdf/pdf_crypt.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index 2d5f5d97..efd9e109 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -239,6 +239,7 @@ void pdf_crypt_buffer(fz_context *ctx, pdf_crypt *crypt, fz_buffer *buf, int num fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen); fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen); +int pdf_crypt_version(pdf_document *doc); int pdf_crypt_revision(pdf_document *doc); char *pdf_crypt_method(pdf_document *doc); int pdf_crypt_length(pdf_document *doc); diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 4fc34ea8..5329e845 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -636,13 +636,20 @@ pdf_crypt_key(pdf_document *xref) } int -pdf_crypt_revision(pdf_document *xref) +pdf_crypt_version(pdf_document *xref) { if (xref->crypt) return xref->crypt->v; return 0; } +int pdf_crypt_revision(pdf_document *xref) +{ + if (xref->crypt) + return xref->crypt->r; + return 0; +} + char * pdf_crypt_method(pdf_document *xref) { -- cgit v1.2.3 From 457a5ca61fc04107ce207ab2f40aa73725eb9947 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:33:48 +0200 Subject: Update PDF metadata to include both PDF encryption version and revision --- pdf/pdf_xref.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index c701d5f0..de91db51 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -1189,7 +1189,8 @@ pdf_meta(pdf_document *doc, int key, void *ptr, int size) return FZ_META_OK; case FZ_META_CRYPT_INFO: if (doc->crypt) - sprintf((char *)ptr, "Standard V%d %d-bit %s", + sprintf((char *)ptr, "Standard V%d R%d %d-bit %s", + pdf_crypt_version(doc), pdf_crypt_revision(doc), pdf_crypt_length(doc), pdf_crypt_method(doc)); -- cgit v1.2.3 From a0cbb73ccb175d5f89ff72f205187ac93623f6af Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:48:09 +0200 Subject: Fix locking bug in path stroking Thanks to Zeniko for pointing out this fix. --- fitz/res_path.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fitz/res_path.c b/fitz/res_path.c index d02ea560..a030cc29 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -415,11 +415,10 @@ fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) fz_stroke_state * fz_keep_stroke_state(fz_context *ctx, fz_stroke_state *stroke) { - fz_lock(ctx, FZ_LOCK_ALLOC); - if (!stroke) return NULL; + fz_lock(ctx, FZ_LOCK_ALLOC); if (stroke->refs > 0) stroke->refs++; fz_unlock(ctx, FZ_LOCK_ALLOC); -- cgit v1.2.3 From 9406ed183d4f1b1bb2b44eee08dce751f0f15345 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:50:48 +0200 Subject: Make fz_open_file_*() always throw exceptions upon error Thanks to Zeniko for pointing out the inconsistency. --- fitz/stm_open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 1709340b..3d605e1a 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -140,7 +140,7 @@ fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) - return NULL; + fz_throw(ctx, "cannot open file %Ls", name); return fz_open_fd(ctx, fd); } #endif -- cgit v1.2.3 From 8acf501687f3a406e8779871c306ba2ad76a440b Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 11:54:48 +0200 Subject: Check whether font in xps has charmap before using it Thanks to Zeniko for pointing out this fix. --- xps/xps_glyphs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index 6a7a1dcc..6b262016 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -46,7 +46,7 @@ xps_encode_font_char(fz_font *font, int code) { FT_Face face = font->ft_face; int gid = FT_Get_Char_Index(face, code); - if (gid == 0 && face->charmap->platform_id == 3 && face->charmap->encoding_id == 0) + if (gid == 0 && face->charmap && face->charmap->platform_id == 3 && face->charmap->encoding_id == 0) gid = FT_Get_Char_Index(face, 0xF000 | code); return gid; } -- cgit v1.2.3 From 63777c8847eedd973ca4e62a1a3cd1179dd9e63e Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 14:34:00 +0200 Subject: Free entire type3 font descriptor upon loding error, not just the font --- pdf/pdf_type3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c index bd60216d..aaf47872 100644 --- a/pdf/pdf_type3.c +++ b/pdf/pdf_type3.c @@ -163,8 +163,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) fz_catch(ctx) { if (fontdesc) - fz_drop_font(ctx, fontdesc->font); - fz_free(ctx, fontdesc); + pdf_drop_font(ctx, fontdesc); fz_throw(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; -- cgit v1.2.3 From 7170e67ed5636f2eaf74ea723e29b3d8c2b06467 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 16:01:04 +0200 Subject: Free jpeg state upon decoding error, even if not fully inited Previously the jpeg decoder state had to be fully initialized in order to be freed when the jpeg decoder is closed, e.g. due to an error. Now, signal that the decode state is initialized earlier, even if the state has not been fully initialized, so that the state is freed. --- fitz/filt_dctd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 1b588d2a..76f82abe 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -107,6 +107,7 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) jpeg_std_error(cinfo->err); cinfo->err->error_exit = error_exit; jpeg_create_decompress(cinfo); + state->init = 1; /* Skip over any stray returns at the start of the stream */ while ((c = fz_peek_byte(state->chain)) == '\n' || c == '\r') @@ -165,8 +166,6 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) state->scanline = fz_malloc(state->ctx, state->stride); state->rp = state->scanline; state->wp = state->scanline; - - state->init = 1; } while (state->rp < state->wp && p < ep) -- cgit v1.2.3 From 0db354a6cffc42d1d0ade2b434504b66ec8efba4 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 01:09:05 +0200 Subject: Add option to mudraw to process further files upon error --- apps/mudraw.c | 71 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/apps/mudraw.c b/apps/mudraw.c index 0f11a7a1..07b9e1c3 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -31,6 +31,7 @@ static int width = 0; static int height = 0; static int fit = 0; static int errored = 0; +static int ignore_errors = 0; static fz_text_sheet *sheet = NULL; static fz_colorspace *colorspace; @@ -68,6 +69,7 @@ static void usage(void) "\t-G gamma\tgamma correct output\n" "\t-I\tinvert output\n" "\t-l\tprint outline\n" + "\t-i\tignore errors and continue with the next file\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -447,7 +449,7 @@ int main(int argc, char **argv) fz_var(doc); - while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:f")) != -1) + while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:fi")) != -1) { switch (c) { @@ -469,6 +471,7 @@ int main(int argc, char **argv) case 'h': height = atof(fz_optarg); break; case 'f': fit = 1; break; case 'I': invert++; break; + case 'i': ignore_errors = 1; break; default: usage(); break; } } @@ -531,41 +534,53 @@ int main(int argc, char **argv) { while (fz_optind < argc) { - filename = argv[fz_optind++]; - files++; - fz_try(ctx) { - doc = fz_open_document(ctx, filename); - } - fz_catch(ctx) - { - fz_throw(ctx, "cannot open document: %s", filename); - } + filename = argv[fz_optind++]; + files++; - if (fz_needs_password(doc)) - if (!fz_authenticate_password(doc, password)) - fz_throw(ctx, "cannot authenticate password: %s", filename); + fz_try(ctx) + { + doc = fz_open_document(ctx, filename); + } + fz_catch(ctx) + { + fz_throw(ctx, "cannot open document: %s", filename); + } - if (showxml || showtext == TEXT_XML) - printf("\n", filename); + if (fz_needs_password(doc)) + if (!fz_authenticate_password(doc, password)) + fz_throw(ctx, "cannot authenticate password: %s", filename); - if (showoutline) - drawoutline(ctx, doc); + if (showxml || showtext == TEXT_XML) + printf("\n", filename); - if (showtext || showxml || showtime || showmd5 || output) - { - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(ctx, doc, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(ctx, doc, argv[fz_optind++]); - } + if (showoutline) + drawoutline(ctx, doc); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(ctx, doc, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(ctx, doc, argv[fz_optind++]); + } + + if (showxml || showtext == TEXT_XML) + printf("\n"); - if (showxml || showtext == TEXT_XML) - printf("\n"); + fz_close_document(doc); + doc = NULL; + } + fz_catch(ctx) + { + if (!ignore_errors) + fz_rethrow(ctx); - fz_close_document(doc); - doc = NULL; + fz_close_document(doc); + doc = NULL; + fz_warn(ctx, "ignoring error in '%s'", filename); + } } } fz_catch(ctx) -- cgit v1.2.3 From 23f97fdf96e65173def430f88a76df1c85d8339e Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 13:50:16 +0200 Subject: Rewording of warning messages for PDF functions --- pdf/pdf_function.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 590ca626..90789ee7 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -958,7 +958,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, { int ranges = fz_mini(func->m, pdf_array_len(obj) / 2); if (ranges != func->m) - fz_warn(ctx, "too few/many sample function input mappings"); + fz_warn(ctx, "wrong number of sample function input mappings"); for (i = 0; i < ranges; i++) { @@ -978,7 +978,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, { int ranges = fz_mini(func->n, pdf_array_len(obj) / 2); if (ranges != func->n) - fz_warn(ctx, "too few/many sample function output mappings"); + fz_warn(ctx, "wrong number of sample function output mappings"); for (i = 0; i < ranges; i++) { @@ -1179,7 +1179,7 @@ load_exponential_func(fz_context *ctx, pdf_function *func, pdf_obj *dict) { int ranges = fz_mini(func->n, pdf_array_len(obj)); if (ranges != func->n) - fz_warn(ctx, "too few/many C0 constants for exponential function"); + fz_warn(ctx, "wrong number of C0 constants for exponential function"); for (i = 0; i < ranges; i++) func->u.e.c0[i] = pdf_to_real(pdf_array_get(obj, i)); @@ -1190,7 +1190,7 @@ load_exponential_func(fz_context *ctx, pdf_function *func, pdf_obj *dict) { int ranges = fz_mini(func->n, pdf_array_len(obj)); if (ranges != func->n) - fz_warn(ctx, "too few/many C1 constants for exponential function"); + fz_warn(ctx, "wrong number of C1 constants for exponential function"); for (i = 0; i < ranges; i++) func->u.e.c1[i] = pdf_to_real(pdf_array_get(obj, i)); @@ -1260,9 +1260,9 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) func->u.st.k ++; if (funcs[i]->m != func->m) - fz_warn(ctx, "sub function %d has too few/many inputs", i); + fz_warn(ctx, "wrong number of inputs for sub function %d", i); if (funcs[i]->n != func->n) - fz_warn(ctx, "sub function %d has too few/many outputs", i); + fz_warn(ctx, "wrong number of outputs for sub function %d", i); } } @@ -1300,7 +1300,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) { int ranges = fz_mini(k, pdf_array_len(obj) / 2); if (ranges != k) - fz_warn(ctx, "too few/many stitching function input mappings"); + fz_warn(ctx, "wrong number of stitching function input mappings"); for (i = 0; i < ranges; i++) { @@ -1449,9 +1449,9 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) } if (func->m != in) - fz_warn(ctx, "too few/many function inputs"); + fz_warn(ctx, "wrong number of function inputs"); if (func->n != out) - fz_warn(ctx, "too few/many function outputs"); + fz_warn(ctx, "wrong number of function outputs"); fz_try(ctx) { -- cgit v1.2.3 From 1ce75e79683b5df7046bdddbc0dad4b11805a73b Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 14:14:19 +0200 Subject: Handle out of range encoding differences for type3 fonts Thanks to Zeniko for pointing out this fix. --- pdf/pdf_font.c | 2 +- pdf/pdf_type3.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index d43d45d4..4f630184 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -546,7 +546,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict) item = pdf_array_get(diff, i); if (pdf_is_int(item)) k = pdf_to_int(item); - if (pdf_is_name(item) && k >= 0 && k < 256) + if (pdf_is_name(item) && k >= 0 && k < nelem(estrings)) estrings[k++] = pdf_to_name(item); } } diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c index aaf47872..4fc7803e 100644 --- a/pdf/pdf_type3.c +++ b/pdf/pdf_type3.c @@ -87,9 +87,8 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) item = pdf_array_get(diff, i); if (pdf_is_int(item)) k = pdf_to_int(item); - if (pdf_is_name(item)) + if (pdf_is_name(item) && k >= 0 && k < nelem(estrings)) estrings[k++] = pdf_to_name(item); - k = fz_clampi(k, 0, 255); } } } -- cgit v1.2.3 From 2f9a718a565195f3bd28a283ab372be8b4430f00 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 14:26:03 +0200 Subject: Remove old error mesages turned into comments when adding exceptions --- fitz/res_font.c | 2 -- pdf/pdf_cmap_parse.c | 19 ------------------- pdf/pdf_colorspace.c | 4 ---- pdf/pdf_font.c | 9 +-------- pdf/pdf_function.c | 9 +-------- pdf/pdf_image.c | 11 +---------- pdf/pdf_interpret.c | 28 +++------------------------- pdf/pdf_parse.c | 10 +--------- pdf/pdf_repair.c | 5 +---- pdf/pdf_shade.c | 3 --- pdf/pdf_stream.c | 8 -------- pdf/pdf_unicode.c | 2 -- pdf/pdf_xref.c | 3 --- 13 files changed, 8 insertions(+), 105 deletions(-) diff --git a/fitz/res_font.c b/fitz/res_font.c index a68a1ff1..50420d97 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -911,7 +911,6 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co ctm = fz_concat(font->t3matrix, trm); dev = fz_new_draw_device_type3(ctx, glyph); font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, NULL); - /* RJW: "cannot draw type3 glyph" */ fz_free_device(dev); if (!model) @@ -953,7 +952,6 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi ctm = fz_concat(font->t3matrix, trm); font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, gstate); - /* RJW: "cannot draw type3 glyph" */ } #ifndef NDEBUG diff --git a/pdf/pdf_cmap_parse.c b/pdf/pdf_cmap_parse.c index b78a36ec..7f2587ec 100644 --- a/pdf/pdf_cmap_parse.c +++ b/pdf/pdf_cmap_parse.c @@ -53,8 +53,6 @@ pdf_lex_cmap(fz_stream *file, pdf_lexbuf *buf) { int tok = pdf_lex(file, buf); - /* RJW: Lost debugging here: "cannot parse cmap token" */ - if (tok == PDF_TOK_KEYWORD) tok = pdf_cmap_token_from_keyword(buf->scratch); @@ -67,7 +65,6 @@ pdf_parse_cmap_name(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf int tok; tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok == PDF_TOK_NAME) fz_strlcpy(cmap->cmap_name, buf->scratch, sizeof(cmap->cmap_name)); @@ -81,7 +78,6 @@ pdf_parse_wmode(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *bu int tok; tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok == PDF_TOK_INT) pdf_set_cmap_wmode(ctx, cmap, buf->i); @@ -98,7 +94,6 @@ pdf_parse_codespace_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_ while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok == TOK_END_CODESPACE_RANGE) return; @@ -107,7 +102,6 @@ pdf_parse_codespace_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_ { lo = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok == PDF_TOK_STRING) { hi = pdf_code_from_string(buf->scratch, buf->len); @@ -131,7 +125,6 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok == TOK_END_CID_RANGE) return; @@ -142,14 +135,12 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf lo = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok != PDF_TOK_STRING) fz_throw(ctx, "expected string"); hi = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: Lost debugging: "syntaxerror in cmap" */ if (tok != PDF_TOK_INT) fz_throw(ctx, "expected integer"); @@ -168,7 +159,6 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok == TOK_END_CID_CHAR) return; @@ -179,8 +169,6 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf src = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ - if (tok != PDF_TOK_INT) fz_throw(ctx, "expected integer"); @@ -200,7 +188,6 @@ pdf_parse_bf_range_array(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_l while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok == PDF_TOK_CLOSE_ARRAY) return; @@ -230,7 +217,6 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok == TOK_END_BF_RANGE) return; @@ -241,14 +227,12 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf lo = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok != PDF_TOK_STRING) fz_throw(ctx, "expected string"); hi = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok == PDF_TOK_STRING) { @@ -280,7 +264,6 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf else if (tok == PDF_TOK_OPEN_ARRAY) { pdf_parse_bf_range_array(ctx, cmap, file, buf, lo, hi); - /* RJW: "cannot map bfrange" */ } else @@ -301,7 +284,6 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf * while (1) { tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ if (tok == TOK_END_BF_CHAR) return; @@ -312,7 +294,6 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf * src = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex_cmap(file, buf); - /* RJW: "syntaxerror in cmap" */ /* Note: does not handle /dstName */ if (tok != PDF_TOK_STRING) fz_throw(ctx, "expected string"); diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index 7a3835dd..7ebda6cf 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -115,7 +115,6 @@ load_separation(pdf_document *xref, pdf_obj *array) fz_throw(ctx, "too many components in colorspace"); base = pdf_load_colorspace(xref, baseobj); - /* RJW: "cannot load base colorspace (%d %d R)", pdf_to_num(baseobj), pdf_to_gen(baseobj) */ fz_try(ctx) { @@ -234,7 +233,6 @@ load_indexed(pdf_document *xref, pdf_obj *array) fz_try(ctx) { base = pdf_load_colorspace(xref, baseobj); - /* "cannot load base colorspace (%d %d R)", pdf_to_num(baseobj), pdf_to_gen(baseobj) */ idx = fz_malloc_struct(ctx, struct indexed); idx->lookup = NULL; @@ -340,7 +338,6 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) } return pdf_load_colorspace(xref, obj); - /* RJW: "cannot load pattern (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ } else if (!strcmp(pdf_to_name(name), "G")) @@ -399,7 +396,6 @@ pdf_load_colorspace(pdf_document *xref, pdf_obj *obj) } cs = pdf_load_colorspace_imp(xref, obj); - /* RJW: "cannot load colorspace (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ pdf_store_item(ctx, obj, cs, cs->size); diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index 4f630184..d92b67d8 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -186,7 +186,6 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname) fz_throw(ctx, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); - /* RJW: "cannot load freetype font from memory" */ if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; @@ -203,7 +202,6 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam fz_throw(ctx, "cannot find substitute font"); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); - /* RJW: "cannot load freetype font from memory" */ fontdesc->font->ft_substitute = 1; fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face); @@ -222,7 +220,6 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon /* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */ fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0); - /* RJW: "cannot load builtin CJK font" */ fontdesc->font->ft_substitute = 1; } @@ -462,7 +459,6 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict) fontdesc->encoding = pdf_load_system_cmap(ctx, "GBK-EUC-H"); fontdesc->to_unicode = pdf_load_system_cmap(ctx, "Adobe-GB1-UCS2"); fontdesc->to_ttf_cmap = pdf_load_system_cmap(ctx, "Adobe-GB1-UCS2"); - /* RJW: "cannot load font" */ face = fontdesc->font->ft_face; kind = ft_kind(face); @@ -865,12 +861,10 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ fontdesc->to_ttf_cmap = pdf_load_system_cmap(ctx, "Adobe-Japan2-UCS2"); else if (!strcmp(collection, "Adobe-Korea1")) fontdesc->to_ttf_cmap = pdf_load_system_cmap(ctx, "Adobe-Korea1-UCS2"); - /* RJW: "cannot load system cmap %s", collection */ } } pdf_load_to_unicode(xref, fontdesc, NULL, collection, to_unicode); - /* RJW: "cannot load to_unicode" */ /* Horizontal */ @@ -999,7 +993,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict) return load_cid_font(xref, dfont, encoding, to_unicode); else fz_throw(xref->ctx, "syntaxerror: unknown cid font type"); - /* RJW: "cannot load descendant font (%d %d R)", pdf_to_num(dfont), pdf_to_gen(dfont) */ + return NULL; /* Stupid MSVC */ } @@ -1144,7 +1138,6 @@ pdf_load_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) fz_warn(ctx, "unknown font format, guessing type1 or truetype."); fontdesc = pdf_load_simple_font(xref, dict); } - /* RJW: "cannot load font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */ /* Save the widths to stretch non-CJK substitute fonts */ if (fontdesc->font->ft_substitute && !fontdesc->to_ttf_cmap) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 90789ee7..c9bbc5b5 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -711,7 +711,6 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) while (1) { tok = pdf_lex(stream, buf); - /* RJW: "calculator function lexical error" */ switch(tok) { @@ -754,19 +753,15 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) ifptr = *codeptr; parse_code(func, stream, codeptr, buf); - /* RJW: "error in 'if' branch" */ tok = pdf_lex(stream, buf); - /* RJW: "calculator function syntax error" */ if (tok == PDF_TOK_OPEN_BRACE) { elseptr = *codeptr; parse_code(func, stream, codeptr, buf); - /* RJW: "error in 'else' branch" */ tok = pdf_lex(stream, buf); - /* RJW: "calculator function syntax error" */ } else { @@ -861,7 +856,6 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int fz_try(ctx) { stream = pdf_open_stream(xref, num, gen); - /* RJW: "cannot open calculator function stream" */ tok = pdf_lex(stream, &buf); if (tok != PDF_TOK_OPEN_BRACE) @@ -997,7 +991,6 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, func->size += samplecount * sizeof(float); stream = pdf_open_stream(xref, num, gen); - /* RJW: "cannot open samples stream (%d %d R)", num, gen */ /* read samples */ for (i = 0; i < samplecount; i++) @@ -1255,7 +1248,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) { sub = pdf_array_get(obj, i); funcs[i] = pdf_load_function(xref, sub, 1, func->n); - /* RJW: "cannot load sub function %d (%d %d R)", i, pdf_to_num(sub), pdf_to_gen(sub) */ + func->size += pdf_function_size(funcs[i]); func->u.st.k ++; diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 873aeb08..249e2c65 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -317,7 +317,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c if (pdf_is_jpx_image(ctx, dict)) { pdf_load_jpx(xref, dict, image); - /* RJW: "cannot load jpx image" */ + if (forcemask) { fz_pixmap *mask_pixmap; @@ -368,7 +368,6 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c } image->base.colorspace = pdf_load_colorspace(xref, obj); - /* RJW: "cannot load image colorspace" */ if (!strcmp(image->base.colorspace->name, "Indexed")) indexed = 1; @@ -400,7 +399,6 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c if (!cstm) { mask = (fz_image *)pdf_load_image_imp(xref, rdb, obj, NULL, 1); - /* RJW: "cannot load image mask/softmask" */ } } else if (pdf_is_array(obj)) @@ -449,7 +447,6 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c else { stm = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict)); - /* RJW: "cannot open image data stream (%d 0 R)", pdf_to_num(dict) */ } image->tile = decomp_image_from_stream(ctx, stm, image, cstm != NULL, indexed, 1, 0); @@ -466,7 +463,6 @@ fz_image * pdf_load_inline_image(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *file) { return (fz_image *)pdf_load_image_imp(xref, rdb, dict, file, 0); - /* RJW: "cannot load inline image" */ } int @@ -500,7 +496,6 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) fz_var(colorspace); buf = pdf_load_stream(xref, pdf_to_num(dict), pdf_to_gen(dict)); - /* RJW: "cannot load jpx image data" */ /* FIXME: We can't handle decode arrays for indexed images currently */ fz_try(ctx) @@ -509,12 +504,10 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) if (obj) { colorspace = pdf_load_colorspace(xref, obj); - /* RJW: "cannot load image colorspace" */ indexed = !strcmp(colorspace->name, "Indexed"); } img = fz_load_jpx(ctx, buf->data, buf->len, colorspace, indexed); - /* RJW: "cannot load jpx image" */ if (img && colorspace == NULL) colorspace = fz_keep_colorspace(ctx, img->colorspace); @@ -526,7 +519,6 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) if (pdf_is_dict(obj)) { image->base.mask = (fz_image *)pdf_load_image_imp(xref, NULL, obj, NULL, 1); - /* RJW: "cannot load image mask/softmask" */ } obj = pdf_dict_getsa(dict, "Decode", "D"); @@ -584,7 +576,6 @@ pdf_load_image(pdf_document *xref, pdf_obj *dict) } image = pdf_load_image_imp(xref, NULL, dict, NULL, 0); - /* RJW: "cannot load image (%d 0 R)", pdf_to_num(dict) */ pdf_store_item(ctx, dict, image, pdf_image_size(ctx, image)); diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index ad4a6cac..704f6e78 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -319,7 +319,7 @@ pdf_begin_group(pdf_csi *csi, fz_rect bbox) fz_begin_mask(csi->dev, bbox, gstate->luminosity, softmask->colorspace, gstate->softmask_bc); pdf_run_xobject(csi, NULL, softmask, fz_identity); - /* RJW: "cannot run softmask" */ + fz_end_mask(csi->dev); gstate->softmask = softmask; @@ -1296,7 +1296,6 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what) csi->top_ctm = gstate->ctm; pdf_gsave(csi); pdf_run_contents_object(csi, pat->resources, pat->contents); - /* RJW: "cannot render pattern tile" */ pdf_grestore(csi); while (oldtop < csi->gtop) pdf_grestore(csi); @@ -1378,7 +1377,6 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, fz_matrix t fz_begin_mask(csi->dev, bbox, gstate->luminosity, softmask->colorspace, gstate->softmask_bc); pdf_run_xobject(csi, resources, softmask, fz_identity); - /* RJW: "cannot run softmask" */ fz_end_mask(csi->dev); pdf_drop_xobject(ctx, softmask); @@ -1412,7 +1410,6 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, fz_matrix t resources = xobj->resources; pdf_run_contents_object(csi, resources, xobj->contents); - /* RJW: "cannot interpret XObject stream" */ } fz_always(ctx) { @@ -1472,7 +1469,6 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) } gstate->font = pdf_load_font(csi->xref, rdb, font); - /* RJW: "cannot load font (%d %d R)", pdf_to_num(font), pdf_to_gen(font) */ if (!gstate->font) fz_throw(ctx, "cannot find font in store"); gstate->size = pdf_to_real(pdf_array_get(val, 1)); @@ -1554,7 +1550,6 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) if (!group) fz_throw(ctx, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val)); xobj = pdf_load_xobject(csi->xref, group); - /* RJW: "cannot load xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val) */ colorspace = xobj->colorspace; if (!colorspace) @@ -1637,7 +1632,6 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) pdf_obj *obj; obj = pdf_parse_dict(csi->xref, file, &csi->xref->lexbuf.base); - /* RJW: "cannot parse inline image dictionary" */ /* read whitespace after ID keyword */ ch = fz_read_byte(file); @@ -1655,7 +1649,6 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) } fz_catch(ctx) { - /* RJW: "cannot load inline image" */ fz_rethrow(ctx); } @@ -1732,7 +1725,6 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what) if (!obj) fz_throw(ctx, "cannot find colorspace resource '%s'", csi->name); colorspace = pdf_load_colorspace(csi->xref, obj); - /* RJW: "cannot load colorspace (%d 0 R)", pdf_to_num(obj) */ } pdf_set_colorspace(csi, what, colorspace); @@ -1746,7 +1738,6 @@ static void pdf_run_CS(pdf_csi *csi, pdf_obj *rdb) csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; pdf_run_cs_imp(csi, rdb, PDF_STROKE); - /* RJW: "cannot set colorspace" */ } static void pdf_run_cs(pdf_csi *csi, pdf_obj *rdb) @@ -1754,7 +1745,6 @@ static void pdf_run_cs(pdf_csi *csi, pdf_obj *rdb) csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; pdf_run_cs_imp(csi, rdb, PDF_FILL); - /* RJW: "cannot set colorspace" */ } static void pdf_run_DP(pdf_csi *csi) @@ -1791,7 +1781,6 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) pdf_xobject *xobj; xobj = pdf_load_xobject(csi->xref, obj); - /* RJW: "cannot load xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ /* Inherit parent resources, in case this one was empty XXX check where it's loaded */ if (!xobj->resources) @@ -1816,7 +1805,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) if ((csi->dev->hints & FZ_IGNORE_IMAGE) == 0) { fz_image *img = pdf_load_image(csi->xref, obj); - /* RJW: "cannot load image (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ + fz_try(ctx) { pdf_show_image(csi, img); @@ -1955,7 +1944,6 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m { pdf_pattern *pat; pat = pdf_load_pattern(csi->xref, obj); - /* RJW: "cannot load pattern (%d 0 R)", pdf_to_num(obj) */ pdf_set_pattern(csi, what, pat, csi->top > 0 ? csi->stack : NULL); pdf_drop_pattern(ctx, pat); } @@ -1963,7 +1951,6 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m { fz_shade *shd; shd = pdf_load_shading(csi->xref, obj); - /* RJW: "cannot load shading (%d 0 R)", pdf_to_num(obj) */ pdf_set_shade(csi, what, shd); fz_drop_shade(ctx, shd); } @@ -1983,7 +1970,6 @@ static void pdf_run_SC(pdf_csi *csi, pdf_obj *rdb) pdf_gstate *gstate = csi->gstate + csi->gtop; csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; pdf_run_SC_imp(csi, rdb, PDF_STROKE, &gstate->stroke); - /* RJW: "cannot set color and colorspace" */ } static void pdf_run_sc(pdf_csi *csi, pdf_obj *rdb) @@ -1991,7 +1977,6 @@ static void pdf_run_sc(pdf_csi *csi, pdf_obj *rdb) pdf_gstate *gstate = csi->gstate + csi->gtop; csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; pdf_run_SC_imp(csi, rdb, PDF_FILL, &gstate->fill); - /* RJW: "cannot set color and colorspace" */ } static void pdf_run_Tc(pdf_csi *csi) @@ -2041,7 +2026,6 @@ static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb) fz_throw(ctx, "cannot find font resource: '%s'", csi->name); gstate->font = pdf_load_font(csi->xref, rdb, obj); - /* RJW: "cannot load font (%d 0 R)", pdf_to_num(obj) */ } static void pdf_run_Tr(pdf_csi *csi) @@ -2224,7 +2208,6 @@ static void pdf_run_gs(pdf_csi *csi, pdf_obj *rdb) fz_throw(ctx, "cannot find extgstate resource '%s'", csi->name); pdf_run_extgstate(csi, rdb, obj); - /* RJW: "cannot set ExtGState (%d 0 R)", pdf_to_num(obj) */ } static void pdf_run_h(pdf_csi *csi) @@ -2328,7 +2311,7 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb) if ((csi->dev->hints & FZ_IGNORE_SHADE) == 0) { shd = pdf_load_shading(csi->xref, obj); - /* RJW: "cannot load shading (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ + fz_try(ctx) { pdf_show_shade(csi, shd); @@ -2437,7 +2420,6 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) case C('B','D','C'): pdf_run_BDC(csi, rdb); break; case B('B','I'): pdf_run_BI(csi, rdb, file); - /* RJW: "cannot draw inline image" */ break; case C('B','M','C'): pdf_run_BMC(csi); break; case B('B','T'): pdf_run_BT(csi); break; @@ -2590,7 +2572,6 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) } tok = pdf_lex(file, buf); - /* RJW: "lexical error in content stream" */ if (in_array) { @@ -2636,7 +2617,6 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) if (!csi->in_text) { csi->obj = pdf_parse_array(csi->xref, file, buf); - /* RJW: "cannot parse array" */ } else { @@ -2646,7 +2626,6 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) case PDF_TOK_OPEN_DICT: csi->obj = pdf_parse_dict(csi->xref, file, buf); - /* RJW: "cannot parse dictionary" */ break; case PDF_TOK_NAME: @@ -2688,7 +2667,6 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) { tok = PDF_TOK_EOF; } - /* RJW: "cannot run keyword" */ pdf_clear_stack(csi); break; diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index 4ed6b6f1..6f27099f 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -429,16 +429,13 @@ pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) fz_context *ctx = file->ctx; tok = pdf_lex(file, buf); - /* RJW: "cannot parse token in object stream") */ switch (tok) { case PDF_TOK_OPEN_ARRAY: return pdf_parse_array(xref, file, buf); - /* RJW: "cannot parse object stream" */ case PDF_TOK_OPEN_DICT: return pdf_parse_dict(xref, file, buf); - /* RJW: "cannot parse object stream" */ case PDF_TOK_NAME: return fz_new_name(ctx, buf->scratch); break; case PDF_TOK_REAL: return pdf_new_real(ctx, buf->f); break; case PDF_TOK_STRING: return pdf_new_string(ctx, buf->scratch, buf->len); break; @@ -475,23 +472,19 @@ pdf_parse_ind_obj(pdf_document *xref, gen = buf->i; tok = pdf_lex(file, buf); - /* RJW: "cannot parse indirect object (%d %d R)", num, gen */ if (tok != PDF_TOK_OBJ) fz_throw(ctx, "expected 'obj' keyword (%d %d ?)", num, gen); tok = pdf_lex(file, buf); - /* RJW: "cannot parse indirect object (%d %d R)", num, gen */ switch (tok) { case PDF_TOK_OPEN_ARRAY: obj = pdf_parse_array(xref, file, buf); - /* RJW: "cannot parse indirect object (%d %d R)", num, gen */ break; case PDF_TOK_OPEN_DICT: obj = pdf_parse_dict(xref, file, buf); - /* RJW: "cannot parse indirect object (%d %d R)", num, gen */ break; case PDF_TOK_NAME: obj = fz_new_name(ctx, buf->scratch); break; @@ -504,7 +497,7 @@ pdf_parse_ind_obj(pdf_document *xref, case PDF_TOK_INT: a = buf->i; tok = pdf_lex(file, buf); - /* "cannot parse indirect object (%d %d R)", num, gen */ + if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ) { obj = pdf_new_int(ctx, a); @@ -514,7 +507,6 @@ pdf_parse_ind_obj(pdf_document *xref, { b = buf->i; tok = pdf_lex(file, buf); - /* RJW: "cannot parse indirect object (%d %d R)", num, gen); */ if (tok == PDF_TOK_R) { obj = pdf_new_indirect(ctx, a, b, xref); diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index 8250ebf4..a3efa030 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -29,7 +29,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf stm_len = 0; tok = pdf_lex(file, buf); - /* RJW: "cannot parse object" */ + if (tok == PDF_TOK_OPEN_DICT) { pdf_obj *dict, *obj; @@ -80,7 +80,6 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf tok != PDF_TOK_INT ) { tok = pdf_lex(file, buf); - /* RJW: "cannot scan for endobj or stream token" */ } if (tok == PDF_TOK_INT) @@ -134,7 +133,6 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf atobjend: tok = pdf_lex(file, buf); - /* RJW: "cannot scan for endobj token" */ if (tok != PDF_TOK_ENDOBJ) fz_warn(ctx, "object missing 'endobj' token"); } @@ -412,7 +410,6 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) if (list[i].stm_len >= 0) { dict = pdf_load_object(xref, list[i].num, list[i].gen); - /* RJW: "cannot load stream object (%d %d R)", list[i].num, list[i].gen */ length = pdf_new_int(ctx, list[i].stm_len); pdf_dict_puts(dict, "Length", length); diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index 9e056c14..39e71626 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -1019,7 +1019,6 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, fz_matrix transform) if (!obj) fz_throw(ctx, "shading colorspace is missing"); shade->colorspace = pdf_load_colorspace(xref, obj); - /* RJW: "cannot load colorspace (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ obj = pdf_dict_gets(dict, "Background"); if (obj) @@ -1143,14 +1142,12 @@ pdf_load_shading(pdf_document *xref, pdf_obj *dict) fz_throw(ctx, "syntaxerror: missing shading dictionary"); shade = pdf_load_shading_dict(xref, obj, mat); - /* RJW: "cannot load shading dictionary (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ } /* Naked shading dictionary */ else { shade = pdf_load_shading_dict(xref, dict, fz_identity); - /* RJW: "cannot load shading dictionary (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */ } pdf_store_item(ctx, dict, shade, fz_shade_size(shade)); diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index a4af8e39..00552ff4 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -11,7 +11,6 @@ pdf_is_stream(pdf_document *xref, int num, int gen) return 0; pdf_cache_object(xref, num, gen); - /* RJW: "cannot load object, ignoring error" */ return xref->table[num].stm_ofs != 0 || xref->table[num].stm_buf; } @@ -326,7 +325,6 @@ pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_nu x = xref->table + num; pdf_cache_object(xref, num, gen); - /* RJW: "cannot load stream object (%d %d R)", num, gen */ if (x->stm_ofs == 0) fz_throw(xref->ctx, "object is not a stream"); @@ -356,7 +354,6 @@ pdf_open_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or x = xref->table + num; pdf_cache_object(xref, num, gen); - /* RJW: "cannot load stream object (%d %d R)", num, gen */ if (x->stm_ofs == 0 && x->stm_buf == NULL) fz_throw(xref->ctx, "object is not a stream"); @@ -438,17 +435,14 @@ pdf_load_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_nu return fz_keep_buffer(xref->ctx, xref->table[num].stm_buf); dict = pdf_load_object(xref, num, gen); - /* RJW: "cannot load stream dictionary (%d %d R)", num, gen */ len = pdf_to_int(pdf_dict_gets(dict, "Length")); pdf_drop_obj(dict); stm = pdf_open_raw_renumbered_stream(xref, num, gen, orig_num, orig_gen); - /* RJW: "cannot open raw stream (%d %d R)", num, gen */ buf = fz_read_all(stm, len); - /* RJW: "cannot read raw stream (%d %d R)", num, gen */ fz_close(stm); return buf; @@ -500,7 +494,6 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or return fz_keep_buffer(xref->ctx, xref->table[num].stm_buf); dict = pdf_load_object(xref, num, gen); - /* RJW: "cannot load stream dictionary (%d %d R)", num, gen */ len = pdf_to_int(pdf_dict_gets(dict, "Length")); obj = pdf_dict_gets(dict, "Filter"); @@ -512,7 +505,6 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or pdf_drop_obj(dict); stm = pdf_open_image_stream(xref, num, gen, orig_num, orig_gen, params); - /* RJW: "cannot open stream (%d %d R)", num, gen */ fz_try(ctx) { diff --git a/pdf/pdf_unicode.c b/pdf/pdf_unicode.c index c94a6683..a6e14d9b 100644 --- a/pdf/pdf_unicode.c +++ b/pdf/pdf_unicode.c @@ -17,7 +17,6 @@ pdf_load_to_unicode(pdf_document *xref, pdf_font_desc *font, if (pdf_is_stream(xref, pdf_to_num(cmapstm), pdf_to_gen(cmapstm))) { cmap = pdf_load_embedded_cmap(xref, cmapstm); - /* RJW: "cannot load embedded cmap (%d %d R)", pdf_to_num(cmapstm), pdf_to_gen(cmapstm) */ font->to_unicode = pdf_new_cmap(ctx); @@ -52,7 +51,6 @@ pdf_load_to_unicode(pdf_document *xref, pdf_font_desc *font, font->to_unicode = pdf_load_system_cmap(ctx, "Adobe-Korea1-UCS2"); return; - /* RJW: "cannot load ToUnicode system cmap %s-UCS2", collection */ } if (strings) diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index de91db51..050a6f53 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -363,12 +363,10 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf) index = pdf_dict_gets(trailer, "Index"); stm = pdf_open_stream_with_offset(xref, num, gen, trailer, stm_ofs); - /* RJW: Ensure pdf_open_stream does fz_throw(ctx, "cannot open compressed xref stream (%d %d R)", num, gen); */ if (!index) { pdf_read_new_xref_section(xref, stm, 0, size, w0, w1, w2); - /* RJW: Ensure above does fz_throw(ctx, "cannot read xref stream (%d %d R)", num, gen); */ } else { @@ -931,7 +929,6 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf) fz_seek(stm, first + ofsbuf[i], 0); obj = pdf_parse_stm_obj(xref, stm, buf); - /* RJW: Ensure above does fz_throw(ctx, "cannot parse object %d in stream (%d %d R)", i, num, gen); */ if (numbuf[i] < 1 || numbuf[i] >= xref->len) { -- cgit v1.2.3 From 9c021377135a931a11bab58d6fe30353a98f1092 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 15:07:52 +0200 Subject: Check for a display list before trying to render it in pdfapp Previously fix 13943b92f10796efb175e769afe5b0aea85d879a introduced continued rendering of further pages for documents where one page failed to load. However, if the entire page tree was missing from a PDF document then no display list would be obtained, yet MuPDF tried to render the display list causing a null pointer dereference. Now, check for a valid display list before trying to render it. --- apps/pdfapp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 50a89610..1a17e172 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -326,9 +326,12 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai /* Extract text */ app->page_sheet = fz_new_text_sheet(app->ctx); app->page_text = fz_new_text_page(app->ctx, app->page_bbox); - tdev = fz_new_text_device(app->ctx, app->page_sheet, app->page_text); - fz_run_display_list(app->page_list, tdev, fz_identity, fz_infinite_bbox, &cookie); - fz_free_device(tdev); + if (app->page_list) + { + tdev = fz_new_text_device(app->ctx, app->page_sheet, app->page_text); + fz_run_display_list(app->page_list, tdev, fz_identity, fz_infinite_bbox, &cookie); + fz_free_device(tdev); + } } if (drawpage) @@ -365,9 +368,12 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai #endif app->image = fz_new_pixmap_with_bbox(app->ctx, colorspace, bbox); fz_clear_pixmap_with_value(app->ctx, app->image, 255); - idev = fz_new_draw_device(app->ctx, app->image); - fz_run_display_list(app->page_list, idev, ctm, bbox, &cookie); - fz_free_device(idev); + if (app->page_list) + { + idev = fz_new_draw_device(app->ctx, app->image); + fz_run_display_list(app->page_list, idev, ctm, bbox, &cookie); + fz_free_device(idev); + } if (app->invert) fz_invert_pixmap(app->ctx, app->image); } -- cgit v1.2.3 From 45753e5b4a9b3370d6411d8400826014ac0fcce7 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 6 Aug 2012 15:31:00 +0200 Subject: Fix leak of page objects/refs for documents without page tree PDF documents that do not have a page tree will have zero pages. Calling fz_count_pages() twice or more on those documents will have pdf_load_page_tree() repeatedly trying to load the page tree, each time leaking the page objects/refs arrays. Thanks to Zeniko for pointing out this fix. --- pdf/pdf_page.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 0733da2f..a6a0950b 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -154,7 +154,7 @@ pdf_load_page_tree(pdf_document *xref) pdf_obj *count; struct info info; - if (xref->page_len) + if (xref->page_refs) return; catalog = pdf_dict_gets(xref->trailer, "Root"); -- cgit v1.2.3 From d13391b011532794563f0e2c3911ee72eece7c39 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 7 Aug 2012 17:27:38 +0100 Subject: Fix various problems with linearisation when saving. Unused objects could cause problems with the sort order and picking the object to start with. Now coped with. If the hintstream object replaces another object that already had a stream, pdf_open_raw_filter would get confused by the presence of a stm_buf. Now fixed. Fix a 64bit problem in page_objects_list_ensure, as well as tweaking the code for readability. When outputting single page files, we can end up with opts->start = 1 and this upset the offset calculating logic. Insist on compacting the xref when linearising. Thanks to Sebras and Zeniko for providing test cases. This commit should (hopefully) stop the SEGVs, but there are still cases where Acrobat doesn't think that the files output are "Optimised for Fast Web View". I cannot see why. --- pdf/pdf_stream.c | 10 +++--- pdf/pdf_write.c | 101 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 00552ff4..a81ecb18 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -225,10 +225,10 @@ build_filter_chain(fz_stream *chain, pdf_document *xref, pdf_obj *fs, pdf_obj *p * allow for other people accessing the file), followed by a decryption * filter. * - * num and gen are used purely to seed the encryption. + * orig_num and orig_gen are used purely to seed the encryption. */ static fz_stream * -pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int gen, int offset) +pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int orig_num, int orig_gen, int offset) { fz_context *ctx = chain->ctx; int hascrypt; @@ -247,7 +247,7 @@ pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int n { hascrypt = pdf_stream_has_crypt(ctx, stmobj); if (xref->crypt && !hascrypt) - chain = pdf_open_crypt(chain, xref->crypt, num, gen); + chain = pdf_open_crypt(chain, xref->crypt, orig_num, orig_gen); } fz_catch(ctx) { @@ -271,7 +271,7 @@ pdf_open_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, filters = pdf_dict_getsa(stmobj, "Filter", "F"); params = pdf_dict_getsa(stmobj, "DecodeParms", "DP"); - chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen, offset); + chain = pdf_open_raw_filter(chain, xref, stmobj, num, num, gen, offset); if (pdf_is_name(filters)) chain = build_filter(chain, xref, filters, params, num, gen, imparams); @@ -329,7 +329,7 @@ pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_nu if (x->stm_ofs == 0) fz_throw(xref->ctx, "object is not a stream"); - return pdf_open_raw_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs); + return pdf_open_raw_filter(xref->file, xref, x->obj, num, orig_num, orig_gen, x->stm_ofs); } /* diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c index 3dce3838..6a07894a 100644 --- a/pdf/pdf_write.c +++ b/pdf/pdf_write.c @@ -3,6 +3,8 @@ /* #define DEBUG_LINEARIZATION */ /* #define DEBUG_HEAP_SORT */ +/* #define DEBUG_WRITING */ + typedef struct pdf_write_options_s pdf_write_options; @@ -128,10 +130,11 @@ page_objects_list_destroy(fz_context *ctx, page_objects_list *pol) static void page_objects_list_ensure(fz_context *ctx, page_objects_list **pol, int newcap) { - if (newcap <= (*pol)->cap) + int oldcap = (*pol)->cap; + if (newcap <= oldcap) return; - *pol = fz_resize_array(ctx, *pol, 1, sizeof(**pol) + (newcap-1)*sizeof(int)); - memset(&(*pol)->page[(*pol)->cap], 0, sizeof(page_objects *)*(newcap-(*pol)->cap)); + *pol = fz_resize_array(ctx, *pol, 1, sizeof(page_objects_list) + (newcap-1)*sizeof(page_objects *)); + memset(&(*pol)->page[oldcap], 0, (newcap-oldcap)*sizeof(page_objects *)); (*pol)->cap = newcap; } @@ -254,6 +257,7 @@ order_ge(int ui, int uj) * Catalogue (and other document level objects) * First page * (Primary Hint stream) (*) + * Any free objects * Note, this is NOT the same order they appear in * the final file! * @@ -264,7 +268,12 @@ order_ge(int ui, int uj) * first. */ if (((ui ^ uj) & ~USE_PAGE_OBJECT) == 0) return ((ui & USE_PAGE_OBJECT) == 0); - /* Put the hint stream last. */ + /* Put unused objects last */ + else if (ui == 0) + return 1; + else if (uj == 0) + return 0; + /* Put the hint stream before that... */ else if (ui & USE_HINTS) return 1; else if (uj & USE_HINTS) @@ -301,7 +310,7 @@ order_ge(int ui, int uj) } static void -heap_sort(int *list, int n, int *val, int (*ge)(int, int)) +heap_sort(int *list, int n, const int *val, int (*ge)(int, int)) { int i, j; @@ -731,7 +740,7 @@ static void renumberobjs(pdf_document *xref, pdf_write_options *opts) if (newlen < opts->renumber_map[num]) newlen = opts->renumber_map[num]; xref->table[opts->renumber_map[num]] = oldxref[num]; - new_use_list[opts->renumber_map[num]] = 1; + new_use_list[opts->renumber_map[num]] = opts->use_list[num]; } else { @@ -1265,6 +1274,14 @@ linearize(pdf_document *xref, pdf_write_options *opts) /* Add new objects required for linearization */ add_linearization_objs(xref, opts); +#ifdef DEBUG_WRITING + fprintf(stderr, "Usage calculated:\n"); + for (i=0; i < xref->len; i++) + { + fprintf(stderr, "%d: use=%d\n", i, opts->use_list[i]); + } +#endif + /* Allocate/init the structures used for renumbering the objects */ reorder = fz_calloc(ctx, n, sizeof(int)); rev_renumber_map = fz_calloc(ctx, n, sizeof(int)); @@ -1277,6 +1294,14 @@ linearize(pdf_document *xref, pdf_write_options *opts) /* Heap sort the reordering */ heap_sort(reorder+1, n-1, opts->use_list, &order_ge); +#ifdef DEBUG_WRITING + fprintf(stderr, "Reordered:\n"); + for (i=1; i < xref->len; i++) + { + fprintf(stderr, "%d: use=%d\n", i, opts->use_list[reorder[i]]); + } +#endif + /* Find the split point */ for (i = 1; (opts->use_list[reorder[i]] & USE_PARAMS) == 0; i++); opts->start = i; @@ -1304,18 +1329,21 @@ linearize(pdf_document *xref, pdf_write_options *opts) static void update_linearization_params(pdf_document *xref, pdf_write_options *opts) { + int offset; pdf_set_int(opts->linear_l, opts->file_len); /* Primary hint stream offset (of object, not stream!) */ pdf_set_int(opts->linear_h0, opts->ofs_list[xref->len-1]); /* Primary hint stream length (of object, not stream!) */ - pdf_set_int(opts->linear_h1, opts->ofs_list[1] - opts->ofs_list[xref->len-1] + opts->hintstream_len); + offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len); + pdf_set_int(opts->linear_h1, offset - opts->ofs_list[xref->len-1]); /* Object number of first pages page object (the first object of page 0) */ pdf_set_int(opts->linear_o, opts->page_object_lists->page[0]->object[0]); /* Offset of end of first page (first page is followed by primary * hint stream (object n-1) then remaining pages (object 1...). The * primary hint stream counts as part of the first pages data, I think. */ - pdf_set_int(opts->linear_e, opts->ofs_list[1] + opts->hintstream_len); + offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len); + pdf_set_int(opts->linear_e, offset); /* Number of pages in document */ pdf_set_int(opts->linear_n, opts->page_count); /* Offset of first entry in main xref table */ @@ -1691,6 +1719,7 @@ padto(FILE *file, int target) { int pos = ftell(file); + assert(pos <= target); while (pos < target) { fputc('\n', file); @@ -1736,27 +1765,25 @@ writeobjects(pdf_document *xref, pdf_write_options *opts, int pass) { /* Write first xref */ if (pass == 0) - { opts->first_xref_offset = ftell(opts->out); - } else - { - int pos = ftell(opts->out); - while (pos < opts->first_xref_offset) - { - fputc('\n', opts->out); - pos++; - } - } + padto(opts->out, opts->first_xref_offset); writexref(xref, opts, opts->start, xref->len, 1, opts->main_xref_offset, 0); } for (num = opts->start+1; num < xref->len; num++) dowriteobject(xref, opts, num, pass); if (opts->do_linear && pass == 1) - padto(opts->out, opts->ofs_list[1] + opts->hintstream_len); + { + int offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len); + padto(opts->out, offset); + } for (num = 1; num < opts->start; num++) + { + if (pass == 1) + opts->ofs_list[num] += opts->hintstream_len; dowriteobject(xref, opts, num, pass); + } } static int @@ -1795,17 +1822,17 @@ make_page_offset_hints(pdf_document *xref, pdf_write_options *opts, fz_buffer *b max_shared_object = 1; min_shared_length = opts->file_len; max_shared_length = 0; - for (i=0; i < xref->len; i++) + for (i=1; i < xref->len; i++) { int min, max, page; min = opts->ofs_list[i]; - if (i == opts->start-1) + if (i == opts->start-1 || (opts->start == 1 && i == xref->len-1)) max = opts->main_xref_offset; - else if (i < xref->len-1) - max = opts->ofs_list[i+1]; - else + else if (i == xref->len-1) max = opts->ofs_list[1]; + else + max = opts->ofs_list[i+1]; assert(max > min); @@ -2067,6 +2094,18 @@ make_hint_stream(pdf_document *xref, pdf_write_options *opts) } } +#ifdef DEBUG_WRITING +static void dump_object_details(pdf_document *xref, pdf_write_options *opts) +{ + int i; + + for (i = 0; i < xref->len; i++) + { + fprintf(stderr, "%d@%d: use=%d\n", i, opts->ofs_list[i], opts->use_list[i]); + } +} +#endif + void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz_opts) { @@ -2126,11 +2165,11 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz removeduplicateobjs(xref, &opts); /* Compact xref by renumbering and removing unused objects */ - if (opts.do_garbage >= 2) + if (opts.do_garbage >= 2 || opts.do_linear) compactxref(xref, &opts); /* Make renumbering affect all indirect references and update xref */ - if (opts.do_garbage >= 2) + if (opts.do_garbage >= 2 || opts.do_linear) renumberobjs(xref, &opts); if (opts.do_linear) @@ -2140,6 +2179,10 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz writeobjects(xref, &opts, 0); +#ifdef DEBUG_WRITING + dump_object_details(xref, &opts); +#endif + /* Construct linked list of free object slots */ lastfree = 0; for (num = 0; num < xref->len; num++) @@ -2155,7 +2198,7 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz if (opts.do_linear) { opts.main_xref_offset = ftell(opts.out); - writexref(xref, &opts, 0, xref->len, !opts.do_linear, 0, opts.first_xref_offset); + writexref(xref, &opts, 0, opts.start, 0, 0, opts.first_xref_offset); opts.file_len = ftell(opts.out); make_hint_stream(xref, &opts); @@ -2166,14 +2209,14 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz writeobjects(xref, &opts, 1); padto(opts.out, opts.main_xref_offset); - + writexref(xref, &opts, 0, opts.start, 0, 0, opts.first_xref_offset); } else { opts.first_xref_offset = ftell(opts.out); + writexref(xref, &opts, 0, xref->len, 1, 0, opts.first_xref_offset); } - writexref(xref, &opts, 0, xref->len, !opts.do_linear, 0, opts.first_xref_offset); } fz_always(ctx) { -- cgit v1.2.3 From 7c871225996e814fe5ce513097a8eefca0b9294c Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 7 Aug 2012 18:08:41 +0100 Subject: Remove fz_too_deeply_nested. Rather than specifically checking for the nesting getting too deep and hence throwing an error, the error handling should do this for itself. Make it so that we spot the depth being too great in the fz_try() and throw to the fz_catch(). --- fitz/base_error.c | 24 ++++++++++++------------ fitz/fitz.h | 7 +++---- pdf/pdf_parse.c | 12 ------------ 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/fitz/base_error.c b/fitz/base_error.c index 606e9c2a..ce048a1e 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -43,12 +43,6 @@ void fz_warn(fz_context *ctx, char *fmt, ...) /* Error context */ -int fz_too_deeply_nested(fz_context *ctx) -{ - fz_error_context *ex = ctx->error; - return ex->top + 1 >= nelem(ex->stack); -} - static void throw(fz_error_context *ex) { if (ex->top >= 0) { @@ -60,15 +54,21 @@ static void throw(fz_error_context *ex) } } -void fz_push_try(fz_error_context *ex) +int fz_push_try(fz_error_context *ex) { assert(ex); - if (ex->top + 1 >= nelem(ex->stack)) - { - fprintf(stderr, "exception stack overflow!\n"); - exit(EXIT_FAILURE); - } ex->top++; + /* Normal case, get out of here quick */ + if (ex->top < nelem(ex->stack)-1) + return 1; + /* We reserve the top slot on the exception stack purely to cope with + * the case when we overflow. If we DO hit this, then we 'throw' + * immediately - returning 0 stops the setjmp happening and takes us + * direct to the always/catch clauses. */ + assert(ex->top == nelem(ex->stack)-1); + strcpy(ex->message, "exception stack overflow!\n"); + ex->stack[ex->top].code = 1; + return 0; } char *fz_caught(fz_context *ctx) diff --git a/fitz/fitz.h b/fitz/fitz.h index 63278cb1..dd9424a9 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -237,8 +237,8 @@ void fz_var_imp(void *); */ #define fz_try(ctx) \ - if (fz_push_try(ctx->error), \ - (ctx->error->stack[ctx->error->top].code = fz_setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ + if (fz_push_try(ctx->error) && \ + ((ctx->error->stack[ctx->error->top].code = fz_setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0))\ { do { #define fz_always(ctx) \ @@ -251,11 +251,10 @@ void fz_var_imp(void *); } \ if (ctx->error->stack[ctx->error->top--].code) -void fz_push_try(fz_error_context *ex); +int fz_push_try(fz_error_context *ex); void fz_throw(fz_context *, char *, ...) __printflike(2, 3); void fz_rethrow(fz_context *); void fz_warn(fz_context *ctx, char *fmt, ...) __printflike(2, 3); -int fz_too_deeply_nested(fz_context *ctx); /* fz_flush_warnings: Flush any repeated warnings. diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index 6f27099f..dd710891 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -244,9 +244,6 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; case PDF_TOK_OPEN_ARRAY: - if (fz_too_deeply_nested(ctx)) - fz_throw(ctx, "nested too deep, not parsing array"); - obj = pdf_parse_array(xref, file, buf); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -254,9 +251,6 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; case PDF_TOK_OPEN_DICT: - if (fz_too_deeply_nested(ctx)) - fz_throw(ctx, "nested too deep, not parsing dict"); - obj = pdf_parse_dict(xref, file, buf); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -354,16 +348,10 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) switch (tok) { case PDF_TOK_OPEN_ARRAY: - if (fz_too_deeply_nested(ctx)) - fz_throw(ctx, "nested too deep, not parsing array"); - val = pdf_parse_array(xref, file, buf); break; case PDF_TOK_OPEN_DICT: - if (fz_too_deeply_nested(ctx)) - fz_throw(ctx, "nested too deep, not parsing array"); - val = pdf_parse_dict(xref, file, buf); break; -- cgit v1.2.3 From 511ea75a53db6e72334438bcda2ce774c7d72d1e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 6 Aug 2012 17:46:02 +0100 Subject: Update VS solutions to new thirdparty files. --- win32/libmupdf.vcproj | 6 +- win32/libthirdparty.vcproj | 176 ++++++++++++++++++++++----------------------- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/win32/libmupdf.vcproj b/win32/libmupdf.vcproj index 8706176c..b9403073 100644 --- a/win32/libmupdf.vcproj +++ b/win32/libmupdf.vcproj @@ -41,7 +41,7 @@ @@ -398,43 +398,43 @@ Name="libz" > @@ -442,95 +442,95 @@ Name="libopenjpeg" > @@ -538,90 +538,90 @@ Name="libfreetype" > -- cgit v1.2.3