mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-14 07:47:13 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user