2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-01 01:40:51 +00:00

Improve handling of replacing stream data with empty strings

When an empty string was passed to replaceStreamData, the code was
passing a null pointer to memcpy. Since a 0 size was also passed, this
was harmless, but it triggers sanitizer errors. The code properly
handles a null pointer as the buffer in other places.
This commit is contained in:
Jay Berkenbilt 2022-05-16 11:07:26 -04:00
parent 60ec94a7c3
commit 051ae7c282

View File

@ -1468,7 +1468,9 @@ QPDFObjectHandle::replaceStreamData(
assertStream();
auto b = std::make_shared<Buffer>(data.length());
unsigned char* bp = b->getBuffer();
memcpy(bp, data.c_str(), data.length());
if (bp) {
memcpy(bp, data.c_str(), data.length());
}
dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
b, filter, decode_parms);
}