ffi: refresh cached string buffers on every call · nodejs/node@9b4f349 · GitHub
Skip to content

Commit 9b4f349

Browse files
trivikraduh95
authored andcommitted
ffi: refresh cached string buffers on every call
Native code can mutate temporary string storage during an FFI call. Rewrite cached buffers on every conversion so a later call with the same JavaScript string receives a fresh copy of its UTF-8 bytes. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #65051 Fixes: #65050 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent eb095a9 commit 9b4f349

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

lib/internal/ffi/fast-api.js

Lines changed: 0 additions & 5 deletions

test/ffi/fixture_library/ffi_test_library.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ FFI_EXPORT uint8_t string_equals_hello(const char* str) {
108108
return str && strcmp(str, "hello") == 0;
109109
}
110110

111+
FFI_EXPORT uint8_t overwrite_string(char* str, int32_t value, uint64_t length) {
112+
memset(str, value, (size_t)length);
113+
return (uint8_t)str[0];
114+
}
115+
111116
FFI_EXPORT char* string_concat(const char* a, const char* b) {
112117
if (!a || !b) {
113118
// NOLINTNEXTLINE (readability/null_usage)

test/ffi/test-ffi-fast-buffer.js

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)