Skip to content

ffi: buffer/arraybuffer args reject BigInt pointers in multi-argument fast signatures #64963

Description

@trivikr

Version

main

Platform

Linux

Subsystem

ffi

What steps will reproduce the bug?

repro.c

#include <stdint.h>

uint64_t ptr_one(void *p) { return (uint64_t)(uintptr_t)p; }
uint64_t ptr_two(void *p, uint64_t extra) { return (uint64_t)(uintptr_t)p + extra; }

Compile it with

$ cc -shared -fPIC -o repro.so repro.c

repro.js

import { dlopen } from 'node:ffi';

const { lib, functions } = dlopen(new URL('repro.so', import.meta.url).pathname, {
  ptr_one: { arguments: ['buffer'], return: 'u64' },
  ptr_two: { arguments: ['buffer', 'u64'], return: 'u64' },
});

for (const [label, call] of [
  ['1-arg buffer(10n)    ', () => functions.ptr_one(10n)],
  ['2-arg buffer(10n, 0n)', () => functions.ptr_two(10n, 0n)],
]) {
  try {
    console.log(label, '->', call());
  } catch (err) {
    console.log(label, '-> THREW', err.code, '-', err.message);
  }
}

lib.close();

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

Always

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

1-arg buffer(10n)     -> 10n
2-arg buffer(10n, 0n) -> 10n

Expected both to return 10n, matching the SB/libffi paths which accept BigInt pointers at every arity; if rejection were intended it should be ERR_INVALID_ARG_VALUE with an Argument N prefix like the rest of the module.

What do you see instead?

1-arg buffer(10n)     -> 10n
2-arg buffer(10n, 0n) -> THREW ERR_INVALID_ARG_TYPE - The first argument must be a Buffer, ArrayBuffer, or ArrayBufferView

The one-argument signature returns 10n while the identical buffer type in a two-argument signature throws ERR_INVALID_ARG_TYPE.

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