From 8a32515a62960af10abfb863157a4c67ea3b506f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 25 Jun 2022 11:29:32 -0400 Subject: Add warnings for some additional page tree repair --- libqpdf/QPDF_pages.cc | 7 +++++++ qpdf/qtest/pages-tree.test | 20 +++++++++++++------- qpdf/qtest/qpdf/direct-page-warning.out | 3 +++ qpdf/qtest/qpdf/direct-pages-json-warning.out | 3 +++ qpdf/qtest/qpdf/direct-pages.out | 3 +++ qpdf/qtest/qpdf/duplicate-page-warning.out | 2 ++ qpdf/qtest/qpdf/page_api_2-json-warning.out | 2 ++ qpdf/qtest/qpdf/page_api_2.out | 1 + 8 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 qpdf/qtest/qpdf/direct-page-warning.out create mode 100644 qpdf/qtest/qpdf/direct-pages-json-warning.out create mode 100644 qpdf/qtest/qpdf/duplicate-page-warning.out create mode 100644 qpdf/qtest/qpdf/page_api_2-json-warning.out diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc index e8416b2b..d43267d2 100644 --- a/libqpdf/QPDF_pages.cc +++ b/libqpdf/QPDF_pages.cc @@ -110,12 +110,19 @@ QPDF::getAllPagesInternal( QPDFObjectHandle kid = kids.getArrayItem(i); if (!kid.isIndirect()) { QTC::TC("qpdf", "QPDF handle direct page object"); + cur_node.warnIfPossible( + "kid " + QUtil::int_to_string(i) + + " (from 0) is direct; converting to indirect"); kid = makeIndirectObject(kid); kids.setArrayItem(i, kid); } else if (seen.count(kid.getObjGen())) { // Make a copy of the page. This does the same as // shallowCopyPage in QPDFPageObjectHelper. QTC::TC("qpdf", "QPDF resolve duplicated page object"); + cur_node.warnIfPossible( + "kid " + QUtil::int_to_string(i) + + " (from 0) appears more than once in the pages tree;" + " creating a new page object as a copy"); kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy()); kids.setArrayItem(i, kid); } diff --git a/qpdf/qtest/pages-tree.test b/qpdf/qtest/pages-tree.test index 4ad260ef..e40d6de1 100644 --- a/qpdf/qtest/pages-tree.test +++ b/qpdf/qtest/pages-tree.test @@ -14,13 +14,14 @@ cleanup(); my $td = new TestDriver('pages-tree'); -my $n_tests = 11; +my $n_tests = 13; $td->runtest("linearize duplicated pages", {$td->COMMAND => "qpdf --static-id --linearize" . " page_api_2.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, + {$td->FILE => "duplicate-page-warning.out", + $td->EXIT_STATUS => 3}, $td->NORMALIZE_NEWLINES); $td->runtest("compare files", {$td->FILE => "a.pdf"}, @@ -29,7 +30,8 @@ $td->runtest("extract duplicated pages", {$td->COMMAND => "qpdf --static-id page_api_2.pdf" . " --pages . -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, + {$td->FILE => "duplicate-page-warning.out", + $td->EXIT_STATUS => 3}, $td->NORMALIZE_NEWLINES); $td->runtest("compare files", {$td->FILE => "a.pdf"}, @@ -37,7 +39,7 @@ $td->runtest("compare files", $td->runtest("direct pages", {$td->COMMAND => "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, + {$td->FILE => "direct-page-warning.out", $td->EXIT_STATUS => 3}, $td->NORMALIZE_NEWLINES); $td->runtest("check output", {$td->FILE => "a.pdf"}, @@ -45,7 +47,7 @@ $td->runtest("check output", $td->runtest("show direct pages", {$td->COMMAND => "qpdf --show-pages direct-pages.pdf"}, - {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0}, + {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 3}, $td->NORMALIZE_NEWLINES); # Json mode for direct and duplicated pages illustrates that the @@ -62,8 +64,12 @@ foreach my $f (qw(page_api_2 direct-pages)) $td->runtest("json for $f (with pages)", {$td->COMMAND => "qpdf --json=latest $f.pdf" . - " --json-key=objects --json-key=pages"}, - {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 0}, + " --json-key=objects --json-key=pages 2>warn.tmpout"}, + {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check page warnings", + {$td->FILE => "warn.tmpout"}, + {$td->FILE => "$f-json-warning.out"}, $td->NORMALIZE_NEWLINES); } diff --git a/qpdf/qtest/qpdf/direct-page-warning.out b/qpdf/qtest/qpdf/direct-page-warning.out new file mode 100644 index 00000000..253dbb8c --- /dev/null +++ b/qpdf/qtest/qpdf/direct-page-warning.out @@ -0,0 +1,3 @@ +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 0 (from 0) is direct; converting to indirect +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 1 (from 0) is direct; converting to indirect +qpdf: operation succeeded with warnings; resulting file may have some problems diff --git a/qpdf/qtest/qpdf/direct-pages-json-warning.out b/qpdf/qtest/qpdf/direct-pages-json-warning.out new file mode 100644 index 00000000..2427e4bb --- /dev/null +++ b/qpdf/qtest/qpdf/direct-pages-json-warning.out @@ -0,0 +1,3 @@ +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 0 (from 0) is direct; converting to indirect +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 1 (from 0) is direct; converting to indirect +qpdf: operation succeeded with warnings diff --git a/qpdf/qtest/qpdf/direct-pages.out b/qpdf/qtest/qpdf/direct-pages.out index 4b4c3c47..5dd9d1af 100644 --- a/qpdf/qtest/qpdf/direct-pages.out +++ b/qpdf/qtest/qpdf/direct-pages.out @@ -1,6 +1,9 @@ +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 0 (from 0) is direct; converting to indirect +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 1 (from 0) is direct; converting to indirect page 1: 7 0 R content: 3 0 R page 2: 8 0 R content: 3 0 R +qpdf: operation succeeded with warnings diff --git a/qpdf/qtest/qpdf/duplicate-page-warning.out b/qpdf/qtest/qpdf/duplicate-page-warning.out new file mode 100644 index 00000000..6e751811 --- /dev/null +++ b/qpdf/qtest/qpdf/duplicate-page-warning.out @@ -0,0 +1,2 @@ +WARNING: page_api_2.pdf, object 3 0 at offset 175: kid 1 (from 0) appears more than once in the pages tree; creating a new page object as a copy +qpdf: operation succeeded with warnings; resulting file may have some problems diff --git a/qpdf/qtest/qpdf/page_api_2-json-warning.out b/qpdf/qtest/qpdf/page_api_2-json-warning.out new file mode 100644 index 00000000..274d6bfe --- /dev/null +++ b/qpdf/qtest/qpdf/page_api_2-json-warning.out @@ -0,0 +1,2 @@ +WARNING: page_api_2.pdf, object 3 0 at offset 175: kid 1 (from 0) appears more than once in the pages tree; creating a new page object as a copy +qpdf: operation succeeded with warnings diff --git a/qpdf/qtest/qpdf/page_api_2.out b/qpdf/qtest/qpdf/page_api_2.out index 30e9b9c3..f874486d 100644 --- a/qpdf/qtest/qpdf/page_api_2.out +++ b/qpdf/qtest/qpdf/page_api_2.out @@ -1 +1,2 @@ +WARNING: page_api_2.pdf, object 3 0 at offset 175: kid 1 (from 0) appears more than once in the pages tree; creating a new page object as a copy test 17 done -- cgit v1.2.3-70-g09d2