Repository navigation
fix(flutter): find snapshot headers that a read chunk boundary splits - #2804
Conversation
Within one chunk the snapshot hash scanner resumes four bytes after each magic, but across chunks it resumed after the whole 52-byte record and dropped the carried bytes. A magic starting 49-51 bytes after a rejected (non-hex) record was therefore lost when its four bytes straddled a read boundary, so the result depended on chunking and a conflicting hash could be omitted while coverage stayed complete. Resume after the magic in both cases.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c24f7443f3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
After a complete record the carried tail is shorter than a magic, and a pending magic has not been processed, so every push can rescan its carried bytes from the start without counting a record twice. Remove the absolute cursor and base offset, and cover sections 49-51 bytes after a rejected record with two-chunk and byte-at-a-time feeds.
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. The absolute cursor duplicated state already fully represented by the retained carry buffer. The contributor independently addressed this in live head 743dbfb while this pass was in progress; I preserved that commit rather than pushing redundant edits. Source inspection confirms #base and #absoluteScanFrom and all their assignments are removed. Scanning resumes at zero in the carry; within-chunk progress still advances past each magic, and retention keeps a pending record or the final magic-prefix bytes. Existing coverage remains, strengthened by the contributor for 49/50/51-byte record overlaps, every split, and bytewise delivery. No additional cleanup remains for this duplicate representation. I inspected the producer and its result consumers; no tests/builds/checks/provider workloads or CI reruns were run, as explicitly requested. |
Summary
identify_flutter_buildcan omit a Dart snapshot hash, and reportcoverage: "complete"with a single agreed hash, depending only on where the APK reader's chunk boundaries fall.Within one chunk,
SnapshotHashScannerresumes four bytes after each magic. Across chunks it resumed after the whole 52-byte magic-to-hash record and dropped the carried bytes. A magic starting 49–51 bytes after a rejected (non-hex) record was therefore lost when its four bytes straddled a read boundary. This PR resumes after the magic in both cases.No issue is linked: I searched issues and PRs for
SnapshotHashScanner,FlutterPayloadScan, "snapshot hash chunk boundary", "snapshot magic" andidentify_flutter_buildand found no report. The #1582 review fixed chunk-boundary cases in the labeled-string scanner, not this one. Open PR #2334 touchesDartElf.ts, not this scanner.Problem and expected behavior
Smallest trigger: a stray magic
f5 f5 dc dcwhose hash field is not lowercase hex, followed 50 bytes later by a real snapshot section. Fed as one chunk, the scanner finds 1 source. Split at byte 52, it finds 0.End to end: an APK whose
lib/arm64-v8a/libapp.soholds the VM and isolate sections (hash65817c30…), a stray magic at 65484, and a third section with hash2222…at 65534. The third section's magic straddles zip.js's 64 KiB read boundary.Violated contract:
docs/flutter-analysis.mdsays that when snapshot hashes disagree, all candidates are kept,snapshot_hashis null, and coverage is partial rather than silently picking one. With the bug, the conflicting hash is dropped and the result says complete.Expected: the result does not depend on chunking, so the APK above reports both candidates, a null hash, and partial coverage.
Change and scope
The cross-chunk resume point now matches the in-chunk one: right after the processed magic. After a complete record, the carried tail is shorter than a magic. A pending magic has not been processed yet. So each push can rescan its carried bytes from the start without counting a record twice. That made the absolute cursor (
#absoluteScanFrom) and its#baseoffset unnecessary, and both are removed (thanks to the Codex review). No other scanner behavior changes. Not included: the labeled-string scanner andDartElf.ts.Contribution scope: an ordinary static format-inspection correctness fix within existing boundaries; a maintainer scope decision is not applicable.
Contract and boundary impact
SnapshotHashScanner.pushinsrc/flutter/FlutterPayloadScan.ts.snapshot_hash_sources,snapshot_hash_candidates,snapshot_hashandcoveragenow match the single-chunk result for affected inputs.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/flutter/FlutterPayloadScan.test.ts— "finds a section %i bytes after a rejected record at any chunking", run for offsets 49, 50 and 51. It splits the payload at every byte and also feeds it one byte at a time. Every result must equal the single-chunk result.91830f1e0all three cases fail withAssertionError: split at 52: expected { sources: +0, candidates: [], …(1) } to deeply equal { sources: 1, …(2) }.FlutterBuildProvideridentify_flutter_buildon the APK described above (a local test that was not committed):{ coverage: 'complete', sources: 2, candidates: [ '65817c30a78bb44c3dc3771876b6010a' ], hash: '65817c30a78bb44c3dc3771876b6010a' }{ coverage: 'partial', sources: 3, candidates: [ '65817c30a78bb44c3dc3771876b6010a', '22222222222222222222222222222222' ], hash: null }For evidence-bearing changes:
Validation performed
macOS (Apple silicon), Node 24.19.0.
npx vitest run src/flutter/FlutterPayloadScan.test.tsagainst the base scanner — the three new cases fail as quoted above (14 others pass).npx vitest run src/flutter/with the fix — 2 files, 31 tests passed.identify_flutter_buildcomparison above, run against the base and the fix.npm run typecheck— passed.npx oxfmt --checkon both changed files — passed.npm run verify:module-boundaries— passed.npm run lint— the only error istests/boundary/providers/ghidra/ghidraLauncher.test.ts:431(max-lines-per-function), which this PR does not touch. The changed files have only the existingno-control-regexwarnings.Compatibility, safety, and release
Before merge
type(scope): outcome.