ffi: refresh cached string buffers on every call - #65051
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65051 +/- ##
=======================================
Coverage 90.30% 90.31%
=======================================
Files 760 760
Lines 248526 248521 -5
Branches 46886 46896 +10
=======================================
+ Hits 224439 224445 +6
+ Misses 15515 15502 -13
- Partials 8572 8574 +2
🚀 New features to boost your workflow:
|
a88fe4c to
8f76513
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
|
Converted to draft as ---
duration_ms: 1355.201
exitcode: 1
severity: fail
stack: |-
Test failure: 'fast FFI refreshes cached temporary string buffers'
Location: test/ffi/test-ffi-fast-buffer.js:99:1
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
'' !== 'yello'
at TestContext.<anonymous> (/home/iojs/build/workspace/node-test-commit-aix/nodes/aix72-power9/test/ffi/test-ffi-fast-buffer.js:108:12)
at Test.runInAsyncScope (node:async_hooks:227:14)
at Test.run (node:internal/test_runner/test:1397:25)
at Test.processPendingSubtests (node:internal/test_runner/test:969:18)
at Test.postRun (node:internal/test_runner/test:1537:19)
at Test.run (node:internal/test_runner/test:1462:12)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Test.processPendingSubtests (node:internal/test_runner/test:969:7) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: '',
expected: 'yello',
operator: 'strictEqual',
diff: 'simple'
}
(node:38469944) internal/test/binding: These APIs are for internal testing only. Do not use them.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:38469944) ExperimentalWarning: FFI is an experimental feature and might change at any time
... |
|
There was a bug in test. AIX does not support Node’s PPC64 fast-call trampoline, so it exposes the test’s invalid assumption: the pointer returned by Fast-path platforms retain the cached It was fixed in 89cc17f by observing the mutation during the native call instead of returning a pointer to temporary storage. I'll re-request review after the CI is successful. |
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
89cc17f to
d225103
Compare
d225103 to
8ef6d08
Compare
|
The ffi contract explicitly says JavaScript strings are copied to temporary NUL-terminated UTF-8 storage “for the duration of the call”
The fast path happens to retain reusable buffers longer, but that is an implementation detail, not a lifetime guarantee. |
Fixes: #65050
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.
Assisted-by: codex:gpt-5.6-sol