From 972e08af58838f5494a05f70683d848130755d78 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 11 Mar 2021 12:49:27 -0500 Subject: Protect against future bugs in fixCopiedAnnotations I don't want additional, undiscovered bugs to fully block page splitting/merging operations. --- qpdf/qpdf.cc | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 48467734..f51e0454 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -5946,9 +5946,20 @@ static void handle_page_specs(QPDF& pdf, Options& o, bool& warnings) { QTC::TC("qpdf", "qpdf copy fields non-first from orig"); } - this_afdh->fixCopiedAnnotations( - new_page, to_copy.getObjectHandle(), *other_afdh, - &referenced_fields); + try + { + this_afdh->fixCopiedAnnotations( + new_page, to_copy.getObjectHandle(), *other_afdh, + &referenced_fields); + } + catch (std::exception& e) + { + pdf.warn( + QPDFExc(qpdf_e_damaged_pdf, pdf.getFilename(), + "", 0, "Exception caught while fixing copied" + " annotations. This may be a qpdf bug." + + std::string("Exception: ") + e.what())); + } } } if (page_data.qpdf->anyWarnings()) @@ -6400,7 +6411,18 @@ static void do_split_pages(QPDF& pdf, Options& o, bool& warnings) if (out_afdh.getPointer()) { QTC::TC("qpdf", "qpdf copy form fields in split_pages"); - out_afdh->fixCopiedAnnotations(new_page, page, afdh); + try + { + out_afdh->fixCopiedAnnotations(new_page, page, afdh); + } + catch (std::exception& e) + { + pdf.warn( + QPDFExc(qpdf_e_damaged_pdf, pdf.getFilename(), + "", 0, "Exception caught while fixing copied" + " annotations. This may be a qpdf bug." + + std::string("Exception: ") + e.what())); + } } } if (pldh.hasPageLabels()) -- cgit v1.2.3-54-g00ecf