Skip to content

Commit

Permalink
Merge pull request #9584
Browse files Browse the repository at this point in the history
74c3134 Fix memcpy in byte_slice constructor (Lee *!* Clagett)
  • Loading branch information
luigi1111 committed Dec 23, 2024
2 parents 3cbcd4f + 74c3134 commit e2fcb91
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 e2fcb91

Please sign in to comment.