Harden array allocation in BitSet::deserialize()

Move bounds check to before the allocation.
Treat NULL bitset values as empty to avoid overflow.

Add tests for excessive allocation, and Null values.
This commit is contained in:
Andrew Johnson authored and Michael Davidsaver committed 2026-08-09 17:49:39 -07:00
1 parent abc95982ed
commit 5012ff95b2
2 files changed
+47 -7

No files matched your search

+4 -6
View File
@@ -337,17 +337,15 @@ namespace epics { namespace pvData {
}
void BitSet::deserialize(ByteBuffer* buffer, DeserializableControl* control) {
size_t size = SerializeHelper::readSize(buffer, control);
uint32 bytes = (size == (size_t) -1) ? 0 : static_cast<uint32>(size);
uint32 bytes = static_cast<uint32>(SerializeHelper::readSize(buffer, control)); // in bytes
// Validate availability before allocating storage
control->ensureData(bytes);
size_t wordsInUse = (bytes + 7) / BYTES_PER_WORD;
words.resize(wordsInUse);
if (wordsInUse == 0)
return;
control->ensureData(bytes);
uint32 i = 0;
uint32 longs = bytes / 8;
while (i < longs)