diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index c972706..d39e1ec 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -745,13 +745,17 @@ QPDFJob::doCheck(QPDF& pdf) // Create all document helper to trigger any validations they carry out. auto& doc = pdf.doc(); - auto& pages = doc.page_dh(); + auto pages = doc.page_dh().getAllPages(); (void)doc.acroform(); (void)doc.embedded_files(); (void)doc.page_labels(); - (void)doc.outlines().resolveNamedDest(QPDFObjectHandle::newString("dummy")); - (void)doc.outlines().getOutlinesForPage(pages.getAllPages().at(0)); - + (void)doc.outlines().resolveNamedDest(String("dummy")); + if (pages.empty()) { + okay = false; + *m->log->getError() << "ERROR: file does not contain any pages\n"; + } else { + (void)doc.outlines().getOutlinesForPage(pages.at(0)); + } // Write the file to nowhere, uncompressing streams. This causes full file traversal and // decoding of all streams we can decode. Writer::Config cfg; @@ -766,7 +770,7 @@ QPDFJob::doCheck(QPDF& pdf) // Parse all content streams int pageno = 0; - for (auto& page: pages.getAllPages()) { + for (auto& page: pages) { ++pageno; try { page.parseContents(nullptr); diff --git a/manual/release-notes.rst b/manual/release-notes.rst index eb1d01e..4b06e86 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -13,6 +13,11 @@ more detail. .. x.y.z: not yet released +12.3.3: not yet released + - Bug fixes + + - Fix error message when :qpdf:ref:`--check` encounters a file without any pages. + 12.3.2: January 24, 2026 - Bug fixes diff --git a/qpdf/qtest/page-errors.test b/qpdf/qtest/page-errors.test index d09b8e1..5300f51 100644 --- a/qpdf/qtest/page-errors.test +++ b/qpdf/qtest/page-errors.test @@ -14,7 +14,7 @@ cleanup(); my $td = new TestDriver('page-errors'); -my $n_tests = 9; +my $n_tests = 10; $td->runtest("handle page no with contents", {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"}, @@ -49,6 +49,10 @@ $td->runtest("detect loops in pages structure", {$td->COMMAND => "qpdf --check pages-loop.pdf"}, {$td->FILE => "pages-loop.out", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("file with zero pages", + {$td->COMMAND => "qpdf --check empty.pdf"}, + {$td->FILE => "empty-check.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); cleanup(); $td->report($n_tests); diff --git a/qpdf/qtest/qpdf/empty-check.out b/qpdf/qtest/qpdf/empty-check.out new file mode 100644 index 0000000..f0a92bb --- /dev/null +++ b/qpdf/qtest/qpdf/empty-check.out @@ -0,0 +1,6 @@ +checking empty.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized +ERROR: file does not contain any pages +qpdf: errors detected diff --git a/qpdf/qtest/qpdf/empty.pdf b/qpdf/qtest/qpdf/empty.pdf new file mode 100644 index 0000000..3808402 --- /dev/null +++ b/qpdf/qtest/qpdf/empty.pdf @@ -0,0 +1,17 @@ +%PDF-1.3 +%¿÷¢þ +1 0 obj +<< /Pages 2 0 R /Type /Catalog >> +endobj +2 0 obj +<< /Count 0 /Kids [ ] /Type /Pages >> +endobj +xref +0 3 +0000000000 65535 f +0000000015 00000 n +0000000064 00000 n +trailer << /Root 1 0 R /Size 3 /ID [] >> +startxref +117 +%%EOF