diff options
author | Simon Bünzli <zeniko@gmail.com> | 2014-10-28 15:04:01 +0100 |
---|---|---|
committer | Simon Bünzli <zeniko@gmail.com> | 2014-10-28 15:46:31 +0100 |
commit | 37779f92eda4a7adf4b0f0212f89680beca77c5c (patch) | |
tree | eb84c516f63aab14115a8d07e62f78f6d3f501df /source | |
parent | b1542d7c2f33a4412606c013a5ba6ce0ad31c034 (diff) | |
download | mupdf-37779f92eda4a7adf4b0f0212f89680beca77c5c.tar.xz |
more liberally accept page trees with unexpected content
pdf_lookup_page_loc_imp currently throws if any object in the page tree
is neither a /Pages node nor a /Page leaf. This unnecessarily rejects
slightly broken documents such as the ones from
https://code.google.com/p/sumatrapdf/issues/detail?id=2582 and
https://code.google.com/p/sumatrapdf/issues/detail?id=2608 .
pdf_count_pages_before_kid currently wrongly throws if a /Pages node
doesn't contain any kids and correctly states so (which even seems to
be permitted by the PDF specification).
Diffstat (limited to 'source')
-rw-r--r-- | source/pdf/pdf-page.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index a6a5699a..6543b7dc 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -64,37 +64,35 @@ pdf_lookup_page_loc_imp(pdf_document *doc, pdf_obj *node, int *skip, pdf_obj **p { pdf_obj *kid = pdf_array_get(kids, i); char *type = pdf_to_name(pdf_dict_gets(kid, "Type")); - if (!strcmp(type, "Page") || (!*type && pdf_dict_gets(kid, "MediaBox"))) + if (*type ? !strcmp(type, "Pages") : pdf_dict_gets(kid, "Kids") && !pdf_dict_gets(kid, "MediaBox")) { - if (*skip == 0) + int count = pdf_to_int(pdf_dict_gets(kid, "Count")); + if (*skip < count) { - if (parentp) *parentp = node; - if (indexp) *indexp = i; - hit = kid; + node = kid; break; } else { - (*skip)--; + *skip -= count; } } - else if (!strcmp(type, "Pages") || (!*type && pdf_dict_gets(kid, "Kids"))) + else { - int count = pdf_to_int(pdf_dict_gets(kid, "Count")); - if (*skip < count) + if (*type ? strcmp(type, "Page") != 0 : !pdf_dict_gets(kid, "MediaBox")) + fz_warn(ctx, "non-page object in page tree (%s)", type); + if (*skip == 0) { - node = kid; + if (parentp) *parentp = node; + if (indexp) *indexp = i; + hit = kid; break; } else { - *skip -= count; + (*skip)--; } } - else - { - fz_throw(ctx, FZ_ERROR_GENERIC, "non-page object in page tree (%s)", type); - } } } while (hit == NULL); @@ -151,7 +149,7 @@ pdf_count_pages_before_kid(pdf_document *doc, pdf_obj *parent, int kid_num) { pdf_obj *count = pdf_dict_gets(kid, "Count"); int n = pdf_to_int(count); - if (count == NULL || n <= 0) + if (!pdf_is_int(count) || n < 0) fz_throw(doc->ctx, FZ_ERROR_GENERIC, "illegal or missing count in pages tree"); total += n; } |