diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 548a307..adb7d9a 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -641,6 +641,11 @@ QPDF::reconstruct_xref(QPDFExc& e) throw damagedPDF("", 0, "unable to find trailer dictionary while recovering damaged file"); } + if (m->xref_table.empty()) { + // We cannot check for an empty xref table in parse because empty tables are valid when + // creating QPDF objects from JSON. + throw damagedPDF("", 0, "unable to find objects while recovering damaged file"); + } // We could iterate through the objects looking for streams and try to find objects inside of // them, but it's probably not worth the trouble. Acrobat can't recover files with any errors diff --git a/qpdf/qtest/qpdf/issue-147.out b/qpdf/qtest/qpdf/issue-147.out index e35bdbc..9e766df 100644 --- a/qpdf/qtest/qpdf/issue-147.out +++ b/qpdf/qtest/qpdf/issue-147.out @@ -4,4 +4,4 @@ WARNING: issue-147.pdf: can't find startxref WARNING: issue-147.pdf: Attempting to reconstruct cross-reference table WARNING: issue-147.pdf (trailer, offset 9): expected dictionary key but found non-name object; inserting key /QPDFFake1 WARNING: issue-147.pdf: ignoring object with impossibly large id 62 -qpdf: issue-147.pdf: unable to find /Root dictionary +qpdf: issue-147.pdf: unable to find objects while recovering damaged file