fix(android): per-call temp file to close concurrent verify->install race - #4
Merged
Merged
Conversation
…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.
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.
Overview
Fixes a concurrency race in the Android verified-install path, raised in review of the consuming app's bump PR (ExodusMovement/exodus#44443).
loadVerifiedFromUrlspawns a thread per call, and every call shared one fixed temp path (verified-bundle.jsbundle.tmp). With two overlapping calls, call B'sdelete()+ recreate at that path swaps the file out from under call A between A's streaming hash and A'srenameTo(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 afinally. 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
NSDataand 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
concurrentCallsUseDistinctTempsSoTargetOnlyHoldsVerifiedBytesregression guard.verifyAndInstalllogic and its existing cases are unchanged; only the caller's temp allocation + cleanup changed.