Tweak QPDF::getCompressibleObjGens

This commit is contained in:
m-holger 2024-01-08 13:42:05 +00:00 committed by Jay Berkenbilt
parent adb866efd3
commit e28625144d
1 changed files with 12 additions and 7 deletions

View File

@ -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() ||