From 349f72288ace1b99e35ad11772e348daa6ba98f8 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 29 Jul 2025 06:47:25 -0700 Subject: [PATCH] src: warn about FastOneByteString invalidation Minor warning about the use of FastOneByteString. --- src/node_buffer.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 2fff0488cd81cd..836f93697a2609 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1526,6 +1526,14 @@ uint32_t FastWriteString(Local receiver, uint32_t max_length, // NOLINTNEXTLINE(runtime/references) FastApiCallbackOptions& options) { + // Just a heads up... this is a v8 fast api function. The use of + // FastOneByteString has some caveats. Specifically, a GC occurring + // between the time the FastOneByteString is created and the time + // we use it below can cause the FastOneByteString to become invalid + // and produce garbage data. This is not a problem here because we + // are not performing any allocations or other operations that would + // trigger a GC before the FastOneByteString is used. Take care when + // modifying this code to ensure that no operations would trigger a GC. HandleScope handle_scope(options.isolate); SPREAD_BUFFER_ARG(dst_obj, dst); CHECK(offset <= dst_length);