Version
main
Platform
Subsystem
ffi
What steps will reproduce the bug?
repro.c
void*destination(void) {
staticunsigned charbyte;
return&byte;
}repro.js
import{dlopen,suffix,exportArrayBuffer,exportArrayBufferView}from'node:ffi';const{ lib, functions }=dlopen(`./repro.${suffix}`,{destination: {arguments: [],return: 'pointer'},});constpointer=functions.destination();functiondetached(makeValue){constbuffer=newArrayBuffer(1);constvalue=makeValue(buffer);structuredClone(buffer,{transfer: [buffer]});returnvalue;}functionrun(name,fn){try{fn();console.log(`${name}: accepted`);}catch(error){console.log(`${name}: ${error.code??error.name}: ${error.message}`);}}run('ArrayBuffer',()=>{exportArrayBuffer(detached((buffer)=>buffer),pointer,1);});run('Uint8Array',()=>{exportArrayBufferView(detached((buffer)=>newUint8Array(buffer)),pointer,1,);});run('DataView',()=>{exportArrayBufferView(detached((buffer)=>newDataView(buffer)),pointer,1,);});lib.close();Commands to run:
$ cc -dynamiclib -o repro.dylib repro.c
$ node --no-warnings --experimental-ffi repro.js
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
All detached inputs should be rejected consistently, preferably with Node.js’s ERR_INVALID_ARG_VALUE.
What do you see instead?
ArrayBuffer: ERR_INVALID_ARG_VALUE: ArrayBuffer is detachedUint8Array: acceptedDataView: TypeError: Cannot perform get DataView.prototype.byteLength on a detached or out-of-bounds ArrayBuffer
A detached ArrayBuffer produces ERR_INVALID_ARG_VALUE, a detached Uint8Array is accepted, and a detached DataView produces a V8 TypeError
Additional information
Noticed while working on #65082
Version
main
Platform
Subsystem
ffi
What steps will reproduce the bug?
repro.crepro.jsCommands to run:
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
All detached inputs should be rejected consistently, preferably with Node.js’s
ERR_INVALID_ARG_VALUE.What do you see instead?
A detached
ArrayBufferproducesERR_INVALID_ARG_VALUE, a detachedUint8Arrayis accepted, and a detachedDataViewproduces a V8TypeErrorAdditional information
Noticed while working on #65082