diff options
Diffstat (limited to 'source/pdf/pdf-page.c')
-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; } |