From a7ecc156141b15cfae8b309697e12deae2740841 Mon Sep 17 00:00:00 2001 From: yzrh Date: Wed, 4 Jan 2023 17:50:25 +0000 Subject: Replace catalog object only if root object does not exist. Signed-off-by: yzrh --- src/cnki_pdf.c | 16 ++++++++++------ src/pdf_parser.c | 6 ++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c index 87fe3f6..0c1ebb0 100644 --- a/src/cnki_pdf.c +++ b/src/cnki_pdf.c @@ -375,9 +375,11 @@ cnki_pdf(cnki_t **param) printf("Root object is %d.\n", root); } + int root_gen; + pdf_object_t *tmp; - if (pdf_get_obj(&pdf, root, &tmp) != 0) { + if ((root_gen = pdf_get_obj(&pdf, root, &tmp)) != 0) { if ((*param)->stat > 0) printf("Root object is missing\n"); @@ -442,13 +444,15 @@ cnki_pdf(cnki_t **param) if ((*param)->stat > 0) printf("Catalog object is %d.\n", catalog); - if ((*param)->stat > 1) - printf("Replacing catalog object\n"); + if (root_gen != 0) { + if ((*param)->stat > 1) + printf("Replacing catalog object\n"); - pdf_obj_replace(&pdf, catalog, NULL, dictionary, NULL, 0); + pdf_obj_replace(&pdf, catalog, NULL, dictionary, NULL, 0); - if ((*param)->stat > 0) - printf("Replaced catalog object\n"); + if ((*param)->stat > 0) + printf("Replaced catalog object\n"); + } } else { if ((*param)->stat > 0) printf("Catalog object is missing\n"); diff --git a/src/pdf_parser.c b/src/pdf_parser.c index 70d72d5..6520fd5 100644 --- a/src/pdf_parser.c +++ b/src/pdf_parser.c @@ -232,7 +232,8 @@ pdf_load(pdf_object_t **pdf, FILE **fp, int size_buf) * A dictionary object may have nested dictionary, * but it should not be in a stream */ - while ((tmp = _memmem_whitespace(tail + 3, + while (ptr->size - (tail - buf) > 3 && + (tmp = _memmem_whitespace(tail + 3, ptr->size - (tail - buf) - 3, ">>", 2)) != NULL && memmem(tail + 3, @@ -241,7 +242,8 @@ pdf_load(pdf_object_t **pdf, FILE **fp, int size_buf) tail = tmp; /* Hack needed for invalid object */ - while ((tmp = memmem(tail + 2, + while (ptr->size - (tail - buf) > 2 && + (tmp = memmem(tail + 2, ptr->size - (tail - buf) - 2, ">>", 2)) != NULL && memmem(tail + 2, -- cgit v1.2.3