aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-06 16:34:52 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-07 06:11:15 +0100
commitfbbb0ee0167a9013c3a712c790a9772075aed2ad (patch)
tree8a0024ce4308413d999ccb82c68a4f76fb48f37e /libqpdf/QPDF.cc
parent7588cac2957f66c6f0e3f5fb5b691ecbb8f3e0b2 (diff)
downloadqpdf-fbbb0ee0167a9013c3a712c790a9772075aed2ad.tar.zst
Make a static version of QPDF::pipeStreamData
This is in preparation of being able to pipe a stream's data without keeping a copy of its containing qpdf object.
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r--libqpdf/QPDF.cc63
1 files changed, 44 insertions, 19 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 813775a2..f5267dea 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -2512,34 +2512,40 @@ QPDF::getCompressibleObjGens()
}
bool
-QPDF::pipeStreamData(int objid, int generation,
+QPDF::pipeStreamData(PointerHolder<EncryptionParameters> encp,
+ PointerHolder<InputSource> file,
+ QPDF& qpdf_for_warning,
+ int objid, int generation,
qpdf_offset_t offset, size_t length,
QPDFObjectHandle stream_dict,
+ bool is_attachment_stream,
Pipeline* pipeline,
bool suppress_warnings,
bool will_retry)
{
- bool success = false;
std::vector<PointerHolder<Pipeline> > to_delete;
- if (this->m->encp->encrypted)
+ if (encp->encrypted)
{
- decryptStream(pipeline, objid, generation, stream_dict, to_delete);
+ decryptStream(encp, file, qpdf_for_warning,
+ pipeline, objid, generation,
+ stream_dict, is_attachment_stream, to_delete);
}
+ bool success = false;
try
{
- this->m->file->seek(offset, SEEK_SET);
+ file->seek(offset, SEEK_SET);
char buf[10240];
while (length > 0)
{
size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length);
- size_t len = this->m->file->read(buf, to_read);
+ size_t len = file->read(buf, to_read);
if (len == 0)
{
throw QPDFExc(qpdf_e_damaged_pdf,
- this->m->file->getName(),
- this->m->last_object_description,
- this->m->file->getLastOffset(),
+ file->getName(),
+ "",
+ file->getLastOffset(),
"unexpected EOF reading stream data");
}
length -= len;
@@ -2552,7 +2558,7 @@ QPDF::pipeStreamData(int objid, int generation,
{
if (! suppress_warnings)
{
- warn(e);
+ qpdf_for_warning.warn(e);
}
}
catch (std::exception& e)
@@ -2560,17 +2566,19 @@ QPDF::pipeStreamData(int objid, int generation,
if (! suppress_warnings)
{
QTC::TC("qpdf", "QPDF decoding error warning");
- warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
- "", this->m->file->getLastOffset(),
- "error decoding stream data for object " +
- QUtil::int_to_string(objid) + " " +
- QUtil::int_to_string(generation) + ": " + e.what()));
+ qpdf_for_warning.warn(
+ QPDFExc(qpdf_e_damaged_pdf, file->getName(),
+ "", file->getLastOffset(),
+ "error decoding stream data for object " +
+ QUtil::int_to_string(objid) + " " +
+ QUtil::int_to_string(generation) + ": " + e.what()));
if (will_retry)
{
- warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
- "", this->m->file->getLastOffset(),
- "stream will be re-processed without"
- " filtering to avoid data loss"));
+ qpdf_for_warning.warn(
+ QPDFExc(qpdf_e_damaged_pdf, file->getName(),
+ "", file->getLastOffset(),
+ "stream will be re-processed without"
+ " filtering to avoid data loss"));
}
}
}
@@ -2588,6 +2596,23 @@ QPDF::pipeStreamData(int objid, int generation,
return success;
}
+bool
+QPDF::pipeStreamData(int objid, int generation,
+ qpdf_offset_t offset, size_t length,
+ QPDFObjectHandle stream_dict,
+ Pipeline* pipeline,
+ bool suppress_warnings,
+ bool will_retry)
+{
+ bool is_attachment_stream = this->m->attachment_streams.count(
+ QPDFObjGen(objid, generation));
+ return pipeStreamData(
+ this->m->encp, this->m->file, *this,
+ objid, generation, offset, length,
+ stream_dict, is_attachment_stream,
+ pipeline, suppress_warnings, will_retry);
+}
+
void
QPDF::findAttachmentStreams()
{