diff options
author | m-holger <m-holger@kubitscheck.org> | 2023-07-08 01:38:50 +0200 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2023-07-08 02:28:15 +0200 |
commit | 2643ed4dd9bd1a8e9bb3dcd95794273e9cf5de0c (patch) | |
tree | 614afd8d9a99e81bf9bbe35f6da196b3add582ba /libqpdf | |
parent | bee726609c9b0c3f6bc497de9ab0fc0790993c89 (diff) | |
download | qpdf-2643ed4dd9bd1a8e9bb3dcd95794273e9cf5de0c.tar.zst |
Add new private method QPDF::readTrailer()
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDF.cc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 3a486457..48f1e186 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -567,7 +567,7 @@ QPDF::reconstruct_xref(QPDFExc& e) insertReconstructedXrefEntry(obj, token_start, gen); } } else if (!m->trailer.isInitialized() && t1.isWord("trailer")) { - QPDFObjectHandle t = readObject("trailer", QPDFObjGen()); + QPDFObjectHandle t = readTrailer(); if (!t.isDictionary()) { // Oh well. It was worth a try. } else { @@ -855,7 +855,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) } // Set offset to previous xref table if any - QPDFObjectHandle cur_trailer = readObject("trailer", QPDFObjGen()); + QPDFObjectHandle cur_trailer = readTrailer(); if (!cur_trailer.isDictionary()) { QTC::TC("qpdf", "QPDF missing trailer"); throw damagedPDF("", "expected trailer dictionary"); @@ -1268,6 +1268,25 @@ QPDF::setLastObjectDescription(std::string const& description, QPDFObjGen const& } QPDFObjectHandle +QPDF::readTrailer() +{ + qpdf_offset_t offset = m->file->tell(); + bool empty = false; + auto object = QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this).parse(empty, false); + if (empty) { + // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in + // actual PDF files and Adobe Reader appears to ignore them. + warn(damagedPDF("trailer", "empty object treated as null")); + } else if (object.isDictionary() && readToken(m->file).isWord("stream")) { + warn(damagedPDF("trailer", m->file->tell(), "stream keyword found in trailer")); + } + // Override last_offset so that it points to the beginning of the object we just read + m->file->setLastOffset(offset); + return object; +} + + +QPDFObjectHandle QPDF::readObject(std::string const& description, QPDFObjGen og) { setLastObjectDescription(description, og); |