From 74c313420c1d22c5c8eecb8430fd5fe7a89143d7 Mon Sep 17 00:00:00 2001 From: Lee *!* Clagett Date: Tue, 19 Nov 2024 18:51:52 -0500 Subject: [PATCH] Fix memcpy in byte_slice constructor --- contrib/epee/src/byte_slice.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp index 72aa397684..47d440dff6 100644 --- a/contrib/epee/src/byte_slice.cpp +++ b/contrib/epee/src/byte_slice.cpp @@ -152,7 +152,11 @@ namespace epee { std::size_t space_needed = 0; for (const auto& source : sources) + { + if (std::numeric_limits::max() - space_needed < source.size()) + throw std::bad_alloc{}; space_needed += source.size(); + } if (space_needed) { @@ -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); }