Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninitialized context annex slot #1497

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ impl Context {
slot: i32,
data: *mut c_void,
) {
// Initialize the annex when slot count > INTERNAL_SLOT_COUNT.
self.get_annex_mut(&mut *v8__Context__GetIsolate(self), true);
littledivy marked this conversation as resolved.
Show resolved Hide resolved

v8__Context__SetAlignedPointerInEmbedderData(
self,
slot + Self::INTERNAL_SLOT_COUNT,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11478,3 +11478,23 @@ fn microtask_queue_new() {
// TODO(bartlomieju): add more tests once we have Context::New() bindings
// https://github.com/denoland/rusty_v8/issues/1438
}

#[test]
fn clear_slots_annex_uninitialized() {
let _setup_guard = setup::parallel_test();
let mut isolate = v8::Isolate::new(Default::default());

let mut scope = v8::HandleScope::new(&mut isolate);

let context = v8::Context::new(&mut scope);

let r = 0;
// This would increase slot count without initializing the annex.
unsafe {
context.set_aligned_pointer_in_embedder_data(1, &r as *const _ as *mut _);
}

// This was trying to deallocate a garbage value when the annex was not
// initialized.
context.clear_all_slots(&mut scope);
}
Loading