diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-11-18 13:02:01 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-11-21 11:11:46 +0100 |
commit | bff572a7365209f36a16951296384974c80ad3d5 (patch) | |
tree | 7d63479831c8edc24bc5933a1ef61c376a8dd6b2 | |
parent | ac6ebbe38e6edb6074b1b73707770a9a4e9979b8 (diff) | |
download | mupdf-bff572a7365209f36a16951296384974c80ad3d5.tar.xz |
Harden viewers against failures when loading outlines.
Ignore invalid page references in outlines.
This was shown by a file that had [null 0 0 1] as a link dest.
Attempting to parse that threw an error, which caused the whole
outline load to fail.
-rw-r--r-- | platform/android/viewer/jni/mupdf.c | 11 | ||||
-rw-r--r-- | platform/gl/gl-main.c | 6 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 12 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 11 | ||||
-rw-r--r-- | source/pdf/pdf-annot.c | 7 | ||||
-rw-r--r-- | source/pdf/pdf-outline.c | 5 |
6 files changed, 36 insertions, 16 deletions
diff --git a/platform/android/viewer/jni/mupdf.c b/platform/android/viewer/jni/mupdf.c index 581da497..55bcfb7a 100644 --- a/platform/android/viewer/jni/mupdf.c +++ b/platform/android/viewer/jni/mupdf.c @@ -1212,7 +1212,11 @@ JNI_FN(MuPDFCore_hasOutlineInternal)(JNIEnv * env, jobject thiz) { globals *glo = get_globals(env, thiz); fz_context *ctx = glo->ctx; - fz_outline *outline = fz_load_outline(ctx, glo->doc); + fz_outline *outline; + fz_try(ctx) + outline = fz_load_outline(ctx, glo->doc); + fz_catch(ctx) + outline = NULL; fz_drop_outline(glo->ctx, outline); return (outline == NULL) ? JNI_FALSE : JNI_TRUE; @@ -1236,7 +1240,10 @@ JNI_FN(MuPDFCore_getOutlineInternal)(JNIEnv * env, jobject thiz) ctor = (*env)->GetMethodID(env, olClass, "<init>", "(ILjava/lang/String;I)V"); if (ctor == NULL) return NULL; - outline = fz_load_outline(ctx, glo->doc); + fz_try(ctx) + outline = fz_load_outline(ctx, glo->doc); + fz_catch(ctx) + outline = NULL; nItems = countOutlineItems(outline); arr = (*env)->NewObjectArray(env, diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c index 46c65262..8300bc0a 100644 --- a/platform/gl/gl-main.c +++ b/platform/gl/gl-main.c @@ -755,7 +755,11 @@ static void reload(void) fz_layout_document(ctx, doc, layout_w, layout_h, layout_em); - outline = fz_load_outline(ctx, doc); + fz_try(ctx) + outline = fz_load_outline(ctx, doc); + fz_catch(ctx) + outline = NULL; + pdf = pdf_specifics(ctx, doc); if (pdf) pdf_enable_js(ctx, pdf); diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index 532ee411..ba18dee2 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -272,7 +272,11 @@ static void saveDoc(const char *current_path, fz_document *doc) // Set up the buttons on the navigation and search bar - fz_outline *outlineRoot = fz_load_outline(ctx, doc); + fz_outline *outlineRoot; + fz_try(ctx) + outlineRoot = fz_load_outline(ctx, doc); + fz_catch(ctx) + outlineRoot = NULL; if (outlineRoot) { // only show the outline button if there is an outline @@ -471,7 +475,11 @@ static void saveDoc(const char *current_path, fz_document *doc) - (void) onShowOutline: (id)sender { // rebuild the outline in case the layout has changed - fz_outline *root = fz_load_outline(ctx, doc); + fz_outline *root; + fz_try(ctx) + root = fz_load_outline(ctx, doc); + fz_catch(ctx) + root = NULL; if (root) { NSMutableArray *titles = [[NSMutableArray alloc] init]; diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index 0b0abafc..ef834aa1 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -407,12 +407,9 @@ void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps) } fz_catch(ctx) { + app->outline = NULL; if (fz_caught(ctx) == FZ_ERROR_TRYLATER) - { app->outline_deferred = PDFAPP_OUTLINE_DEFERRED; - } - else - fz_rethrow(ctx); } break; } @@ -818,13 +815,9 @@ void pdfapp_reloadpage(pdfapp_t *app) if (app->outline_deferred == PDFAPP_OUTLINE_LOAD_NOW) { fz_try(app->ctx) - { app->outline = fz_load_outline(app->ctx, app->doc); - } fz_catch(app->ctx) - { - /* Ignore any error now */ - } + app->outline = NULL; app->outline_deferred = 0; } pdfapp_showpage(app, 1, 1, 1, 0, 0); diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index 2d6aab16..6f622da4 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -67,7 +67,12 @@ pdf_parse_link_dest(fz_context *ctx, pdf_document *doc, pdf_obj *dest) if (pdf_is_int(ctx, obj)) page = pdf_to_int(ctx, obj); else - page = pdf_lookup_page_number(ctx, doc, obj); + { + fz_try(ctx) + page = pdf_lookup_page_number(ctx, doc, obj); + fz_catch(ctx) + page = -1; + } x = y = 0; obj = pdf_array_get(ctx, dest, 1); diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c index 7db65153..c31a1954 100644 --- a/source/pdf/pdf-outline.c +++ b/source/pdf/pdf-outline.c @@ -33,7 +33,10 @@ pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict) else node->uri = NULL; - node->page = pdf_resolve_link(ctx, doc, node->uri, NULL, NULL); + if (node->uri) + node->page = pdf_resolve_link(ctx, doc, node->uri, NULL, NULL); + else + node->page = -1; obj = pdf_dict_get(ctx, dict, PDF_NAME_First); if (obj) |