diff options
author | m-holger <m-holger@kubitscheck.org> | 2024-01-08 14:42:05 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2024-01-08 16:55:51 +0100 |
commit | e28625144d8eb77b98d3e64107aa0f353863def4 (patch) | |
tree | f92ceff0b500a87c07bc06bdc6308e1f6e652679 /libqpdf | |
parent | adb866efd3942ca0ce9c93a60dfecdde332379ec (diff) | |
download | qpdf-e28625144d8eb77b98d3e64107aa0f353863def4.tar.zst |
Tweak QPDF::getCompressibleObjGens
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDF.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index e2371c9d..89d4a0a8 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2398,7 +2398,6 @@ QPDF::getCompressibleObjGens() const size_t max_obj = getObjectCount(); std::vector<bool> visited(max_obj, false); - QPDFObjGen::set visited_gen; // for objects with generation > 0 std::vector<QPDFObjectHandle> queue; queue.reserve(512); queue.push_back(m->trailer); @@ -2409,19 +2408,25 @@ QPDF::getCompressibleObjGens() if (obj.isIndirect()) { QPDFObjGen og = obj.getObjGen(); const size_t id = toS(og.getObj() - 1); - const int gen = og.getGen(); if (id >= max_obj) throw std::logic_error( "unexpected object id encountered in getCompressibleObjGens"); - if ((gen == 0 && visited[id]) || visited_gen.count(og)) { + if (visited[id]) { QTC::TC("qpdf", "QPDF loop detected traversing objects"); continue; } - if (gen == 0) { - visited[id] = true; - } else { - visited_gen.insert(og); + + // Check whether this is the current object. If not, remove it (which changes it into a + // direct null and therefore stops us from revisiting it) and move on to the next object + // in the queue. + auto upper = m->obj_cache.upper_bound(og); + if (upper != m->obj_cache.end() && upper->first.getObj() == og.getObj()) { + removeObject(og); + continue; } + + visited[id] = true; + if (og == encryption_dict_og) { QTC::TC("qpdf", "QPDF exclude encryption dictionary"); } else if (!(obj.isStream() || |