From 0be4a8e7a8ee8b227611224a0e36ffe013360f9d Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 5 Oct 2025 11:44:58 +0100 Subject: [PATCH] Move `ParseGuard` to `QPDF::Doc` and update references --- include/qpdf/QPDF.hh | 1 - libqpdf/QPDFParser.cc | 34 ++++++++++++++++++++++++++++++++-- libqpdf/qpdf/QPDF_private.hh | 32 ++------------------------------ 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index a89aae5..863650a 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -793,7 +793,6 @@ class QPDF class Writer; class Resolver; class StreamCopier; - class ParseGuard; class Pipe; class JobSetter; diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc index 0132f17..c4ceee1 100644 --- a/libqpdf/QPDFParser.cc +++ b/libqpdf/QPDFParser.cc @@ -15,6 +15,36 @@ using namespace qpdf; using ObjectPtr = std::shared_ptr; +// The ParseGuard class allows QPDFParser to detect re-entrant parsing. It also provides +// special access to allow the parser to create unresolved objects and dangling references. +class QPDF::Doc::ParseGuard +{ + public: + ParseGuard(QPDF* qpdf) : + qpdf(qpdf) + { + if (qpdf) { + qpdf->inParse(true); + } + } + + static std::shared_ptr + getObject(QPDF* qpdf, int id, int gen, bool parse_pdf) + { + return qpdf->getObjectForParser(id, gen, parse_pdf); + } + + ~ParseGuard() + { + if (qpdf) { + qpdf->inParse(false); + } + } + QPDF* qpdf; +}; + +using ParseGuard = QPDF::Doc::ParseGuard; + QPDFObjectHandle QPDFParser::parse(InputSource& input, std::string const& object_description, QPDF* context) { @@ -126,7 +156,7 @@ QPDFParser::parse(bool& empty, bool content_stream) // effect of reading the object and changing the file pointer. If you do this, it will cause a // logic error to be thrown from QPDF::inParse(). - QPDF::ParseGuard pg(context); + ParseGuard pg(context); empty = false; start = input.tell(); @@ -262,7 +292,7 @@ QPDFParser::parseRemainder(bool content_stream) auto id = QIntC::to_int(int_buffer[(int_count - 1) % 2]); auto gen = QIntC::to_int(int_buffer[(int_count) % 2]); if (!(id < 1 || gen < 0 || gen >= 65535)) { - add(QPDF::ParseGuard::getObject(context, id, gen, parse_pdf)); + add(ParseGuard::getObject(context, id, gen, parse_pdf)); } else { QTC::TC("qpdf", "QPDFParser invalid objgen"); addNull(); diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index bd71708..69943f0 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -41,36 +41,6 @@ class QPDF::StreamCopier } }; -// The ParseGuard class allows QPDFParser to detect re-entrant parsing. It also provides -// special access to allow the parser to create unresolved objects and dangling references. -class QPDF::ParseGuard -{ - friend class QPDFParser; - - private: - ParseGuard(QPDF* qpdf) : - qpdf(qpdf) - { - if (qpdf) { - qpdf->inParse(true); - } - } - - static std::shared_ptr - getObject(QPDF* qpdf, int id, int gen, bool parse_pdf) - { - return qpdf->getObjectForParser(id, gen, parse_pdf); - } - - ~ParseGuard() - { - if (qpdf) { - qpdf->inParse(false); - } - } - QPDF* qpdf; -}; - // Pipe class is restricted to QPDF_Stream. class QPDF::Pipe { @@ -412,6 +382,8 @@ class QPDF::PatternFinder final: public InputSource::Finder class QPDF::Doc { public: + class ParseGuard; + Doc() = delete; Doc(Doc const&) = delete; Doc(Doc&&) = delete; -- libgit2 0.21.4