Commit 972e08af58838f5494a05f70683d848130755d78
1 parent
85884c36
Protect against future bugs in fixCopiedAnnotations
I don't want additional, undiscovered bugs to fully block page splitting/merging operations.
Showing
1 changed file
with
26 additions
and
4 deletions
qpdf/qpdf.cc
| ... | ... | @@ -5946,9 +5946,20 @@ static void handle_page_specs(QPDF& pdf, Options& o, bool& warnings) |
| 5946 | 5946 | { |
| 5947 | 5947 | QTC::TC("qpdf", "qpdf copy fields non-first from orig"); |
| 5948 | 5948 | } |
| 5949 | - this_afdh->fixCopiedAnnotations( | |
| 5950 | - new_page, to_copy.getObjectHandle(), *other_afdh, | |
| 5951 | - &referenced_fields); | |
| 5949 | + try | |
| 5950 | + { | |
| 5951 | + this_afdh->fixCopiedAnnotations( | |
| 5952 | + new_page, to_copy.getObjectHandle(), *other_afdh, | |
| 5953 | + &referenced_fields); | |
| 5954 | + } | |
| 5955 | + catch (std::exception& e) | |
| 5956 | + { | |
| 5957 | + pdf.warn( | |
| 5958 | + QPDFExc(qpdf_e_damaged_pdf, pdf.getFilename(), | |
| 5959 | + "", 0, "Exception caught while fixing copied" | |
| 5960 | + " annotations. This may be a qpdf bug." + | |
| 5961 | + std::string("Exception: ") + e.what())); | |
| 5962 | + } | |
| 5952 | 5963 | } |
| 5953 | 5964 | } |
| 5954 | 5965 | if (page_data.qpdf->anyWarnings()) |
| ... | ... | @@ -6400,7 +6411,18 @@ static void do_split_pages(QPDF& pdf, Options& o, bool& warnings) |
| 6400 | 6411 | if (out_afdh.getPointer()) |
| 6401 | 6412 | { |
| 6402 | 6413 | QTC::TC("qpdf", "qpdf copy form fields in split_pages"); |
| 6403 | - out_afdh->fixCopiedAnnotations(new_page, page, afdh); | |
| 6414 | + try | |
| 6415 | + { | |
| 6416 | + out_afdh->fixCopiedAnnotations(new_page, page, afdh); | |
| 6417 | + } | |
| 6418 | + catch (std::exception& e) | |
| 6419 | + { | |
| 6420 | + pdf.warn( | |
| 6421 | + QPDFExc(qpdf_e_damaged_pdf, pdf.getFilename(), | |
| 6422 | + "", 0, "Exception caught while fixing copied" | |
| 6423 | + " annotations. This may be a qpdf bug." + | |
| 6424 | + std::string("Exception: ") + e.what())); | |
| 6425 | + } | |
| 6404 | 6426 | } |
| 6405 | 6427 | } |
| 6406 | 6428 | if (pldh.hasPageLabels()) | ... | ... |