Title: ffi: Fast API calls silently truncate out-of-range integer arguments · Issue #64613 · nodejs/node · GitHub
Open Graph Title: ffi: Fast API calls silently truncate out-of-range integer arguments · Issue #64613 · nodejs/node
X Title: ffi: Fast API calls silently truncate out-of-range integer arguments · Issue #64613 · nodejs/node
Description: Version main Platform macOS 26.5.2 Subsystem ffi What steps will reproduce the bug? repro.c #include
Open Graph Description: Version main Platform macOS 26.5.2 Subsystem ffi What steps will reproduce the bug? repro.c #include
X Description: Version main Platform macOS 26.5.2 Subsystem ffi What steps will reproduce the bug? repro.c #include <stdint.h> int8_t i8(int8_t x) { return x; } uint8_t u8(uint8_t x) { return x; } int16_t i...
Opengraph URL: https://github.com/nodejs/node/issues/64613
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: Fast API calls silently truncate out-of-range integer arguments","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nmacOS 26.5.2\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n`repro.c`\n```c\n#include \u003cstdint.h>\n\nint8_t i8(int8_t x) {\n return x;\n}\n\nuint8_t u8(uint8_t x) {\n return x;\n}\n\nint16_t i16(int16_t x) {\n return x;\n}\n\nuint16_t u16(uint16_t x) {\n return x;\n}\n\nint64_t i64(int64_t x) {\n return x;\n}\n```\n\nCompile it by running\n```sh\n$ clang -dynamiclib repro.c -o librepro.dylib\n```\n\n`repro.js`\n```js\nimport { dlopen } from 'node:ffi';\n\nconst { functions } = dlopen(`./librepro.dylib`, {\n i8: { arguments: ['i8'], return: 'i8' },\n u8: { arguments: ['u8'], return: 'u8' },\n i16: { arguments: ['i16'], return: 'i16' },\n u16: { arguments: ['u16'], return: 'u16' },\n i64: { arguments: ['i64'], return: 'i64' },\n});\n\nfunction callI8(x) { return functions.i8(x); }\nfunction callU8(x) { return functions.u8(x); }\nfunction callI16(x) { return functions.i16(x); }\nfunction callU16(x) { return functions.u16(x); }\nfunction callI64(x) { return functions.i64(x); }\n\nfunction optimize(fn, value) {\n eval('%PrepareFunctionForOptimization(fn)');\n fn(value);\n fn(value);\n eval('%OptimizeFunctionOnNextCall(fn)');\n fn(value);\n}\n\nfor (const [fn, value] of [\n [callI8, 0],\n [callU8, 0],\n [callI16, 0],\n [callU16, 0],\n [callI64, 0n],\n]) {\n optimize(fn, value);\n}\n\nconsole.log('i8:', callI8(128));\nconsole.log('u8:', callU8(256));\nconsole.log('i16:', callI16(32768));\nconsole.log('u16:', callU16(65536));\nconsole.log('i64:', callI64(2n ** 63n));\n```\n\nRun it\n```sh\n$ node --no-warnings --experimental-ffi --allow-natives-syntax repro.js\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nEach call should throw `ERR_INVALID_ARG_VALUE`, as the generic FFI path does.\n\n### What do you see instead?\n\n```sh\ni8: -128\nu8: 0\ni16: -32768\nu16: 0\ni64: -9223372036854775808n\n```\n\noptimized FFI calls silently truncate or wrap every out-of-range argument\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-07-20T06:20:19Z","url":"https://github.com/nodejs/node/issues/64613"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:60849112-a2c3-4c17-60f3-f4f87a9abb6c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82BC:1051BB:5BCCE1:7D1F62:6AED5E08 |
| html-safe-nonce | d41ea4b11493d1a5524d1fd3f8c85c6b936ea6d2c417f58ea597a0a86ffff393 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkJDOjEwNTFCQjo1QkNDRTE6N0QxRjYyOjZBRUQ1RTA4IiwidmlzaXRvcl9pZCI6IjI1NjI2ODE3MDMxMjExMTY2ODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1758633dd6bfe49d7784b04e0ea9fe4002bd278729c1578a7ee591cd6463a9d0 |
| hovercard-subject-tag | issue:4926335391 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/64613/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fdfa884b3112c8962cf1fa30928212d7c89fa1e7410f56d1628ff86757fd77b7/nodejs/node/issues/64613 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fdfa884b3112c8962cf1fa30928212d7c89fa1e7410f56d1628ff86757fd77b7/nodejs/node/issues/64613 |
| og:image:alt | Version main Platform macOS 26.5.2 Subsystem ffi What steps will reproduce the bug? repro.c #include |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trivikr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width