Skip to content

Fix WeakTag type confusion via unchecked ObjectInfo::Unwrap #1 - #2

Merged
urbanogilson merged 2 commits into
mainfrom
1-weaktag-crash-via-unchecked-objectinfounwrap
Jul 28, 2026
Merged

Fix WeakTag type confusion via unchecked ObjectInfo::Unwrap #1#2
urbanogilson merged 2 commits into
mainfrom
1-weaktag-crash-via-unchecked-objectinfounwrap

Conversation

@urbanogilson

Copy link
Copy Markdown
Member

ObjectWrap<T>::Unwrap() has no way to verify the JS object it's given was actually constructed as T, it's just napi_unwrap() + a blind static_cast. WeakTag relied on this to unwrap ObjectInfo instances, so passing a WeakTag (or any other object) where an ObjectInfo was expected returned a non-null pointer of the wrong type.

The info_ == nullptr guard didn't catch it, and WeakTag's destructor later dereferenced the mistyped pointer, corrupting memory and crashing V8 during GC.

Tag every ObjectInfo instance with a node-api type tag at construction and have WeakTag check that tag before trusting the unwrapped pointer, so mistyped arguments now throw instead of crashing.

@urbanogilson urbanogilson self-assigned this Jul 28, 2026
@urbanogilson urbanogilson added the bug Something isn't working label Jul 28, 2026
@urbanogilson urbanogilson linked an issue Jul 28, 2026 that may be closed by this pull request
@urbanogilson
urbanogilson merged commit 2316d8d into main Jul 28, 2026
12 checks passed
@urbanogilson
urbanogilson deleted the 1-weaktag-crash-via-unchecked-objectinfounwrap branch July 28, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WeakTag crash via unchecked ObjectInfo::Unwrap

1 participant