From 7f8892525f897b17049f9e59bc4ce8ac28c9e082 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 27 Jul 2017 23:42:27 -0400 Subject: Add precheck streams capability When requested, QPDFWriter will do more aggress prechecking of streams to make sure it can actually succeed in decoding them before attempting to do so. This will allow preservation of raw data even when the raw data is corrupted relative to the specified filters. --- libqpdf/QPDF.cc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'libqpdf/QPDF.cc') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 32c8cdf9..b5c1212c 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2134,12 +2134,14 @@ QPDF::getCompressibleObjGens() return result; } -void +bool QPDF::pipeStreamData(int objid, int generation, qpdf_offset_t offset, size_t length, QPDFObjectHandle stream_dict, - Pipeline* pipeline) + Pipeline* pipeline, + bool suppress_warnings) { + bool success = false; std::vector > to_delete; if (this->encrypted) { @@ -2165,21 +2167,29 @@ QPDF::pipeStreamData(int objid, int generation, length -= len; pipeline->write(QUtil::unsigned_char_pointer(buf), len); } + success = true; } catch (QPDFExc& e) { - warn(e); + if (! suppress_warnings) + { + warn(e); + } } catch (std::runtime_error& e) { - QTC::TC("qpdf", "QPDF decoding error warning"); - warn(QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), - "", this->file->getLastOffset(), - "error decoding stream data for object " + - QUtil::int_to_string(objid) + " " + - QUtil::int_to_string(generation) + ": " + e.what())); + if (! suppress_warnings) + { + QTC::TC("qpdf", "QPDF decoding error warning"); + warn(QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), + "", this->file->getLastOffset(), + "error decoding stream data for object " + + QUtil::int_to_string(objid) + " " + + QUtil::int_to_string(generation) + ": " + e.what())); + } } pipeline->finish(); + return success; } void -- cgit v1.2.3-54-g00ecf