Skip to content

Commit 9bd11e0

Browse files
fm4vclaude
andcommitted
fix: guard memcpy against null _ptr in Poco::Buffer::setCapacity
When a Buffer is default-constructed (_ptr = nullptr, _used = 0), calling setCapacity with newCapacity > 0 and preserveContent = true computes newSz = 0 and then calls memcpy(dst, nullptr, 0). Passing a null pointer to memcpy is undefined behaviour even when size is 0 (the nonnull attribute on argument 2 applies regardless of size). UBSan correctly flags this and with abort_on_error=1 the ClickHouse server process aborts during Poco::CompressedLogFile construction before binding port 9000, causing integration tests to time out. Fix: skip the memcpy when newSz == 0. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
1 parent afcfb5e commit 9bd11e0

File tree

1 file changed

+2
-1
lines changed
  • base/poco/Foundation/include/Poco

1 file changed

+2
-1
lines changed

base/poco/Foundation/include/Poco/Buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class Buffer
155155
if (preserveContent)
156156
{
157157
std::size_t newSz = _used < newCapacity ? _used : newCapacity;
158-
std::memcpy(ptr, _ptr, newSz * sizeof(T));
158+
if (newSz > 0)
159+
std::memcpy(ptr, _ptr, newSz * sizeof(T));
159160
}
160161
}
161162
delete[] _ptr;

0 commit comments

Comments
 (0)