From fbbb0ee0167a9013c3a712c790a9772075aed2ad Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 6 Jan 2019 10:34:52 -0500 Subject: 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. --- libqpdf/QPDF.cc | 63 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'libqpdf/QPDF.cc') 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 encp, + PointerHolder 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 > 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() { -- cgit v1.2.3-54-g00ecf