diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index cc54db29..8db62d9c 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include #include #include -#include #include #include @@ -980,12 +980,11 @@ QPDF::pipeStreamData( bool attempted_finish = false; try { - file->seek(offset, SEEK_SET); - auto buf = std::make_unique(length); - if (auto read = file->read(buf.get(), length); read != length) { - throw damagedPDF(*file, "", offset + toO(read), "unexpected EOF reading stream data"); + auto buf = file->read(length, offset); + if (buf.size() != length) { + throw damagedPDF(*file, "", offset + toO(buf.size()), "unexpected EOF reading stream data"); } - pipeline->write(buf.get(), length); + pipeline->write(buf.data(), length); attempted_finish = true; pipeline->finish(); return true;