Skip to content

fix: terminate immediately on asar integrity violation - #53433

Merged
MarshallOfSound merged 3 commits into
mainfrom
fix/asar-integrity-violation-exit-immediately
Sep 3, 2026
Merged

MarshallOfSound merged 3 commits into
mainfrom
fix/asar-integrity-violation-exit-immediately

Conversation

@claude

@claude claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Requested by David Sanders · Slack thread

Description of Change

Before: When an ASAR integrity violation is detected in JavaScript (the asar-fs-wrapper.ts block/file hash checks), the process is torn down with process.reallyExit(1), which bottoms out in libc exit(1). That runs atexit handlers and static destructors on the main thread while Chromium's IO thread, ThreadPool and friends are still live. On Windows this intermittently dies with an access violation (0xC0000005 = 3221225477) before the CRT reaches ExitProcess, so the process exits with the wrong code. This is the expected 3221225477 to equal 1 flake in spec/asar-integrity-spec.ts, and for a shipping app it means a tampered archive would randomly crash instead of exiting with code 1.

After: The violation path calls base::Process::TerminateCurrentProcessImmediately(1) (TerminateProcess on Windows, _exit on POSIX) right after the message is written to stderr. Nothing else runs in-process, so there is no destructor/thread interleaving to lose, and the exit code is 1 on all platforms.

How: Adds an internal exitImmediately(code) method to the electron_common_v8_util binding (alongside the other process-level internal helpers such as runUntilIdle and triggerFatalErrorForTesting), and integrityViolation in lib/node/asar-fs-wrapper.ts now calls it after writing the message instead of process.reallyExit(1). No public API is added and process.exit() behaviour is unchanged. The message is already written with an unbuffered fs.writeSync(2, ...), so nothing is lost by skipping the normal exit sequence. The C++ LOG(FATAL) detection sites are unchanged; they crash by design and the spec expects that.

