From d64b14912d2f96e81fc56c15b19c9678bd5e58f6 Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 12 Aug 2024 16:01:37 +0100 Subject: [PATCH] Move QPDF::readTrailer to QPDF::Xref_table --- include/qpdf/QPDF.hh | 1 - libqpdf/QPDF.cc | 18 +++++++++--------- libqpdf/qpdf/QPDF_private.hh | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index cfb790d1..a7cc3e58 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -760,7 +760,6 @@ class QPDF void parse(char const* password); void inParse(bool); void setLastObjectDescription(std::string const& description, QPDFObjGen const& og); - QPDFObjectHandle readTrailer(); QPDFObjectHandle readObject(std::string const& description, QPDFObjGen og); void readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset); void validateStreamLineEnd(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 00ab1ce0..26d5142d 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -596,7 +596,7 @@ QPDF::Xref_table::reconstruct(QPDFExc& e) file->seek(pos, SEEK_SET); } else if (!trailer && t1.isWord("trailer")) { auto pos = file->tell(); - QPDFObjectHandle t = qpdf.readTrailer(); + QPDFObjectHandle t = read_trailer(); if (!t.isDictionary()) { // Oh well. It was worth a try. } else { @@ -994,7 +994,7 @@ QPDF::Xref_table::read_table(qpdf_offset_t xref_offset) } // Set offset to previous xref table if any - auto cur_trailer = qpdf.readTrailer(); + auto cur_trailer = read_trailer(); if (!cur_trailer.isDictionary()) { QTC::TC("qpdf", "QPDF missing trailer"); throw qpdf.damagedPDF("", "expected trailer dictionary"); @@ -1456,21 +1456,21 @@ QPDF::setLastObjectDescription(std::string const& description, QPDFObjGen const& } QPDFObjectHandle -QPDF::readTrailer() +QPDF::Xref_table::read_trailer() { - qpdf_offset_t offset = m->file->tell(); + qpdf_offset_t offset = file->tell(); bool empty = false; auto object = - QPDFParser(*m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false); + QPDFParser(*qpdf.m->file, "trailer", *tokenizer, nullptr, &qpdf, true).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")); + qpdf.warn(qpdf.damagedPDF("trailer", "empty object treated as null")); + } else if (object.isDictionary() && read_token().isWord("stream")) { + qpdf.warn(qpdf.damagedPDF("trailer", 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); + file->setLastOffset(offset); return object; } diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index 9beaa29d..a83c970a 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -54,6 +54,8 @@ class QPDF::Xref_table: public std::map int max_num_entries, std::function damaged); + QPDFObjectHandle read_trailer(); + QPDFTokenizer::Token read_token(size_t max_len = 0) {