Commit 051ae7c282b5487a0dfb5214b9855cd45066c813

Authored by Jay Berkenbilt
1 parent 60ec94a7

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.
Showing 1 changed file with 3 additions and 1 deletions
libqpdf/QPDFObjectHandle.cc
... ... @@ -1468,7 +1468,9 @@ QPDFObjectHandle::replaceStreamData(
1468 1468 assertStream();
1469 1469 auto b = std::make_shared<Buffer>(data.length());
1470 1470 unsigned char* bp = b->getBuffer();
1471   - memcpy(bp, data.c_str(), data.length());
  1471 + if (bp) {
  1472 + memcpy(bp, data.c_str(), data.length());
  1473 + }
1472 1474 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1473 1475 b, filter, decode_parms);
1474 1476 }
... ...