Skip to content

fix: read asar contents through the archive's retained file handle - #52283

Merged
MarshallOfSound merged 3 commits into
mainfrom
sam/asar-read-retained-fd
Jul 9, 2026
Merged

MarshallOfSound merged 3 commits into
mainfrom
sam/asar-read-retained-fd

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Description of Change

Reads of packed asar contents re-opened the archive by path on every read, while using file offsets and per-file integrity hashes from the cached header. If the asar on disk is replaced while the app is running — enterprise MDM / updater software swapping the app bundle is the common case — the fresh open reads the new file's bytes at the old header's offsets. Depending on timing this presents as:

  • a fatal browser-process crash in asar::ValidateIntegrityOrDie (via asar::ReadFileToString reading a preload script at ReadyToCommitNavigation), or
  • a spurious ENOENT: no such file or directory, open '.../app.asar/...' preload error when the file is briefly missing mid-swap, or
  • the equivalent block-hash LOG(FATAL) in AsarFileValidator for apps that serve their UI over file:// from the asar.

The first two became much more visible after #51602 moved preload reads from main-process JS into C++: the JS read path (asar-fs-wrapper.ts) reads through the archive's retained fd and exits cleanly on mismatch, so the same race previously produced no crash reports.

This PR makes the C++ read paths behave like the JS path — read through the base::File the Archive has held open since its header was validated:

  • Archive::ReadFileAt() — positional reads on the retained handle; asar::ReadFileToString() now uses it (covers the three preload startup-data readers and nativeImage file reads).
  • Archive::DuplicateFile() — hands streaming consumers a duplicate of the retained handle; AsarURLLoader uses it for packed files instead of re-opening by path.
  • The unused Archive::path() accessor is removed so by-path opens of archive contents can't be reintroduced accidentally.

