Skip to content

ffi: DynamicLibrary getters crash on incompatible receivers #65287

Description

@trivikr

Version

main

Platform

macOS 26.6.1

Subsystem

ffi

What steps will reproduce the bug?

repro.c

#include <stdint.h>

int add(int a, int b) {
  return a + b;
}

repro.js

import { DynamicLibrary, suffix } from 'node:ffi';

const name = process.argv[2] || 'path';
const lib = new DynamicLibrary(`./repro.${suffix}`);

const owner = name === 'functions' ? DynamicLibrary.prototype : lib;
const getter = Object.getOwnPropertyDescriptor(owner, name).get;

getter.call({});

Commands to run:

cc -dynamiclib repro.c -o repro.dylib

node --experimental-ffi repro.js path
node --experimental-ffi repro.js symbols
node --experimental-ffi repro.js functions

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

It should instead throw a JavaScript TypeError, such as “Illegal invocation” or “Invalid receiver,” without terminating the process.

What do you see instead?

Each extracted getter crashes the Node.js process when called with an incompatible receiver, with either segmentation fault or bus error

Additional information

No response

Metadata

Metadata

Assignees

Labels

ffiIssues and PRs related to experimental Foreign Function Interface support.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions