Commit 2e378d920d18714b3c4f60c82e7f9458b0dcf333

Authored by m-holger
1 parent 7445e0ac

Add additional sanity check during xref reconstruction

Check that xref table is not empty after recovery. Empty xref tables
disable other sanity checks.
libqpdf/QPDF.cc
... ... @@ -641,6 +641,11 @@ QPDF::reconstruct_xref(QPDFExc& e)
641 641  
642 642 throw damagedPDF("", 0, "unable to find trailer dictionary while recovering damaged file");
643 643 }
  644 + if (m->xref_table.empty()) {
  645 + // We cannot check for an empty xref table in parse because empty tables are valid when
  646 + // creating QPDF objects from JSON.
  647 + throw damagedPDF("", 0, "unable to find objects while recovering damaged file");
  648 + }
644 649  
645 650 // We could iterate through the objects looking for streams and try to find objects inside of
646 651 // them, but it's probably not worth the trouble. Acrobat can't recover files with any errors
... ...
qpdf/qtest/qpdf/issue-147.out
... ... @@ -4,4 +4,4 @@ WARNING: issue-147.pdf: can't find startxref
4 4 WARNING: issue-147.pdf: Attempting to reconstruct cross-reference table
5 5 WARNING: issue-147.pdf (trailer, offset 9): expected dictionary key but found non-name object; inserting key /QPDFFake1
6 6 WARNING: issue-147.pdf: ignoring object with impossibly large id 62
7   -qpdf: issue-147.pdf: unable to find /Root dictionary
  7 +qpdf: issue-147.pdf: unable to find objects while recovering damaged file
... ...