Title: ffi: setFloat32()/setFloat64() coerce their value and discard a pending exception · Issue #65341 · nodejs/node · GitHub
Open Graph Title: ffi: setFloat32()/setFloat64() coerce their value and discard a pending exception · Issue #65341 · nodejs/node
X Title: ffi: setFloat32()/setFloat64() coerce their value and discard a pending exception · Issue #65341 · nodejs/node
Description: Version main (ad7a5b8) 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 (ad7a5b8) 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 (ad7a5b8) 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/65341
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: setFloat32()/setFloat64() coerce their value and discard a pending exception","articleBody":"### Version\n\nmain (ad7a5b8302ae54b6e6dc77e03eabc5a3218dfb85)\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 { getRawPointer, setFloat64, getFloat64 } = require('node:ffi');\n\nconst ptr = getRawPointer(Buffer.alloc(8));\n\nfor (const value of ['1.5', true, {}, null]) {\n setFloat64(ptr, 0, value);\n console.log(`setFloat64(${String(value)}) ->`, getFloat64(ptr, 0));\n}\n\ntry {\n setFloat64(ptr, 0, { valueOf() { throw new RangeError('boom'); } });\n} catch (err) {\n console.log('valueOf threw ->', err.name, err.message);\n}\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways. `setFloat32()` behaves the same way.\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`setFloat32()` and `setFloat64()` should reject a value that is not a `number`, like every other setter in the module, and they should not replace an exception the value itself threw.\n\nThe same `double` is type-checked on the argument path, where `ToFFIArgument()` requires `IsNumber()` and throws `Argument %s must be a double`, and the documentation says the setters \"validate the supplied JavaScript value against the target native type before writing it into memory\".\n\n### What do you see instead?\n\n```text\nsetFloat64(1.5) -> 1.5\nsetFloat64(true) -> 1\nsetFloat64([object Object]) -> NaN\nsetFloat64(null) -> 0\nvalueOf threw -> TypeError Value must be a number\n```\n\nThe integer branches of `SetValue\u003cT>()` require `IsNumber()` before any range check, but the floating-point branch calls `ToNumber()` and casts the result. When `ToNumber()` itself fails, the `ERR_INVALID_ARG_VALUE` overwrites the exception it left pending, so the `RangeError` never reaches the caller. `DataView.prototype.setFloat64()` and `Buffer.prototype.writeDoubleLE()` both propagate it.\n\nhttps://github.com/nodejs/node/blob/ad7a5b8302ae54b6e6dc77e03eabc5a3218dfb85/src/ffi/data.cc#L402-L411\n\n### Additional information\n\nThe setters write straight into native memory, so a `'1,5'` typo from a config file stores `NaN` in a struct field with no error at the call site. `setInt32()` throws on the same mistake.\n\n`DataView` and `Buffer` coerce here too, but they coerce for integers as well (`dv.setInt8(0, 300)` writes `44`), while `node:ffi` rejects those.\n\nThe integer validation, the float coercion and the documentation sentence all landed together in d0fa608c079, the floating-point branch has not been modified since, and I found no review comment about the difference in the pull requests that touched it.\n\nRefs: https://github.com/nodejs/node/pull/62072\nRefs: https://github.com/nodejs/node/pull/62762\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-17T00:27:49Z","url":"https://github.com/nodejs/node/issues/65341"}
| 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:f73006f8-019d-dc90-594f-3d88bedd51b7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8250:12D2BD:4E8D1B:6A8DD0:6AED1C0F |
| html-safe-nonce | e4ffeb71d644ff784271089adbac5eafcf263010bbfc42bbe3fbb9226192978c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjUwOjEyRDJCRDo0RThEMUI6NkE4REQwOjZBRUQxQzBGIiwidmlzaXRvcl9pZCI6IjU2NjE2NzkwMTE1MzY2NDEwNDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 85c907699ca50455f1dcbb056a60641f89c1d2318b04a6f6bbc9bad2cdcc97b2 |
| hovercard-subject-tag | issue:5167119249 |
| 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/65341/issue_layout |
| twitter:image | https://opengraph.githubassets.com/09b8fc0ff182c0c2db533fb143f2cb997b52295e495b715fbba55f81a433d168/nodejs/node/issues/65341 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/09b8fc0ff182c0c2db533fb143f2cb997b52295e495b715fbba55f81a433d168/nodejs/node/issues/65341 |
| og:image:alt | Version main (ad7a5b8) 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 | 120085d0bcec1f427e3ab45302c8b95f873d26ad21984dc86d62ab2c10158f41 |
| 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 | e12fd03aa775dceadc5a793c3a0791e43ca256bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width