diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 01b333b..560bead 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -779,6 +779,14 @@ QPDFJob::doCheck(QPDF& pdf) cout << "File is not linearized\n"; } + // Create all document helper to trigger any validations they carry out. + auto& pages = pdf.pages(); + (void)pdf.acroform(); + (void)pdf.embedded_files(); + (void)pdf.page_labels(); + (void)pdf.outlines().resolveNamedDest(QPDFObjectHandle::newString("dummy")); + (void)pdf.outlines().getOutlinesForPage(pages.getAllPages().at(0)); + // Write the file to nowhere, uncompressing streams. This causes full file traversal and // decoding of all streams we can decode. QPDFWriter w(pdf); @@ -789,7 +797,7 @@ QPDFJob::doCheck(QPDF& pdf) // Parse all content streams int pageno = 0; - for (auto& page: pdf.pages().getAllPages()) { + for (auto& page: pages.getAllPages()) { ++pageno; try { page.parseContents(nullptr); diff --git a/manual/release-notes.rst b/manual/release-notes.rst index 7a03a90..f8860b0 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -47,6 +47,9 @@ more detail. with the incompatible options :qpdf:ref:`--encrypt` or :qpdf:ref:`--copy-encryption`. + - Option :qpdf:ref:`--check` now includes additional basic checks of the + AcroForm, Dests, Outlines, and PageLabels structures. + - Other enhancements - ``QPDFWriter`` will no longer add filters when writing empty streams. diff --git a/qpdf/qtest/outlines.test b/qpdf/qtest/outlines.test index 9444b4e..9c6b453 100644 --- a/qpdf/qtest/outlines.test +++ b/qpdf/qtest/outlines.test @@ -21,7 +21,7 @@ my @outline_files = ( 'outlines-with-old-root-dests-dict', 'outlines-with-loop', ); -my $n_tests = scalar(@outline_files); +my $n_tests = scalar(@outline_files) + 1; foreach my $f (@outline_files) { $td->runtest("outlines: $f", @@ -30,5 +30,10 @@ foreach my $f (@outline_files) $td->NORMALIZE_NEWLINES); } +$td->runtest("outlines: outlines-with-loop --check", + {$td->COMMAND => "qpdf --check outlines-with-loop.pdf"}, + {$td->FILE => "outlines-with-loop-check.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + cleanup(); $td->report($n_tests); diff --git a/qpdf/qtest/page-labels.test b/qpdf/qtest/page-labels.test index 37f2a61..9f098a3 100644 --- a/qpdf/qtest/page-labels.test +++ b/qpdf/qtest/page-labels.test @@ -14,7 +14,7 @@ cleanup(); my $td = new TestDriver('page-labels'); -my $n_tests = 4; +my $n_tests = 5; $td->runtest("complex page labels", {$td->COMMAND => "test_driver 47 page-labels-num-tree.pdf"}, @@ -38,6 +38,11 @@ $td->runtest("damaged page labels", {$td->FILE => "page-labels-num-tree-damaged.out", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); +$td->runtest("damaged page labels --check", + {$td->COMMAND => "qpdf --check page-labels-num-tree-damaged.pdf"}, + {$td->FILE => "page-labels-num-tree-damaged-check.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + # --set-page-labels my @errors = ( ["quack", ".*page label spec must be.*"], diff --git a/qpdf/qtest/qpdf/outlines-with-loop-check.out b/qpdf/qtest/qpdf/outlines-with-loop-check.out new file mode 100644 index 0000000..a38d385 --- /dev/null +++ b/qpdf/qtest/qpdf/outlines-with-loop-check.out @@ -0,0 +1,6 @@ +checking outlines-with-loop.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized +No syntax or stream encoding errors found; the file may still contain +errors that qpdf cannot detect diff --git a/qpdf/qtest/qpdf/page-labels-num-tree-damaged-check.out b/qpdf/qtest/qpdf/page-labels-num-tree-damaged-check.out new file mode 100644 index 0000000..b7b8295 --- /dev/null +++ b/qpdf/qtest/qpdf/page-labels-num-tree-damaged-check.out @@ -0,0 +1,7 @@ +checking page-labels-num-tree-damaged.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized +WARNING: page-labels-num-tree-damaged.pdf (Name/Number tree node (object 2)): attempting to repair after error: page-labels-num-tree-damaged.pdf (Name/Number tree node (object 2)): keys are not sorted in validate +WARNING: page-labels-num-tree-damaged.pdf (Name/Number tree node (object 37)): item 1 is invalid +qpdf: operation succeeded with warnings