src: fix null pointer call when running without a startup snapshot - #65820
Open
codebytere wants to merge 1 commit into
Open
src: fix null pointer call when running without a startup snapshot#65820codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
Collaborator
Without a startup snapshot (`--no-node-snapshot`, a `--without-node-snapshot` build, or an embedder Environment that was bootstrapped from scratch) starting a Worker made a member call through a null `SnapshotData*`, and so did `NodeMainInstance` while setting itself up. It only worked because the function called does not touch `this`; UBSan reports it for every such Worker. The call existed because `IsolateData::CreateIsolateData()` took an `EmbedderSnapshotData*` and unwrapped it straight away, so the two internal callers wrapped their possibly-null `SnapshotData*` with `AsEmbedderWrapper()` only for it to be unwrapped again. Let the internal function take the `SnapshotData*` itself, unwrap in the public `CreateIsolateData()` only, and drop `AsEmbedderWrapper()`, which has no other users. Refs: nodejs#47731 Signed-off-by: Shelley Vohr <[email protected]>
codebytere
force-pushed
the
fix/embedder-worker-null-snapshot-ub
branch
from
September 5, 2026 17:56
a6a8713 to
c55177f
Compare
Collaborator
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65820 +/- ##
==========================================
- Coverage 90.19% 90.17% -0.03%
==========================================
Files 770 770
Lines 264410 264410
Branches 50243 50232 -11
==========================================
- Hits 238490 238437 -53
- Misses 16924 16979 +55
+ Partials 8996 8994 -2
🚀 New features to boost your workflow:
|
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.
Without a startup snapshot (
--no-node-snapshot, a--without-node-snapshotbuild, or an embedder Environment that was bootstrapped from scratch, which includes Electron's renderer), starting a Worker calls a member function through a nullSnapshotData*, and so does the main instance while setting itself up. Nothing crashes today only because that function happens not to touchthis; it is undefined behaviour and UBSan reports it for every such Worker (node_worker.cc:211: runtime error: member call on null pointer of type 'node::SnapshotData'). The call is there becauseIsolateData::CreateIsolateData()took anEmbedderSnapshotData*parameter, so its two internal callers wrapped their possibly-nullSnapshotData*withAsEmbedderWrapper()only for it to be unwrapped again.IsolateData::CreateIsolateData()now takes theSnapshotData*itself and only the publicCreateIsolateData()unwraps the embedder type, so there is no call left to make on a null pointer.AsEmbedderWrapper()had no other users and is removed.Tests:
EnvironmentTest.WorkerInEnvironmentWithoutSnapshotstarts a Worker from the snapshot-less cctest Environment; UBSan flags it before the change and is quiet after.node --no-node-snapshotwith a Worker and the worker and snapshot suites pass.Refs: #47731
Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.