From c71dc6888c69aea7a892b313e07dba377200a6c9 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 22 Jun 2018 10:45:31 -0400 Subject: Don't prune resource dictionaries on errors or by request If we are unable to filter a page's content streams, don't attempt to remove objects from the page's resource dictionary. Also provide a command line option to suppress resource removal in case we ever need this as a workaround for some bug or broken PDF files. --- libqpdf/QPDFPageObjectHelper.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libqpdf/QPDFPageObjectHelper.cc') diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index e9e09d73..4093622d 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -122,7 +122,17 @@ void QPDFPageObjectHelper::removeUnreferencedResources() { NameWatcher nw; - filterPageContents(&nw); + try + { + filterPageContents(&nw); + } + catch (std::exception& e) + { + this->oh.warnIfPossible( + std::string("Unable to parse content stream: ") + e.what() + + "; not attempting to remove unreferenced objects from this page"); + return; + } // Walk through /Font and /XObject dictionaries, removing any // resources that are not referenced. We must make copies of // resource dictionaries down into the dictionaries are mutating -- cgit v1.2.3-54-g00ecf