Fix memcpy in byte_slice constructor

This commit is contained in:
Lee *!* Clagett 2024-11-19 18:51:52 -05:00
parent 893916ad09
commit 92de47fd37

View File

@ -152,7 +152,11 @@ namespace epee
{ {
std::size_t space_needed = 0; std::size_t space_needed = 0;
for (const auto& source : sources) for (const auto& source : sources)
{
if (std::numeric_limits<std::size_t>::max() - space_needed < source.size())
throw std::bad_alloc{};
space_needed += source.size(); space_needed += source.size();
}
if (space_needed) if (space_needed)
{ {
@ -162,9 +166,9 @@ namespace epee
for (const auto& source : sources) for (const auto& source : sources)
{ {
assert(source.size() <= out.size()); // see check above
std::memcpy(out.data(), source.data(), source.size()); std::memcpy(out.data(), source.data(), source.size());
if (out.remove_prefix(source.size()) < source.size()) out.remove_prefix(source.size());
throw std::bad_alloc{}; // size_t overflow on space_needed
} }
storage_ = std::move(storage); storage_ = std::move(storage);
} }