Skip to content

feat(extract): read remote APFS files through HTTP ranges - #1409

Merged
blacktop merged 9 commits into
blacktop:masterfrom
KishanBagaria:codex/remote-ranges-extract
Nov 17, 2026
Merged

blacktop merged 9 commits into
blacktop:masterfrom
KishanBagaria:codex/remote-ranges-extract

Conversation

@KishanBagaria

@KishanBagaria KishanBagaria commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Adds ipsw extract --remote --files --ranged, which fetches matching files from an APFS image inside a remote IPSW using HTTP byte ranges, without downloading or mounting the image. --ranged-dmg selects fs (default), sys, app or exc.

Example: 70 loctables from the 25.6 GB macOS 27.2.1 (26B131) restore image cost 57.6 MB in 238 range requests and about 9 seconds. Also discussed in #1375 where reporter wanted one Info.plist across many OS versions.

Builds on #1408 (merged) and uses go-apfs v1.0.31, which includes the OpenReader API from blacktop/go-apfs#89. master is merged in, so the diff is only this PR's changes.

How it works: the stored ZIP member is read through download.RangeReader, unwrapped through aea.Reader, UDIF and GPT when present, and walked with go-apfs OpenReader. Patterns that must match from the start of the path prune directories that cannot match.

Scope and limits:

  • Opt-in only. Unsupported layouts (deflated DMG, HFS+, legacy encrypted DMG, sparse files, resource-fork zlib) are errors; there is no fallback to a full download.
  • Only regular files at their physical paths inside the selected image are matched; symlinks are not followed, and members of the IPSW ZIP itself are not searched. --flat and --lookup are rejected.
  • After a mid-run error, files already written are still reported.
  • Extracted files keep the image's permission bits; ownership and other metadata are not preserved.
  • Unread AEA segments, AEA padding and the APFS volume seal are not verified in this mode. Everything that is read is authenticated.

Testing

  • go test ./... with master merged in and go-apfs v1.0.31: everything passes except pkg/car/internal/render, pkg/lzma and pkg/usb/{afc,apps,debugserver,forward}, which fail identically on unmodified master on this machine.

  • New tests: an end-to-end synthetic IPSW (plain and AEA) served over HTTP, including permission bits and a pre-existing output symlink; deflated-member rejection; GPT partition selection; prefix pruning; CLI flag validation.

  • Fuzz tests: FuzzAPFSPartition (a partition returned for an arbitrary image must lie inside it) and FuzzPrefixMatcher (pruning must never skip a directory above a path the pattern matches). Ran about 40 s and 60 s (1.2 million and 1.1 million executions) with no failures.

  • Live run on macOS 27.2.1 (26B131):

    ipsw extract --remote --files --ranged --device VirtualMac2,1 \
      --pattern '^/System/(Library|iOSSupport/System/Library)/(PrivateFrameworks|AccessibilityBundles)/(Chat|IM).*\.loctable$' \
      --output out \
      'https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw'

    Exit 0, 70 files, each byte-identical (cmp) to the same path on the installed 26B131 system. Ranged 141-12228-174.dmg.aea: 238 requests, 57608766 bytes downloaded (IPSW: 25595954706 bytes).

  • A second live run extracted /usr/libexec/amfid and /usr/libexec/locationd: both mode 755 and byte-identical to the installed copies.

Not run: make fmt in full (gofmt is clean on the changed files) and make docs (the two new flags were added to www/docs/cli/ipsw/extract.md by hand).

AI Assistance

Planned and written by GPT 6.1 Sol + Claude Fable 5.2. Reviewed manually.

KishanBagaria and others added 4 commits November 16, 2026 16:25
Write and WriteRoot share one temp-file, sync and rename sequence. Write keeps operating on plain paths; WriteRoot runs the same steps confined to an os.Root the caller already holds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reader authenticates the root header and cluster header chain, then decrypts only the segments a ReadAt touches, with a bounded plaintext cache.

The prologue parser, root validation and cluster walk are factored out of decrypt (readPrologue, validateRoot, walkSegments) and shared by both paths. ReadMetadata reads AEA metadata from an io.ReaderAt, and Metadata.SymmetricKey resolves an embedded or FCS-wrapped key.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An io.ReaderAt for sparse remote access: 64 KiB pages in an 8 MiB LRU, large reads sent as direct ranges of up to 4 MiB. Every response must be a 206 whose Content-Range, length and ETag match the request; a full-body 200 is rejected unread. Transport failures and 5xx, 429 and 408 responses are retried twice.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ipsw extract --remote --files --ranged fetches matching files from an APFS image inside a remote IPSW without downloading or mounting the image. --ranged-dmg selects fs (default), sys, app or exc.

The stored ZIP member is read through download.RangeReader, unwrapped through aea.Reader, UDIF and GPT when present, and walked with go-apfs OpenReader. Anchored patterns prune directories that cannot match. Extracted files keep the image's permission bits. Unsupported layouts are errors; there is no fallback to a full download.

go-apfs is pinned to the head of blacktop/go-apfs#89, which adds OpenReader, until that merges.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KishanBagaria and others added 5 commits November 16, 2026 21:18
FuzzNewReader feeds arbitrary archives to the prologue parser. FuzzWalkSegments authenticates a cluster header built from the fuzz input, so the segment bounds checks are exercised rather than stopped at the HMAC.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
FuzzAPFSPartition checks that a partition returned for an arbitrary image lies inside it. FuzzPrefixMatcher checks that pruning never skips a directory above a path the pattern matches.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
v1.0.31 includes OpenReader (blacktop/go-apfs#89).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
if err != nil {
return nil, fmt.Errorf("ranged APFS %s: %w", name, err)
}
if err := os.MkdirAll(destination, 0755); err != nil {
@blacktop
blacktop merged commit 5d96e8d into blacktop:master Nov 17, 2026
5 of 9 checks passed
@KishanBagaria
KishanBagaria deleted the codex/remote-ranges-extract branch November 17, 2026 07:42
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.

3 participants