mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-02 11:58:25 +00:00
Tweak QPDF::getCompressibleObjGens
This commit is contained in:
parent
adb866efd3
commit
e28625144d
@ -2398,7 +2398,6 @@ QPDF::getCompressibleObjGens()
|
|||||||
|
|
||||||
const size_t max_obj = getObjectCount();
|
const size_t max_obj = getObjectCount();
|
||||||
std::vector<bool> visited(max_obj, false);
|
std::vector<bool> visited(max_obj, false);
|
||||||
QPDFObjGen::set visited_gen; // for objects with generation > 0
|
|
||||||
std::vector<QPDFObjectHandle> queue;
|
std::vector<QPDFObjectHandle> queue;
|
||||||
queue.reserve(512);
|
queue.reserve(512);
|
||||||
queue.push_back(m->trailer);
|
queue.push_back(m->trailer);
|
||||||
@ -2409,19 +2408,25 @@ QPDF::getCompressibleObjGens()
|
|||||||
if (obj.isIndirect()) {
|
if (obj.isIndirect()) {
|
||||||
QPDFObjGen og = obj.getObjGen();
|
QPDFObjGen og = obj.getObjGen();
|
||||||
const size_t id = toS(og.getObj() - 1);
|
const size_t id = toS(og.getObj() - 1);
|
||||||
const int gen = og.getGen();
|
|
||||||
if (id >= max_obj)
|
if (id >= max_obj)
|
||||||
throw std::logic_error(
|
throw std::logic_error(
|
||||||
"unexpected object id encountered in getCompressibleObjGens");
|
"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");
|
QTC::TC("qpdf", "QPDF loop detected traversing objects");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (gen == 0) {
|
|
||||||
visited[id] = true;
|
// Check whether this is the current object. If not, remove it (which changes it into a
|
||||||
} else {
|
// direct null and therefore stops us from revisiting it) and move on to the next object
|
||||||
visited_gen.insert(og);
|
// 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) {
|
if (og == encryption_dict_og) {
|
||||||
QTC::TC("qpdf", "QPDF exclude encryption dictionary");
|
QTC::TC("qpdf", "QPDF exclude encryption dictionary");
|
||||||
} else if (!(obj.isStream() ||
|
} else if (!(obj.isStream() ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user