Title: ffi reuses mutated temporary string buffer without restoring its contents · Issue #65050 · nodejs/node · GitHub
Open Graph Title: ffi reuses mutated temporary string buffer without restoring its contents · Issue #65050 · nodejs/node
X Title: ffi reuses mutated temporary string buffer without restoring its contents · Issue #65050 · nodejs/node
Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include
Open Graph Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include
X Description: Version main Platform macOS 26.6.0 Subsystem ffi What steps will reproduce the bug? repro.c #include <stddef.h> #include <string.h> char* overwrite(char* string, int byte, size_t count)...
Opengraph URL: https://github.com/nodejs/node/issues/65050
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi reuses mutated temporary string buffer without restoring its contents","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\n#include \u003cstddef.h>\n#include \u003cstring.h>\n\nchar* overwrite(char* string, int byte, size_t count) {\n return memset(string, byte, count);\n}\n```\n\n`repro.js`\n```js\nimport { DynamicLibrary, suffix, toString } from 'node:ffi';\n\nconst lib = new DynamicLibrary(`./repro.${suffix}`);\nconst overwrite = lib.getFunction('overwrite', {\n arguments: ['string', 'i32', 'u64'],\n return: 'pointer',\n});\n\nconsole.log(toString(overwrite('hello', 0x79, 1n))); // \"yello\"\nconsole.log(toString(overwrite('hello', 0, 0n))); // \"yello\"; expected \"hello\"\n\nlib.close();\n```\n\nRun commands\n```sh\n$ cc -dynamiclib -o repro.dylib repro.c\n$ node --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\n```console\nyello\nhello\n```\n\neach call should populate temporary storage from the supplied JavaScript string, so reusing `\"hello\"` should produce `\"hello\"`.\n\n\n### What do you see instead?\n\n```console\nyello\nyello\n```\n\nthe second call receives `\"yello\"` because the cached temporary buffer retains the native mutation from the first call.\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-08-05T14:57:41Z","url":"https://github.com/nodejs/node/issues/65050"}
| 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:482e8c14-c6d5-f31e-938a-af62fe94c642 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B05C:39BC20:687FEA:8BF9D4:6AED2124 |
| html-safe-nonce | ad5a582c1fbafc0c578f233878ebddd0737294207f8a5d7edb219ba249c89b5f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDVDOjM5QkMyMDo2ODdGRUE6OEJGOUQ0OjZBRUQyMTI0IiwidmlzaXRvcl9pZCI6IjUxMzE0MDkzNjk3ODEzMTM4MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9cd967f10a7328efef423cb88c5eee00c963ae16ed8be720e404161c5bc08218 |
| hovercard-subject-tag | issue:5072232127 |
| 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/65050/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f00291e3d31458affc35f7a0316f616793141bf1c556b942570ead2a1b02616/nodejs/node/issues/65050 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f00291e3d31458affc35f7a0316f616793141bf1c556b942570ead2a1b02616/nodejs/node/issues/65050 |
| og:image:alt | Version main Platform macOS 26.6.0 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 | e3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6 |
| 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 | 707a24b346ac8a82878b9c084efaa38a997660cb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width