Commit cc628d9b5786bf84efbae3ed22b8cda99d935a73
1 parent
9e358a32
Fix error handling for missing pages in QPDFJob::doCheck (fixes #1674)
Showing
5 changed files
with
42 additions
and
6 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -745,13 +745,17 @@ QPDFJob::doCheck(QPDF& pdf) |
| 745 | 745 | |
| 746 | 746 | // Create all document helper to trigger any validations they carry out. |
| 747 | 747 | auto& doc = pdf.doc(); |
| 748 | - auto& pages = doc.page_dh(); | |
| 748 | + auto pages = doc.page_dh().getAllPages(); | |
| 749 | 749 | (void)doc.acroform(); |
| 750 | 750 | (void)doc.embedded_files(); |
| 751 | 751 | (void)doc.page_labels(); |
| 752 | - (void)doc.outlines().resolveNamedDest(QPDFObjectHandle::newString("dummy")); | |
| 753 | - (void)doc.outlines().getOutlinesForPage(pages.getAllPages().at(0)); | |
| 754 | - | |
| 752 | + (void)doc.outlines().resolveNamedDest(String("dummy")); | |
| 753 | + if (pages.empty()) { | |
| 754 | + okay = false; | |
| 755 | + *m->log->getError() << "ERROR: file does not contain any pages\n"; | |
| 756 | + } else { | |
| 757 | + (void)doc.outlines().getOutlinesForPage(pages.at(0)); | |
| 758 | + } | |
| 755 | 759 | // Write the file to nowhere, uncompressing streams. This causes full file traversal and |
| 756 | 760 | // decoding of all streams we can decode. |
| 757 | 761 | Writer::Config cfg; |
| ... | ... | @@ -766,7 +770,7 @@ QPDFJob::doCheck(QPDF& pdf) |
| 766 | 770 | |
| 767 | 771 | // Parse all content streams |
| 768 | 772 | int pageno = 0; |
| 769 | - for (auto& page: pages.getAllPages()) { | |
| 773 | + for (auto& page: pages) { | |
| 770 | 774 | ++pageno; |
| 771 | 775 | try { |
| 772 | 776 | page.parseContents(nullptr); | ... | ... |
manual/release-notes.rst
qpdf/qtest/page-errors.test
| ... | ... | @@ -14,7 +14,7 @@ cleanup(); |
| 14 | 14 | |
| 15 | 15 | my $td = new TestDriver('page-errors'); |
| 16 | 16 | |
| 17 | -my $n_tests = 9; | |
| 17 | +my $n_tests = 10; | |
| 18 | 18 | |
| 19 | 19 | $td->runtest("handle page no with contents", |
| 20 | 20 | {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"}, |
| ... | ... | @@ -49,6 +49,10 @@ $td->runtest("detect loops in pages structure", |
| 49 | 49 | {$td->COMMAND => "qpdf --check pages-loop.pdf"}, |
| 50 | 50 | {$td->FILE => "pages-loop.out", $td->EXIT_STATUS => 2}, |
| 51 | 51 | $td->NORMALIZE_NEWLINES); |
| 52 | +$td->runtest("file with zero pages", | |
| 53 | + {$td->COMMAND => "qpdf --check empty.pdf"}, | |
| 54 | + {$td->FILE => "empty-check.out", $td->EXIT_STATUS => 2}, | |
| 55 | + $td->NORMALIZE_NEWLINES); | |
| 52 | 56 | |
| 53 | 57 | cleanup(); |
| 54 | 58 | $td->report($n_tests); | ... | ... |
qpdf/qtest/qpdf/empty-check.out
0 → 100644
qpdf/qtest/qpdf/empty.pdf
0 → 100644
| 1 | +%PDF-1.3 | |
| 2 | +%¿÷¢þ | |
| 3 | +1 0 obj | |
| 4 | +<< /Pages 2 0 R /Type /Catalog >> | |
| 5 | +endobj | |
| 6 | +2 0 obj | |
| 7 | +<< /Count 0 /Kids [ ] /Type /Pages >> | |
| 8 | +endobj | |
| 9 | +xref | |
| 10 | +0 3 | |
| 11 | +0000000000 65535 f | |
| 12 | +0000000015 00000 n | |
| 13 | +0000000064 00000 n | |
| 14 | +trailer << /Root 1 0 R /Size 3 /ID [<c340298302ab3c4e01d6f14c08b392dd><c340298302ab3c4e01d6f14c08b392dd>] >> | |
| 15 | +startxref | |
| 16 | +117 | |
| 17 | +%%EOF | ... | ... |