Behavior after this change: reads stay consistent with the header that was integrity-validated at open time, so an app whose asar is swapped underneath it keeps serving the version it launched with until relaunch (the pre-#51602 behavior). Note this also means packed reads from a deleted archive now succeed from the retained handle instead of returning ENOENT — intentional, as the transient-deletion window during non-atomic updates was the source of the spurious preload errors.

Security: integrity enforcement is unchanged in strength — in-place tampering is still caught, because the retained handle sees the modified bytes and the hash check fails exactly as before. A swap can no longer produce a false-positive integrity failure, and an attacker who replaces the file gains nothing since the retained handle never observes the replacement.

Verified on macOS with a fused (embeddedAsarIntegrityValidation) packaged build: swapping the asar mid-run previously crashed with the reported ValidateIntegrityOrDie stack on the next navigation and now serves the original content cleanly; removing the asar mid-run previously produced the handled ENOENT preload error and now also serves the original content; a tampered-in-place asar still fails integrity validation fatally.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes locally
  • relevant documentation is changed or added (n/a — no API change)
  • PR title follows semantic commit guidelines

Release Notes

Notes: Fixed a browser-process crash (ValidateIntegrityOrDie) and spurious preload ENOENT errors when an app's app.asar is replaced on disk (e.g. by an updater or MDM software) while the app is running.

Reads of packed asar contents re-opened the archive by path on every
read, while using file offsets and integrity hashes from the cached
header. If the asar on disk was replaced while the app was running
(e.g. by an updater or MDM software swapping the app bundle), the
fresh open would read the new file's bytes at the old header's
offsets, producing either a fatal integrity-check crash in
ValidateIntegrityOrDie (browser process) or a spurious ENOENT preload
error when the file was briefly missing.

Read through the base::File the Archive has held open since the
header was validated instead:

- Archive::ReadFileAt() does positional reads on the retained handle;
  asar::ReadFileToString() now uses it, fixing the preload startup
  data paths and nativeImage reads.
- Archive::DuplicateFile() hands streaming consumers a duplicate of
  the retained handle; AsarURLLoader now uses it for packed files
  instead of re-opening by path, fixing the equivalent block-hash
  FATAL in AsarFileValidator for file:// loads.

This matches the JS fs wrapper, which has always read through the
archive's retained fd. Content served after a swap is the version the
app launched with, consistently, until relaunch. In-place tampering is
still caught: the retained handle sees modified bytes and the hash
check fails as before.

Also removes the now-unused Archive::path() accessor so future
readers of archive contents can't accidentally reintroduce by-path
opens.
@MarshallOfSound MarshallOfSound 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. labels Jul 8, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jul 8, 2026

@samuelmaddock samuelmaddock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for taking a look!

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 9, 2026
@MarshallOfSound
MarshallOfSound merged commit 8215b5a into main Jul 9, 2026
132 of 134 checks passed
@MarshallOfSound
MarshallOfSound deleted the sam/asar-read-retained-fd branch July 9, 2026 04:22
@release-clerk

release-clerk Bot commented Jul 9, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a browser-process crash (ValidateIntegrityOrDie) and spurious preload ENOENT errors when an app's app.asar is replaced on disk (e.g. by an updater or MDM software) while the app is running.

@trop

trop Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

@trop trop Bot added in-flight/44-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. labels Jul 9, 2026
@trop

trop Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

@trop

trop Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

@trop trop Bot added in-flight/43-x-y in-flight/42-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/43-x-y in-flight/42-x-y labels Jul 9, 2026
@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 Jul 9, 2026
MarshallOfSound pushed a commit that referenced this pull request Sep 24, 2026
…cement

Regression test for #52283. File contents used to be re-read from whatever
file was at the archive's path using offsets from the header read at
startup, so replacing app.asar under a running app (as updaters do) served
the wrong bytes or failed. A fixture app loads a file from a temporary
asar in a BrowserWindow, renames a different archive over it, loads the
same file again and reports both results; the spec expects them to match
the original archive. Skipped on Windows, which does not allow renaming
over an archive that is held open.

Verified against Linux release builds: fails on 45.0.0-nightly.20260706,
passes on 45.0.0-nightly.20260716.
MarshallOfSound pushed a commit that referenced this pull request Sep 24, 2026
…cement

Regression test for #52283. File contents used to be re-read from whatever
file was at the archive's path using offsets from the header read at
startup, so replacing app.asar under a running app (as updaters do) served
the wrong bytes or failed. A fixture app loads a file from a temporary
asar in a BrowserWindow, renames a different archive over it, loads the
same file again and reports both results; the spec expects them to match
the original archive. Skipped on Windows, which does not allow renaming
over an archive that is held open.

Verified against Linux release builds: fails on 45.0.0-nightly.20260706,
passes on 45.0.0-nightly.20260716.
MarshallOfSound added a commit that referenced this pull request Sep 24, 2026
* test: cover app.disableHardwareAcceleration() adding --disable-gpu

Regression test for #51817, where disableHardwareAcceleration() stopped
appending the --disable-gpu switch. A small fixture app calls it before
ready and reports whether app.commandLine has the switch once ready.

Verified against Linux release builds: fails on 45.0.0-nightly.20260716,
passes on 45.0.0-nightly.20260720.

* test: check the default menu has no Help menu

Regression test for #50629, which moved the Electron project links out of
the menu every app gets by default and into the default app. The
default-menu fixture gains a --print-items mode that prints the roles and
labels of the top-level items, and the spec asserts the window menu is
there but no Help menu is.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check an unopened Menu can be garbage collected

Regression test for #50806, where a Menu that was built but never opened
was kept alive forever. The spec drops the last reference, holds a WeakRef
and requests async GCs until it clears.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check openDevTools() ignores an unknown dock mode

Regression test for #50646, where the dock mode string was spliced into a
script evaluated in the DevTools frontend. The spec passes a mode that
would break out of the string literal and set a global, waits for the
frontend host to round-trip, and asserts the global was never set. Uses
its own session partition so the dock state it leaves behind does not leak
into other DevTools tests.

Verified against Linux release builds: fails on 43.0.0-nightly.20260402,
passes on 43.0.0-nightly.20260406.

* test: check DevTools reopens in its last dock state

Regression test for #50807, where calling openDevTools() without a mode
always docked to the right instead of restoring the previous dock state.
The spec opens DevTools undocked, closes it, reopens with no options and
reads currentDockState back from the frontend preferences.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check a running app keeps serving its original asar after replacement

Regression test for #52283. File contents used to be re-read from whatever
file was at the archive's path using offsets from the header read at
startup, so replacing app.asar under a running app (as updaters do) served
the wrong bytes or failed. A fixture app loads a file from a temporary
asar in a BrowserWindow, renames a different archive over it, loads the
same file again and reports both results; the spec expects them to match
the original archive. Skipped on Windows, which does not allow renaming
over an archive that is held open.

Verified against Linux release builds: fails on 45.0.0-nightly.20260706,
passes on 45.0.0-nightly.20260716.

* test: check zygote children get their own process title on Linux

Regression test for #50509, where processes forked from the zygote kept
the zygote's command line as their process title, so ps and friends
showed every child as --type=zygote. The spec reads /proc/<pid>/cmdline
for the GPU, renderer and utility processes reported by getAppMetrics()
and expects each to carry its own --type switch, tolerating processes
that exit in the meantime.

Verified against Linux release builds: fails on 43.0.0-nightly.20260323,
passes on 43.0.0-nightly.20260402.

* test: check losing the X server exits the app instead of crashing

Regression test for #52603, where losing the display server connection
went straight to LOG(FATAL). The spec starts a private Xvfb (skipping if
none is available), launches a fixture app on it that logs when its window
is ready, kills the X server and expects the app to exit with a normal
exit code rather than die on a signal. Either Ozone (the app.exit(0) path
the fix added) or GTK (_exit(1)) can be the first to notice the dead
connection, so both codes are accepted. The X server is started inside the
test so mocha's in-job retries get a fresh one.

Verified against Linux release builds: the app dies with SIGTRAP on
45.0.0-nightly.20260805 and exits cleanly on 45.0.0-nightly.20260808.

* test: check a fully transparent titleBarOverlay color on Linux

Regression test for #51017, where a fully transparent overlay colour was
treated as unset and replaced with the default opaque one. Adds
captureDisplayPixels()/expectDisplayPixelsEventually() screen helpers that
read the primary display back through desktopCapturer and retry a set of
assertions until the compositor catches up, then uses them to show a red
page under a transparent overlay and assert that nearly all of the overlay
strip shows the page (only the caption glyphs differ).

The page carries a marker square so the check cannot pass on an unpainted
or stale surface, and colours are compared against each other rather than
constants because CI's 16-bit Xvfb screen quantises them. X11 only:
Wayland has no portal-free capture and other platforms draw native
caption buttons. Tagged serial since it reads the real screen.

Verified against Linux release builds: fails on 44.0.0-nightly.20260529,
passes on 44.0.0-nightly.20260701.

* test: check titleBarOverlay draws its background and buttons on Linux

Regression test for #52577, where the caption button container was not
shown at all on Linux. Using the same capture helpers, the spec shows a
red page with a blue overlay and white symbols and asserts that the
overlay strip is mostly not the page colour and that a second colour (the
button glyphs) is present within it.

Verified against Linux release builds: fails on 45.0.0-nightly.20260731,
passes on 45.0.0-nightly.20260803.

* test: check transparent frameless windows draw no border on Linux

Regression test for #50541, where the frame painted an opaque border
around transparent frameless windows on Linux. The spec puts a blue
backdrop window across the work area, shows a transparent frameless
window with two marker squares over it, captures the screen and asserts
that the only colours in and just around the window bounds are the
backdrop, the see-through area and the two markers, i.e. no frame, border
or shadow pixels. X11 only, tagged serial with the rest of the
"transparent" suite.

Verified against Linux release builds: fails on 43.0.0-nightly.20260323,
passes on 43.0.0-nightly.20260402.

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/42-x-y PR was merged to the "42-x-y" branch. 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. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants