fix(ext/ffi): retain backing store references in nonblocking calls#32775
Merged
bartlomieju merged 2 commits intomainfrom Mar 16, 2026
Merged
fix(ext/ffi): retain backing store references in nonblocking calls#32775bartlomieju merged 2 commits intomainfrom
bartlomieju merged 2 commits intomainfrom
Conversation
Nonblocking FFI calls extract raw pointers from ArrayBuffer backing stores and send them to a background thread via spawn_blocking, but without retaining a reference to the backing store. If V8's garbage collector runs before the background thread completes, the backing store can be freed, leaving the native code with a dangling pointer. Fix by collecting SharedRef<BackingStore> references alongside the raw pointers for buffer, struct, and out_buffer arguments in nonblocking calls, and moving them into the spawn_blocking closure so they are kept alive for the duration of the native call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kajukitli
approved these changes
Mar 16, 2026
Contributor
kajukitli
left a comment
There was a problem hiding this comment.
lgtm — solid fix for the UAF in nonblocking FFI
the BackingStoreHolder pattern is clean: grab SharedRef<BackingStore> before extracting raw pointers, move holder into the spawn_blocking closure, explicit drop() after the call to make intent clear
test coverage is good: fills buffer with known pattern, forces GC while native sleeps, validates checksum on return
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nonblocking FFI calls extract raw pointers from ArrayBuffer backing stores and send them to a background thread via spawn_blocking, but without retaining a reference to the backing store. If V8's garbage collector runs before the background thread completes, the backing store can be freed, leaving the native code with a dangling pointer.
Fix by collecting SharedRef references alongside the raw pointers for buffer, struct, and out_buffer arguments in nonblocking calls, and moving them into the spawn_blocking closure so they are kept alive for the duration of the native call.