Commit 206c2fc1da0c9608bfec4e91e4b91410bba7f830
1 parent
36e1c142
Add additional validation of document-level structures to `--check` option.
Showing
6 changed files
with
37 additions
and
3 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -779,6 +779,14 @@ QPDFJob::doCheck(QPDF& pdf) |
| 779 | 779 | cout << "File is not linearized\n"; |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | + // Create all document helper to trigger any validations they carry out. | |
| 783 | + auto& pages = pdf.pages(); | |
| 784 | + (void)pdf.acroform(); | |
| 785 | + (void)pdf.embedded_files(); | |
| 786 | + (void)pdf.page_labels(); | |
| 787 | + (void)pdf.outlines().resolveNamedDest(QPDFObjectHandle::newString("dummy")); | |
| 788 | + (void)pdf.outlines().getOutlinesForPage(pages.getAllPages().at(0)); | |
| 789 | + | |
| 782 | 790 | // Write the file to nowhere, uncompressing streams. This causes full file traversal and |
| 783 | 791 | // decoding of all streams we can decode. |
| 784 | 792 | QPDFWriter w(pdf); |
| ... | ... | @@ -789,7 +797,7 @@ QPDFJob::doCheck(QPDF& pdf) |
| 789 | 797 | |
| 790 | 798 | // Parse all content streams |
| 791 | 799 | int pageno = 0; |
| 792 | - for (auto& page: pdf.pages().getAllPages()) { | |
| 800 | + for (auto& page: pages.getAllPages()) { | |
| 793 | 801 | ++pageno; |
| 794 | 802 | try { |
| 795 | 803 | page.parseContents(nullptr); | ... | ... |
manual/release-notes.rst
| ... | ... | @@ -47,6 +47,9 @@ more detail. |
| 47 | 47 | with the incompatible options :qpdf:ref:`--encrypt` or |
| 48 | 48 | :qpdf:ref:`--copy-encryption`. |
| 49 | 49 | |
| 50 | + - Option :qpdf:ref:`--check` now includes additional basic checks of the | |
| 51 | + AcroForm, Dests, Outlines, and PageLabels structures. | |
| 52 | + | |
| 50 | 53 | - Other enhancements |
| 51 | 54 | |
| 52 | 55 | - ``QPDFWriter`` will no longer add filters when writing empty streams. | ... | ... |
qpdf/qtest/outlines.test
| ... | ... | @@ -21,7 +21,7 @@ my @outline_files = ( |
| 21 | 21 | 'outlines-with-old-root-dests-dict', |
| 22 | 22 | 'outlines-with-loop', |
| 23 | 23 | ); |
| 24 | -my $n_tests = scalar(@outline_files); | |
| 24 | +my $n_tests = scalar(@outline_files) + 1; | |
| 25 | 25 | foreach my $f (@outline_files) |
| 26 | 26 | { |
| 27 | 27 | $td->runtest("outlines: $f", |
| ... | ... | @@ -30,5 +30,10 @@ foreach my $f (@outline_files) |
| 30 | 30 | $td->NORMALIZE_NEWLINES); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | +$td->runtest("outlines: outlines-with-loop --check", | |
| 34 | + {$td->COMMAND => "qpdf --check outlines-with-loop.pdf"}, | |
| 35 | + {$td->FILE => "outlines-with-loop-check.out", $td->EXIT_STATUS => 0}, | |
| 36 | + $td->NORMALIZE_NEWLINES); | |
| 37 | + | |
| 33 | 38 | cleanup(); |
| 34 | 39 | $td->report($n_tests); | ... | ... |
qpdf/qtest/page-labels.test
| ... | ... | @@ -14,7 +14,7 @@ cleanup(); |
| 14 | 14 | |
| 15 | 15 | my $td = new TestDriver('page-labels'); |
| 16 | 16 | |
| 17 | -my $n_tests = 4; | |
| 17 | +my $n_tests = 5; | |
| 18 | 18 | |
| 19 | 19 | $td->runtest("complex page labels", |
| 20 | 20 | {$td->COMMAND => "test_driver 47 page-labels-num-tree.pdf"}, |
| ... | ... | @@ -38,6 +38,11 @@ $td->runtest("damaged page labels", |
| 38 | 38 | {$td->FILE => "page-labels-num-tree-damaged.out", $td->EXIT_STATUS => 0}, |
| 39 | 39 | $td->NORMALIZE_NEWLINES); |
| 40 | 40 | |
| 41 | +$td->runtest("damaged page labels --check", | |
| 42 | + {$td->COMMAND => "qpdf --check page-labels-num-tree-damaged.pdf"}, | |
| 43 | + {$td->FILE => "page-labels-num-tree-damaged-check.out", $td->EXIT_STATUS => 3}, | |
| 44 | + $td->NORMALIZE_NEWLINES); | |
| 45 | + | |
| 41 | 46 | # --set-page-labels |
| 42 | 47 | my @errors = ( |
| 43 | 48 | ["quack", ".*page label spec must be.*"], | ... | ... |
qpdf/qtest/qpdf/outlines-with-loop-check.out
0 → 100644
qpdf/qtest/qpdf/page-labels-num-tree-damaged-check.out
0 → 100644
| 1 | +checking page-labels-num-tree-damaged.pdf | |
| 2 | +PDF Version: 1.3 | |
| 3 | +File is not encrypted | |
| 4 | +File is not linearized | |
| 5 | +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 | |
| 6 | +WARNING: page-labels-num-tree-damaged.pdf (Name/Number tree node (object 37)): item 1 is invalid | |
| 7 | +qpdf: operation succeeded with warnings | ... | ... |