aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-07-28 05:42:27 +0200
committerJay Berkenbilt <ejb@ql.org>2017-07-28 05:42:27 +0200
commit7f8892525f897b17049f9e59bc4ce8ac28c9e082 (patch)
tree8f46d2ac355e8245cb2e0c764ebe0b34923e3494 /libqpdf/QPDF.cc
parent428d96dfe19da96ac4759b190f5b25cf75ecdac6 (diff)
downloadqpdf-7f8892525f897b17049f9e59bc4ce8ac28c9e082.tar.zst
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.
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r--libqpdf/QPDF.cc28
1 files changed, 19 insertions, 9 deletions
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<PointerHolder<Pipeline> > 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