ffi: reject direct SharedArrayBuffer pointers · nodejs/node@537feec · GitHub
Skip to content

Commit 537feec

Browse files
trivikraduh95
authored andcommitted
ffi: reject direct SharedArrayBuffer pointers
Reject direct SharedArrayBuffer pointer arguments in the JavaScript wrapper and native fast-buffer helper. This keeps validation behavior consistent before and after optimization. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #65233 Fixes: #65232 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 43757d0 commit 537feec

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

lib/internal/ffi/fast-api.js

Lines changed: 2 additions & 3 deletions

src/ffi/fast.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
248248
constexpr uintptr_t kInvalidBuffer = std::numeric_limits<uintptr_t>::max();
249249
v8::Isolate* isolate = options != nullptr ? options->isolate : nullptr;
250250

251-
// Accept only memory-backed JS values in the native helper. Other pointer
252-
// conversions, including strings, stay in the JS wrapper so their temporary
253-
// lifetime is explicit.
251+
// Accept only the memory-backed JS values supported by ToFFIArgument in the
252+
// native helper. Other pointer conversions, including strings and direct
253+
// SharedArrayBuffers, stay in the JS wrapper so validation and temporary
254+
// lifetimes match the generic path.
254255
if (value->IsArrayBufferView()) {
255256
v8::Local<v8::ArrayBufferView> view = value.As<v8::ArrayBufferView>();
256257
if (view->Buffer()->WasDetached()) {
@@ -281,9 +282,6 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
281282
}
282283
return PointerFromValue(value);
283284
}
284-
if (value->IsSharedArrayBuffer()) {
285-
return PointerFromValue(value);
286-
}
287285

288286
if (isolate != nullptr) {
289287
// No HandleScope is active during a Fast API call, so open one before

test/ffi/test-ffi-fast-buffer.js

Lines changed: 30 additions & 1 deletion

0 commit comments

Comments
 (0)