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 22, 2024
1 parent 58a1d54 commit 74c3134
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 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,9 @@ 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
out.remove_prefix(source.size());
}
storage_ = std::move(storage);
}
Expand Down

0 comments on commit 74c3134

Please sign in to comment.