fix: adapt the length prefixed reader to check a length against the data left

The reader the message structs share made room for the length it read,
up to the message limit, before it found that the stream held less.
The length now has to fit in the data the stream has left first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 16:06:49 -06:00
parent 1ba8f26d2b
commit a7b8bfb3ae

View File

@@ -138,6 +138,8 @@ namespace BitStreamUtils {
if (length < 0) return false;
}
if (static_cast<uint64_t>(length) > maxLength) return false;
// The stream can not hold more characters than it has bytes left
if (static_cast<uint64_t>(length) * sizeof(typename StringT::value_type) * 8 > static_cast<uint64_t>(bitStream.GetNumberOfUnreadBits())) return false;
value.resize(length);
if (length == 0) return true;
return bitStream.ReadBits(reinterpret_cast<unsigned char*>(value.data()), BYTES_TO_BITS(value.size() * sizeof(typename StringT::value_type)), true);