2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-31 17:30:54 +00:00

In QPDF::pipeStreamData read buffer in a single read

This commit is contained in:
m-holger 2023-11-18 13:11:12 +00:00
parent 9f7f9496ed
commit 0dee397075

View File

@ -2419,23 +2419,17 @@ QPDF::pipeStreamData(
} }
bool attempted_finish = false; bool attempted_finish = false;
bool success = false;
try { try {
file->seek(offset, SEEK_SET); file->seek(offset, SEEK_SET);
char buf[10240]; auto buf = std::make_unique<char[]>(length);
while (length > 0) { if (auto read = file->read(buf.get(), length); read != length) {
size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length); throw damagedPDF(
size_t len = file->read(buf, to_read); file, "", offset + toO(read), "unexpected EOF reading stream data");
if (len == 0) {
throw damagedPDF(
file, "", file->getLastOffset(), "unexpected EOF reading stream data");
}
length -= len;
pipeline->write(buf, len);
} }
pipeline->write(buf.get(), length);
attempted_finish = true; attempted_finish = true;
pipeline->finish(); pipeline->finish();
success = true; return true;
} catch (QPDFExc& e) { } catch (QPDFExc& e) {
if (!suppress_warnings) { if (!suppress_warnings) {
qpdf_for_warning.warn(e); qpdf_for_warning.warn(e);
@ -2458,8 +2452,7 @@ QPDF::pipeStreamData(
file, file,
"", "",
file->getLastOffset(), file->getLastOffset(),
"stream will be re-processed without" "stream will be re-processed without filtering to avoid data loss"));
" filtering to avoid data loss"));
} }
} }
} }
@ -2470,7 +2463,7 @@ QPDF::pipeStreamData(
// ignore // ignore
} }
} }
return success; return false ;
} }
bool bool