Evidence: Six failing win-x64 test jobs were examined (e.g. https://github.com/electron/electron/actions/runs/33682957442). Every one of the 33 in-job failures is the identical AssertionError: expected 3221225477 to equal 1; there is never a hash error or a readfile-ok/stream-ok result that would indicate the check itself misbehaved. Only the async JS-detected variants fail (terminates a stream when it reaches corrupted block 0 at 22/24 attempts, (stream) 7/10, (handle) 6/9); the C++ LOG(FATAL) variants (header, main-process JS, renderer file) never fail, and the spec uses expectToHaveCrashed for those. One sampled green main win-x64 job had the same (stream) failure masked by the in-suite retry, so the real rate is higher than the visible one.

Verification: Not built or run here (this was prepared in a Linux environment that cannot build Electron). The existing Windows asar integrity tests in spec/asar-integrity-spec.ts are the regression test for this change; a Windows run of that spec looped on a runner that previously failed the block-0 test should show no 0xC0000005 exits.

This is the same class of problem as #52856, which added TearDownOncePerProcess() before the pre-ready app.exit() exit() call in browser.cc. Follow-ups not included in this PR: installing a node::SetProcessExitHandler in the browser process so any process.reallyExit avoids libc exit(), and giving the pre-ready exit() in browser.cc the same treatment.

Checklist

  • I have built and tested this change (not possible in the environment this was prepared in; needs a Windows CI run)
  • I have filled out the PR description
  • I have reviewed and verified the changes
  • npm test passes (not run here; lint:js, oxfmt --check and clang-format pass on the changed files)
  • tests are changed or added (covered by the existing spec/asar-integrity-spec.ts tests; no new tests)
  • relevant API documentation, tutorials, and examples are updated (n/a, internal binding only)
  • PR release notes describe the change in a way relevant to app developers

Release Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

Notes: Fixed an intermittent crash (access violation) on Windows when an ASAR integrity violation is detected, so the process now exits with code 1 as intended.

The JS-side asar integrity check ends the process via
process.reallyExit(1), which bottoms out in libc exit(). That runs
atexit handlers and static destructors on the main thread while
Chromium's threads are still live, and on Windows intermittently
dies with an access violation (0xC0000005) before reaching
ExitProcess, so the process exits with the wrong code. Terminate
via base::Process::TerminateCurrentProcessImmediately instead so
nothing else runs and exit code 1 is preserved.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Sep 3, 2026
@claude claude Bot added semver/patch backwards-compatible bug fixes target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 3, 2026
@dsanders11
dsanders11 marked this pull request as ready for review September 3, 2026 02:43
@MarshallOfSound MarshallOfSound removed the target/42-x-y PR should also be added to the "42-x-y" branch. label Sep 3, 2026
@MarshallOfSound
MarshallOfSound merged commit 18e2caa into main Sep 3, 2026
84 checks passed
@MarshallOfSound
MarshallOfSound deleted the fix/asar-integrity-violation-exit-immediately branch September 3, 2026 04:55
@release-clerk

release-clerk Bot commented Sep 3, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an intermittent crash (access violation) on Windows when an ASAR integrity violation is detected, so the process now exits with code 1 as intended.

@github-actions github-actions Bot added the 46-x-y label Sep 3, 2026
@trop

trop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "43-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot removed the target/43-x-y PR should also be added to the "43-x-y" branch. label Sep 3, 2026
@trop

trop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "44-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/43-x-y needs-manual-bp/44-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. labels Sep 3, 2026
@trop

trop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "45-x-y", please check out #53438

@trop trop Bot added in-flight/45-x-y merged/45-x-y PR was merged to the "45-x-y" branch. and removed target/45-x-y PR should also be added to the "45-x-y" branch. in-flight/45-x-y labels Sep 3, 2026
@trop

trop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@MarshallOfSound has manually backported this PR to "44-x-y", please check out #53455

@trop

trop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@MarshallOfSound has manually backported this PR to "43-x-y", please check out #53456

MarshallOfSound added a commit that referenced this pull request Sep 3, 2026
fix: terminate immediately on asar integrity violation (#53433)

* fix: terminate immediately on asar integrity violation

The JS-side asar integrity check ends the process via
process.reallyExit(1), which bottoms out in libc exit(). That runs
atexit handlers and static destructors on the main thread while
Chromium's threads are still live, and on Windows intermittently
dies with an access violation (0xC0000005) before reaching
ExitProcess, so the process exits with the wrong code. Terminate
via base::Process::TerminateCurrentProcessImmediately instead so
nothing else runs and exit code 1 is preserved.


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

* refactor: drop dead exit fallbacks after exitImmediately


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

* refactor: move exitImmediately to the v8_util binding


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

---------


(cherry picked from commit 18e2caa)

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude <[email protected]>
@trop trop Bot added merged/43-x-y PR was merged to the "43-x-y" branch. and removed in-flight/43-x-y labels Sep 3, 2026
MarshallOfSound added a commit that referenced this pull request Sep 3, 2026
fix: terminate immediately on asar integrity violation (#53433)

* fix: terminate immediately on asar integrity violation

The JS-side asar integrity check ends the process via
process.reallyExit(1), which bottoms out in libc exit(). That runs
atexit handlers and static destructors on the main thread while
Chromium's threads are still live, and on Windows intermittently
dies with an access violation (0xC0000005) before reaching
ExitProcess, so the process exits with the wrong code. Terminate
via base::Process::TerminateCurrentProcessImmediately instead so
nothing else runs and exit code 1 is preserved.


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

* refactor: drop dead exit fallbacks after exitImmediately


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

* refactor: move exitImmediately to the v8_util binding


Claude-Session: https://claude.ai/code/session_01PBKD1L6FXPM4TQBiNcicTj

---------


(cherry picked from commit 18e2caa)

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude <[email protected]>
@trop trop Bot added merged/44-x-y PR was merged to the "44-x-y" branch. and removed in-flight/44-x-y labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. new-pr 🌱 PR opened recently semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants