From 54753f37aa4cbd7f1aded18929436a52c5e58b5e Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 2 Sep 2025 16:13:01 +0100 Subject: [PATCH] Refactor: replace `QPDFObjectHandle` with `Dictionary` in `QPDF::readHintStream`, remove redundant `QTC::TC` call, and simplify type usage. --- include/qpdf/QPDF.hh | 13 +++++++++---- libqpdf/QPDF_linearization.cc | 12 ++++-------- qpdf/qpdf.testcov | 1 - 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 590257e..fe0ce8f 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -46,10 +46,15 @@ #include #include -namespace qpdf::is +namespace qpdf { - class OffsetBuffer; -} + class Dictionary; + + namespace is + { + class OffsetBuffer; + } +} // namespace qpdf class QPDF_Stream; class BitStream; @@ -1006,7 +1011,7 @@ class QPDF void checkLinearizationInternal(); void dumpLinearizationDataInternal(); void linearizationWarning(std::string_view); - QPDFObjectHandle readHintStream(Pipeline&, qpdf_offset_t offset, size_t length); + qpdf::Dictionary readHintStream(Pipeline&, qpdf_offset_t offset, size_t length); void readHPageOffset(BitStream); void readHSharedObject(BitStream); void readHGeneric(BitStream, HGeneric&); diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 1af95c0..6a5fd5f 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -262,7 +262,7 @@ QPDF::readLinearizationData() } } -QPDFObjectHandle +Dictionary QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) { auto H = readObjectAtOffset(offset, "linearization hint stream", false); @@ -273,18 +273,14 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) throw damagedPDF("linearization dictionary", "hint table is not a stream"); } - QPDFObjectHandle Hdict = H.getDict(); + Dictionary Hdict = H.getDict(); // Some versions of Acrobat make /Length indirect and place it immediately after the stream, // increasing length to cover it, even though the specification says all objects in the // linearization parameter dictionary must be direct. We have to get the file position of the // end of length in this case. - QPDFObjectHandle length_obj = Hdict.getKey("/Length"); - if (length_obj.isIndirect()) { - QTC::TC("qpdf", "QPDF hint table length indirect"); - // Force resolution - (void)length_obj.getIntValue(); - ObjCache& oc2 = m->obj_cache[length_obj.getObjGen()]; + if (Hdict["/Length"].indirect()) { + ObjCache& oc2 = m->obj_cache[Hdict["/Length"]]; min_end_offset = oc2.end_before_space; max_end_offset = oc2.end_after_space; } else { diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 9f4c772..114f10d 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -7,7 +7,6 @@ QPDF check obj 1 QPDF object stream offsets not increasing 0 QPDF ignore self-referential object stream 0 QPDF object stream contains id < 1 0 -QPDF hint table length indirect 0 QPDF hint table length direct 0 QPDF P absent in lindict 0 QPDF P present in lindict 0 -- libgit2 0.21.4