Skip to content

src: fix null pointer call when running without a startup snapshot - #65820

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-worker-null-snapshot-ub
Open

src: fix null pointer call when running without a startup snapshot#65820
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-worker-null-snapshot-ub

Conversation

@codebytere

@codebytere codebytere commented Sep 5, 2026

Copy link
Copy Markdown
Member

Without a startup snapshot (--no-node-snapshot, a --without-node-snapshot build, or an embedder Environment that was bootstrapped from scratch, which includes Electron's renderer), starting a Worker calls a member function through a null SnapshotData*, and so does the main instance while setting itself up. Nothing crashes today only because that function happens not to touch this; 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 because IsolateData::CreateIsolateData() took an EmbedderSnapshotData* parameter, so its two internal callers wrapped their possibly-null SnapshotData* with AsEmbedderWrapper() only for it to be unwrapped again.

IsolateData::CreateIsolateData() now takes the SnapshotData* itself and only the public CreateIsolateData() 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.WorkerInEnvironmentWithoutSnapshot starts a Worker from the snapshot-less cctest Environment; UBSan flags it before the change and is quiet after. node --no-node-snapshot with 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.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 5, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codebytere codebytere changed the title src: pass SnapshotData to IsolateData::CreateIsolateData() directly src: fix null pointer call when running without a startup snapshot Sep 5, 2026
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
codebytere force-pushed the fix/embedder-worker-null-snapshot-ub branch from a6a8713 to c55177f Compare September 5, 2026 17:56
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.17%. Comparing base (b0d56c7) to head (c55177f).
⚠️ Report is 2 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/api/environment.cc 78.01% <100.00%> (+0.13%) ⬆️
src/env.cc 82.24% <ø> (-0.10%) ⬇️
src/env.h 98.36% <ø> (ø)
src/node_main_instance.cc 90.14% <100.00%> (ø)
src/node_snapshotable.cc 73.47% <ø> (-0.06%) ⬇️
src/node_worker.cc 82.10% <100.00%> (-0.21%) ⬇️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants