Title: ffi: memory helpers return undefined instead of throwing when a required argument is omitted · Issue #65499 · nodejs/node · GitHub
Open Graph Title: ffi: memory helpers return undefined instead of throwing when a required argument is omitted · Issue #65499 · nodejs/node
X Title: ffi: memory helpers return undefined instead of throwing when a required argument is omitted · Issue #65499 · nodejs/node
Description: Version main (a48e33f) Platform Darwin 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64 Subsystem ffi What steps will reproduce the bug? // node --experimental-ffi repro....
Open Graph Description: Version main (a48e33f) Platform Darwin 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64 Subsystem ffi What steps will reproduce th...
X Description: Version main (a48e33f) Platform Darwin 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64 Subsystem ffi What steps will reproduce th...
Opengraph URL: https://github.com/nodejs/node/issues/65499
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: memory helpers return undefined instead of throwing when a required argument is omitted","articleBody":"### Version\n\nmain (a48e33fb6f8e48be856da69692a17bc19a39317a)\n\n### Platform\n\n```text\nDarwin 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n```js\n// node --experimental-ffi repro.js\nconst ffi = require('node:ffi');\n\nconsole.log(ffi.getUint8()); // pointer omitted\nconsole.log(ffi.setUint8()); // pointer omitted\nconsole.log(ffi.toBuffer(1n)); // length omitted\n\n// The same arguments, passed explicitly.\ntry { ffi.getUint8(undefined); } catch (err) { console.log(err.message); }\ntry { ffi.toBuffer(1n, undefined); } catch (err) { console.log(err.message); }\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways. All 22 helpers behave the same way: the ten getters, the ten setters, `toBuffer()` and `toArrayBuffer()`.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nOmitting a required argument should throw, like passing it explicitly as `undefined` already does.\n\nThe documented signatures are `ffi.getInt8(pointer[, offset])`, `ffi.setInt8(pointer, offset, value)` and `ffi.toBuffer(pointer, length[, copy])`, and the getters are documented to return a `number` or a `bigint`. The helpers are inconsistent among themselves too: `setUint8(ptr)` throws `Expected an offset argument`, so only a missing first argument goes unreported.\n\n### What do you see instead?\n\n```text\nundefined\nundefined\nundefined\nThe pointer must be a bigint\nThe length must be a number\n```\n\n`GetValidatedPointerAddress()` and `GetValidatedSize()` already reject `undefined`. The `args.Length()` test in front of them short-circuits the call and returns `Nothing` without scheduling an exception:\n\nhttps://github.com/nodejs/node/blob/a48e33fb6f8e48be856da69692a17bc19a39317a/src/ffi/data.cc#L163-L169\n\nThe same shape guards the setters (`L207`), the length of `ToBuffer()` (`L559`) and of `ToArrayBuffer()` (`L621`), and both arguments of `ExportBytes()` (`L697`, `L703`).\n\n### Additional information\n\nThese are raw memory helpers, so the silent `undefined` is easy to miss: `if (ffi.getUint8(ptr))` written with the pointer left out is falsy exactly like a zero byte, and `ffi.setUint8()` reports success for a write that never happened.\n\nThe tests do not look deliberate. `FunctionCallbackInfo::operator[]` returns `Undefined` for an out-of-range index, which is exactly the value these validators reject, and these six are the only tests in `src/` where `args.Length()` can skip a call that throws (the only other `Length()` tests that guard a call at all guard `Buffer::HasInstance()`, which cannot throw). They arrived with the module in d0fa608c079 and survived fe41105dddc (#62858), which reworked the surrounding error handling; I found no mention of argument count in the reviews of #62072, #62762 or #62858.\n\nRefs: https://github.com/nodejs/node/pull/62072\nRefs: https://github.com/nodejs/node/pull/62858\nRefs: https://github.com/nodejs/node/pull/65342\n","author":{"url":"https://github.com/soulee-dev","@type":"Person","name":"soulee-dev"},"datePublished":"2026-08-23T07:19:23Z","url":"https://github.com/nodejs/node/issues/65499"}
| 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:e8065be2-f79a-05c2-ed5f-98e7970d1300 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E9C:169E62:85D338:AD92AC:6AED3550 |
| html-safe-nonce | 630fed1ab9bb01a31411ee30fd6eecc28af1cecb6e29c35089e1d05141d025e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTlDOjE2OUU2Mjo4NUQzMzg6QUQ5MkFDOjZBRUQzNTUwIiwidmlzaXRvcl9pZCI6IjcwNzQwMzU4MTIzNDAxNTE2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7eda7394e6dcf08fac3e80c160e3f823bd3a600eae3eb2420f2784c6e1739e27 |
| hovercard-subject-tag | issue:5225813193 |
| 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/65499/issue_layout |
| twitter:image | https://opengraph.githubassets.com/080e8718d635fd959e4b4ff15818d1e3b649ca59bab2e2463b6465692794cf83/nodejs/node/issues/65499 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/080e8718d635fd959e4b4ff15818d1e3b649ca59bab2e2463b6465692794cf83/nodejs/node/issues/65499 |
| og:image:alt | Version main (a48e33f) Platform Darwin 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64 Subsystem ffi What steps will reproduce th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | soulee-dev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26c92a9388ddfad3fa88d132b5d5f0b4747030233dcc4e5efb05f1cbae152184 |
| 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 | c629ad99c254d306375fc8354d04321c2c362236 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width