diff --git a/dNet/BitStreamUtils.h b/dNet/BitStreamUtils.h index 620b200e9..5f6eba968 100644 --- a/dNet/BitStreamUtils.h +++ b/dNet/BitStreamUtils.h @@ -138,6 +138,8 @@ namespace BitStreamUtils { if (length < 0) return false; } if (static_cast(length) > maxLength) return false; + // The stream can not hold more characters than it has bytes left + if (static_cast(length) * sizeof(typename StringT::value_type) * 8 > static_cast(bitStream.GetNumberOfUnreadBits())) return false; value.resize(length); if (length == 0) return true; return bitStream.ReadBits(reinterpret_cast(value.data()), BYTES_TO_BITS(value.size() * sizeof(typename StringT::value_type)), true);