Fix bytebuffer

This commit is contained in:
Maurice Heumann 2023-04-04 18:23:10 +02:00
parent 27ab6193e5
commit 077167e81b
2 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,6 @@
#include "byte_buffer.hpp" #include "byte_buffer.hpp"
#include <cstring> #include <cstring>
#include <stdexcept>
namespace utils namespace utils
{ {

View File

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdexcept>
namespace utils namespace utils
{ {
@ -73,8 +74,13 @@ namespace utils
std::vector<T> read_vector() std::vector<T> read_vector()
{ {
std::vector<T> result{}; std::vector<T> result{};
result.resize(read<uint32_t>()); const auto size = read<uint32_t>();
read(result.data(), result.size() * sizeof(T)); if (offset_ + size > buffer_.size())
{
throw std::runtime_error("Out of bounds read from byte buffer");
}
read(result.data(), size);
return result; return result;
} }