diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2023-12-16 17:31:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-16 17:31:11 +0100 |
commit | b0b6d9f21fe77fb7b46469529bf252f0dbcaa551 (patch) | |
tree | 612562863dbf4364e41e2086b701b92761c18e72 /libqpdf/QPDF.cc | |
parent | d7a364b882be44c93dc4a843bcca2ae63e805c2c (diff) | |
parent | 368666899fe24885fbe05ea03688fa985645ebd9 (diff) | |
download | qpdf-b0b6d9f21fe77fb7b46469529bf252f0dbcaa551.tar.zst |
Merge pull request #1067 from m-holger/pl_buff
Reduce copying of Buffer contents
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r-- | libqpdf/QPDF.cc | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 473cf5f0..f6badc35 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2413,29 +2413,23 @@ QPDF::pipeStreamData( bool suppress_warnings, bool will_retry) { - std::vector<std::shared_ptr<Pipeline>> to_delete; + std::unique_ptr<Pipeline> to_delete; if (encp->encrypted) { decryptStream(encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete); } bool attempted_finish = false; - bool success = false; try { file->seek(offset, SEEK_SET); - char buf[10240]; - while (length > 0) { - size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length); - size_t len = file->read(buf, to_read); - if (len == 0) { - throw damagedPDF( - file, "", file->getLastOffset(), "unexpected EOF reading stream data"); - } - length -= len; - pipeline->write(buf, len); + auto buf = std::make_unique<char[]>(length); + if (auto read = file->read(buf.get(), length); read != length) { + throw damagedPDF( + file, "", offset + toO(read), "unexpected EOF reading stream data"); } + pipeline->write(buf.get(), length); attempted_finish = true; pipeline->finish(); - success = true; + return true; } catch (QPDFExc& e) { if (!suppress_warnings) { qpdf_for_warning.warn(e); @@ -2458,8 +2452,7 @@ QPDF::pipeStreamData( file, "", file->getLastOffset(), - "stream will be re-processed without" - " filtering to avoid data loss")); + "stream will be re-processed without filtering to avoid data loss")); } } } @@ -2470,7 +2463,7 @@ QPDF::pipeStreamData( // ignore } } - return success; + return false ; } bool |