aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFObjectHandle.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-16 17:07:26 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-16 19:39:26 +0200
commit051ae7c282b5487a0dfb5214b9855cd45066c813 (patch)
tree11b601cc6534d1337654283eedad078fa946aa23 /libqpdf/QPDFObjectHandle.cc
parent60ec94a7c35ff3f7153c99deff29afef91500622 (diff)
downloadqpdf-051ae7c282b5487a0dfb5214b9855cd45066c813.tar.zst
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.
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r--libqpdf/QPDFObjectHandle.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 10fb153c..4a61f595 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -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);
}