Commit 4ebe54529cdce132a12f4a205ff7cc7c3641cda0
1 parent
a095549e
Fix linearization logic to conditionally add outlines object only if erased, ens…
…uring robustness against damaged PDFs.
Showing
1 changed file
with
13 additions
and
7 deletions
libqpdf/QPDF_linearization.cc
| @@ -1412,14 +1412,20 @@ QPDF::pushOutlinesToPart( | @@ -1412,14 +1412,20 @@ QPDF::pushOutlinesToPart( | ||
| 1412 | QTC::TC( | 1412 | QTC::TC( |
| 1413 | "qpdf", | 1413 | "qpdf", |
| 1414 | "QPDF lin outlines in part", | 1414 | "QPDF lin outlines in part", |
| 1415 | - ((&part == (&m->part6)) ? 0 | ||
| 1416 | - : (&part == (&m->part9)) ? 1 | ||
| 1417 | - : 9999)); // can't happen | ||
| 1418 | - m->c_outline_data.first_object = outlines_og.getObj(); | ||
| 1419 | - m->c_outline_data.nobjects = 1; | ||
| 1420 | - lc_outlines.erase(outlines_og); | ||
| 1421 | - part.push_back(outlines); | 1415 | + &part == &m->part6 ? 0 |
| 1416 | + : (&part == &m->part9) ? 1 | ||
| 1417 | + : 9999); // can't happen | ||
| 1418 | + if (lc_outlines.erase(outlines_og)) { | ||
| 1419 | + // Make sure outlines is in lc_outlines in case the file is damaged. in which case it may be | ||
| 1420 | + // included in an earlier part. | ||
| 1421 | + part.push_back(outlines); | ||
| 1422 | + m->c_outline_data.first_object = outlines_og.getObj(); | ||
| 1423 | + m->c_outline_data.nobjects = 1; | ||
| 1424 | + } | ||
| 1422 | for (auto const& og: lc_outlines) { | 1425 | for (auto const& og: lc_outlines) { |
| 1426 | + if (!m->c_outline_data.first_object) { | ||
| 1427 | + m->c_outline_data.first_object = og.getObj(); | ||
| 1428 | + } | ||
| 1423 | part.push_back(getObject(og)); | 1429 | part.push_back(getObject(og)); |
| 1424 | ++m->c_outline_data.nobjects; | 1430 | ++m->c_outline_data.nobjects; |
| 1425 | } | 1431 | } |