From ea45c6c841edff4d3db6c532217f9851678c29c7 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 15 Aug 2024 08:17:05 +0200 Subject: [PATCH] buffer: properly apply offset on fast path Refs: https://github.com/nodejs/node/pull/54311#issuecomment-2290453437 PR-URL: https://github.com/nodejs/node/pull/54391 --- src/node_buffer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 0e1881eeb5f16d..9e7b634720f2bb 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1479,9 +1479,10 @@ uint32_t FastWriteString(Local receiver, CHECK(offset <= dst.length()); CHECK(dst.length() - offset <= std::numeric_limits::max()); - max_length = std::min(dst.length() - offset, max_length); + const auto size = std::min( + {static_cast(dst.length() - offset), max_length, src.length}); - memcpy(dst_data, src.data, max_length); + memcpy(dst_data + offset, src.data, size); return max_length; }