Title: ffi: exportArrayBufferView() inconsistently handles detached views · Issue #65085 · nodejs/node · GitHub
Open Graph Title: ffi: exportArrayBufferView() inconsistently handles detached views · Issue #65085 · nodejs/node
X Title: ffi: exportArrayBufferView() inconsistently handles detached views · Issue #65085 · nodejs/node
Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c void* destination(void) { static unsigned char byte; return &byte; } repro.js import { dlopen, suffix, exportArrayBuffer, exportArrayBufferView }...
Open Graph Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c void* destination(void) { static unsigned char byte; return &byte; } repro.js import { dlopen, suffix, ex...
X Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c void* destination(void) { static unsigned char byte; return &byte; } repro.js import { dlopen, suffix...
Opengraph URL: https://github.com/nodejs/node/issues/65085
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: exportArrayBufferView() inconsistently handles detached views","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nmacOS 26.6.0\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n`repro.c`\n```c\nvoid* destination(void) {\n static unsigned char byte;\n return &byte;\n}\n```\n\n`repro.js`\n```js\nimport { dlopen, suffix, exportArrayBuffer, exportArrayBufferView } from 'node:ffi';\n\nconst { lib, functions } = dlopen(`./repro.${suffix}`, {\n destination: { arguments: [], return: 'pointer' },\n});\n\nconst pointer = functions.destination();\n\nfunction detached(makeValue) {\n const buffer = new ArrayBuffer(1);\n const value = makeValue(buffer);\n structuredClone(buffer, { transfer: [buffer] });\n return value;\n}\n\nfunction run(name, fn) {\n try {\n fn();\n console.log(`${name}: accepted`);\n } catch (error) {\n console.log(`${name}: ${error.code ?? error.name}: ${error.message}`);\n }\n}\n\nrun('ArrayBuffer', () => {\n exportArrayBuffer(detached((buffer) => buffer), pointer, 1);\n});\n\nrun('Uint8Array', () => {\n exportArrayBufferView(\n detached((buffer) => new Uint8Array(buffer)),\n pointer,\n 1,\n );\n});\n\nrun('DataView', () => {\n exportArrayBufferView(\n detached((buffer) => new DataView(buffer)),\n pointer,\n 1,\n );\n});\n\nlib.close();\n```\n\nCommands to run:\n```sh\n$ cc -dynamiclib -o repro.dylib repro.c\n$ node --no-warnings --experimental-ffi 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\nAll detached inputs should be rejected consistently, preferably with Node.js’s `ERR_INVALID_ARG_VALUE`.\n\n### What do you see instead?\n\n```console\nArrayBuffer: ERR_INVALID_ARG_VALUE: ArrayBuffer is detached\nUint8Array: accepted\nDataView: TypeError: Cannot perform get DataView.prototype.byteLength on a detached or out-of-bounds ArrayBuffer\n```\n\nA detached `ArrayBuffer` produces `ERR_INVALID_ARG_VALUE`, a detached `Uint8Array` is accepted, and a detached `DataView` produces a V8 `TypeError`\n\n### Additional information\n\nNoticed while working on https://github.com/nodejs/node/issues/65082","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-08-06T15:13:41Z","url":"https://github.com/nodejs/node/issues/65085"}
| 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:e89ff4b6-3242-442e-532f-c00fbba04397 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D030:12AE65:95C134:C2D1EB:6AED3C5F |
| html-safe-nonce | 332b7fd09b8f6a4f577caaf2dc8fc8a5fba7fd54a5f0161ca282a8143a339614 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDMwOjEyQUU2NTo5NUMxMzQ6QzJEMUVCOjZBRUQzQzVGIiwidmlzaXRvcl9pZCI6Ijk0NzgwMjc1NDYzMTE1NDc4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 35643d6385680d4de2d7530de6f36ee8ecdea4b73b9c26041ead4c94bee0fcf6 |
| hovercard-subject-tag | issue:5082631773 |
| 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/65085/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70d9822f79e8dedb5ad17007a10f2d0779c90e790ee8314177f36bde7e57d142/nodejs/node/issues/65085 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70d9822f79e8dedb5ad17007a10f2d0779c90e790ee8314177f36bde7e57d142/nodejs/node/issues/65085 |
| og:image:alt | Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c void* destination(void) { static unsigned char byte; return &byte; } repro.js import { dlopen, suffix, ex... |
| 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 | 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