Skip to content

fix(android): per-call temp file to close concurrent verify->install race - #4

Merged
exo-doguhan merged 1 commit into
masterfrom
exo-doguhan/fix-concurrent-tmp-race
Sep 3, 2026
Merged

exo-doguhan merged 1 commit into
masterfrom
exo-doguhan/fix-concurrent-tmp-race

Conversation

@exo-doguhan

Copy link
Copy Markdown

Overview

Fixes a concurrency race in the Android verified-install path, raised in review of the consuming app's bump PR (ExodusMovement/exodus#44443).

loadVerifiedFromUrl spawns a thread per call, and every call shared one fixed temp path (verified-bundle.jsbundle.tmp). With two overlapping calls, call B's delete() + recreate at that path swaps the file out from under call A between A's streaming hash and A's renameTo(target): A still writes to its now-orphaned inode so its digest matches its own bytes, but the rename promotes B's partial/unverified file onto the canonical bundle — breaking the "canonical path only ever holds verified bytes" invariant the temp-then-promote design is meant to establish.

Fix: download to a per-call File.createTempFile(...) temp, cleaned up in a finally. Each call verifies and renames its own file, so the canonical path only ever receives a fully verified bundle regardless of concurrency.

iOS is unaffected — it hashes the in-memory NSData and atomically writes those exact verified bytes (no shared-path promotion).

No version bump here — the version will be bumped in a separate commit after merge (same as the hardening PR), then published.

Verification

  • Android JVM tests: 5/5 pass, incl. a new concurrentCallsUseDistinctTempsSoTargetOnlyHoldsVerifiedBytes regression guard.
  • JS lint / typescript / jest (10) / verify-pack all pass.
  • verifyAndInstall logic and its existing cases are unchanged; only the caller's temp allocation + cleanup changed.

…race

loadVerifiedFromUrl spawned a thread per call and every call shared one fixed
temp path (verified-bundle.jsbundle.tmp). Under two overlapping calls, call B's
delete+recreate at that path swapped the file out from under call A between A's
streaming hash and A's renameTo(target): A's digest still matched its own
(orphaned-inode) bytes, but the rename promoted B's partial/unverified file onto
the canonical bundle — breaking the 'canonical path only ever holds verified
bytes' invariant the temp-then-promote design establishes.

Download to a per-call File.createTempFile temp instead, cleaned up in a finally.
Each call now verifies and renames its own file, so the canonical path only ever
receives a fully verified bundle regardless of concurrency. iOS is unaffected (it
hashes the in-memory NSData and atomically writes those same bytes).

Adds a regression test asserting distinct temps per call.
@exo-doguhan
exo-doguhan merged commit 73008f1 into master Sep 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant