Skip to content

ffi: optimized calls skip BigInt range validation for pointer arguments #66370

Description

@trivikr

Version

main

Platform

macOS

Subsystem

ffi

What steps will reproduce the bug?

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

const lib = new DynamicLibrary(
  `test/ffi/fixture_library/build/Release/ffi_test_library.${suffix}`);

const fn = lib.getFunction('pointer_to_usize', {
  arguments: ['pointer', 'pointer'],
  return: 'u64',
});
function call(p) { return fn(p, 0n); }

const run = (label) => {
  for (const v of [-1n, 2n ** 64n + 5n]) {
    try { console.log(label, v, call(v)); } catch (e) { console.log(label, v, e.code); }
  }
};

run('cold');
%PrepareFunctionForOptimization(call);
call(1n);
%OptimizeFunctionOnNextCall(call);
call(1n);
run('optimized');

Run with

node --allow-natives-syntax repro.js

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

Always

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

Both calls throw ERR_INVALID_ARG_VALUE in both the cold and optimized runs.

What do you see instead?

cold -1n ERR_INVALID_ARG_VALUE
cold 18446744073709551621n ERR_INVALID_ARG_VALUE
optimized -1n 18446744073709551615n
optimized 18446744073709551621n 5n

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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