ffi: reject detached ArrayBufferViews · nodejs/node@eacd65e · GitHub
Skip to content

Commit eacd65e

Browse files
trivikraduh95
authored andcommitted
ffi: reject detached ArrayBufferViews
Detached ArrayBuffers were rejected with ERR_INVALID_ARG_VALUE, but detached views were not: typed arrays exported zero bytes and DataViews threw a bare TypeError from byteLength. Track detachment in ArrayBufferViewContents::Read() and skip the JS length check for detached buffers, so every detached input is rejected. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #65086 Fixes: #65085 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent be2ab89 commit eacd65e

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

lib/ffi.js

Lines changed: 12 additions & 1 deletion

src/util-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
572572
template <typename T, size_t S>
573573
requires(sizeof(T) == 1)
574574
void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> abv) {
575+
was_detached_ = abv->Buffer()->WasDetached();
575576
length_ = abv->ByteLength();
576577
if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) {
577578
auto buf_data = abv->Buffer()->Data();

test/ffi/test-ffi-memory.js

Lines changed: 17 additions & 0 deletions

0 commit comments

Comments
 (0)