- added some safety checks for reading empty lumps into a std::vector.

These can trip the internal safety checks, even though nothing gets read in.
This commit is contained in:
Christoph Oelckers 2023-08-22 22:59:29 +02:00
parent 42283f56ab
commit 5a1b858c0e

View file

@ -194,8 +194,11 @@ public:
std::vector<uint8_t> Read(size_t len) std::vector<uint8_t> Read(size_t len)
{ {
std::vector<uint8_t> buffer(len); std::vector<uint8_t> buffer(len);
Size length = mReader->Read(&buffer[0], (long)len); if (len > 0)
buffer.resize((size_t)length); {
Size length = mReader->Read(&buffer[0], (long)len);
buffer.resize((size_t)length);
}
return buffer; return buffer;
} }
@ -208,9 +211,13 @@ public:
{ {
auto len = GetLength(); auto len = GetLength();
std::vector<uint8_t> buffer(len + padding); std::vector<uint8_t> buffer(len + padding);
Size length = mReader->Read(&buffer[0], (long)len); if (len > 0)
if (length < len) buffer.clear(); {
else memset(buffer.data() + len, 0, padding); Size length = mReader->Read(&buffer[0], (long)len);
if (length < len) buffer.clear();
else memset(buffer.data() + len, 0, padding);
}
else buffer[0] = 0;
return buffer; return buffer;
} }