Commit ba477e0b335ea430451711e125843f7624803ae5
1 parent
61954995
Tune QPDF::getCompressibleObjGens
Change set visited to std::vector<bool>
Showing
1 changed file
with
9 additions
and
3 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -2376,20 +2376,26 @@ QPDF::getCompressibleObjGens() |
| 2376 | 2376 | QPDFObjectHandle encryption_dict = m->trailer.getKey("/Encrypt"); |
| 2377 | 2377 | QPDFObjGen encryption_dict_og = encryption_dict.getObjGen(); |
| 2378 | 2378 | |
| 2379 | - QPDFObjGen::set visited; | |
| 2379 | + const size_t max_obj = getObjectCount(); | |
| 2380 | + std::vector<bool> visited(max_obj, false); | |
| 2380 | 2381 | std::vector<QPDFObjectHandle> queue; |
| 2381 | 2382 | queue.reserve(512); |
| 2382 | 2383 | queue.push_back(m->trailer); |
| 2383 | 2384 | std::vector<QPDFObjGen> result; |
| 2384 | 2385 | while (!queue.empty()) { |
| 2385 | - QPDFObjectHandle obj = queue.back(); | |
| 2386 | + auto obj = queue.back(); | |
| 2386 | 2387 | queue.pop_back(); |
| 2387 | 2388 | if (obj.isIndirect()) { |
| 2388 | 2389 | QPDFObjGen og = obj.getObjGen(); |
| 2389 | - if (!visited.add(og)) { | |
| 2390 | + const size_t id = toS(og.getObj() - 1); | |
| 2391 | + if (id >= max_obj) | |
| 2392 | + throw std::runtime_error( | |
| 2393 | + "unexpected object id encountered in getCompressibleObjGens"); | |
| 2394 | + if (visited[id]) { | |
| 2390 | 2395 | QTC::TC("qpdf", "QPDF loop detected traversing objects"); |
| 2391 | 2396 | continue; |
| 2392 | 2397 | } |
| 2398 | + visited[id] = true; | |
| 2393 | 2399 | if (og == encryption_dict_og) { |
| 2394 | 2400 | QTC::TC("qpdf", "QPDF exclude encryption dictionary"); |
| 2395 | 2401 | } else if (!(obj.isStream() || | ... | ... |