Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: properly apply dst offset and src length on fast path #54391

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1479,11 +1479,12 @@ uint32_t FastWriteString(Local<Value> receiver,
CHECK(offset <= dst.length());
CHECK(dst.length() - offset <= std::numeric_limits<uint32_t>::max());

max_length = std::min<uint32_t>(dst.length() - offset, max_length);
const auto size = std::min(
{static_cast<uint32_t>(dst.length() - offset), max_length, src.length});

memcpy(dst_data, src.data, max_length);
memcpy(dst_data + offset, src.data, size);

return max_length;
return size;
}

static v8::CFunction fast_write_string(v8::CFunction::Make(FastWriteString));
Expand Down
Loading