Skip to content

Commit

Permalink
Fix memcpy in byte_slice constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
vtnerd committed Nov 21, 2024
1 parent 58a1d54 commit b42f571
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contrib/epee/src/byte_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ namespace epee
{
std::size_t space_needed = 0;
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();
}

if (space_needed)
{
Expand All @@ -162,9 +166,8 @@ namespace epee

for (const auto& source : sources)
{
assert(source.size() <= out.size()); // see check above
std::memcpy(out.data(), source.data(), source.size());
if (out.remove_prefix(source.size()) < source.size())
throw std::bad_alloc{}; // size_t overflow on space_needed
}
storage_ = std::move(storage);
}
Expand Down

0 comments on commit b42f571

Please sign in to comment.