Skip to content

ffi: getFunctions() can return a wrapper with the wrong signature if a signature getter requests an earlier symbol #67192

Open

Description

@trivikr

Version

main

Platform

macOS

Subsystem

ffi

What steps will reproduce the bug?

import { DynamicLibrary } from 'node:ffi';
import { strictEqual } from 'node:assert';

const lib = new DynamicLibrary(null); // Symbols already loaded in the process.
let conflicting;
const { abs } = lib.getFunctions({
  abs: { arguments: ['i32'], return: 'i32' },
  get labs() {
    conflicting = lib.getFunction('abs', { arguments: ['f64'], return: 'f64' });
    return { arguments: ['i64'], return: 'i64' };
  },
});

console.log('same wrapper:', abs === conflicting);
console.log('abs(-5):', abs(-5));
strictEqual(abs(-5), 5);

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

Always

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

getFunctions() should throw ERR_INVALID_ARG_VALUE ("Function abs was already requested with a different signature"), so neither console.log nor the assert should run. The assert is only reached because of the bug.

What do you see instead?

same wrapper: true
abs(-5): -5
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

-5 !== 5

Additional information

No response

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    ffiIssues and PRs related to experimental Foreign Function Interface support.
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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