diff options
author | m-holger <m-holger@kubitscheck.org> | 2023-11-18 14:11:12 +0100 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2023-11-26 13:26:57 +0100 |
commit | 0dee39707583b300bc745c923452a848d0f02c88 (patch) | |
tree | 68cd4f8cb5dc87bc0d363ac5cbe5dad01e390476 | |
parent | 9f7f9496ed26a5490b9f2b847806282cd1ae1146 (diff) | |
download | qpdf-0dee39707583b300bc745c923452a848d0f02c88.tar.zst |
In QPDF::pipeStreamData read buffer in a single read
-rw-r--r-- | libqpdf/QPDF.cc | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 473cf5f0..01f1f339 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2419,23 +2419,17 @@ QPDF::pipeStreamData( } 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 |