Skip to content

fix(flutter): find snapshot headers that a read chunk boundary splits - #2804

Merged
morluto merged 2 commits into
morluto:mainfrom
Dragolone:fix/flutter-snapshot-scan-chunk-boundary
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
Dragolone:fix/flutter-snapshot-scan-chunk-boundary

Conversation

@Dragolone

@Dragolone Dragolone commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

identify_flutter_build can omit a Dart snapshot hash, and report coverage: "complete" with a single agreed hash, depending only on where the APK reader's chunk boundaries fall.

Within one chunk, SnapshotHashScanner resumes 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" and identify_flutter_build and found no report. The #1582 review fixed chunk-boundary cases in the labeled-string scanner, not this one. Open PR #2334 touches DartElf.ts, not this scanner.

Problem and expected behavior

Smallest trigger: a stray magic f5 f5 dc dc whose 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.so holds the VM and isolate sections (hash 65817c30…), a stray magic at 65484, and a third section with hash 2222… at 65534. The third section's magic straddles zip.js's 64 KiB read boundary.

Violated contract: docs/flutter-analysis.md says that when snapshot hashes disagree, all candidates are kept, snapshot_hash is 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 #base offset unnecessary, and both are removed (thanks to the Codex review). No other scanner behavior changes. Not included: the labeled-string scanner and DartElf.ts.

Contribution scope: an ordinary static format-inspection correctness fix within existing boundaries; a maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: SnapshotHashScanner.push in src/flutter/FlutterPayloadScan.ts.
  • Contribution scope fit and linked maintainer decision: in scope (format inspection, evidence reporting); not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. snapshot_hash_sources, snapshot_hash_candidates, snapshot_hash and coverage now match the single-chunk result for affected inputs.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: fixes a case where a disagreement was silently omitted while coverage said complete.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (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.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: 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.
  • Base reproduction: on 91830f1e0 all three cases fail with AssertionError: split at 52: expected { sources: +0, candidates: [], …(1) } to deeply equal { sources: 1, …(2) }.
  • User-visible output: FlutterBuildProvider identify_flutter_build on the APK described above (a local test that was not committed):
    • Before: { coverage: 'complete', sources: 2, candidates: [ '65817c30a78bb44c3dc3771876b6010a' ], hash: '65817c30a78bb44c3dc3771876b6010a' }
    • After: { coverage: 'partial', sources: 3, candidates: [ '65817c30a78bb44c3dc3771876b6010a', '22222222222222222222222222222222' ], hash: null }
  • Remaining proof gaps: the trigger needs a magic within 49–51 bytes after a rejected record and a read boundary inside the second magic. I have not observed it in a real Flutter APK.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

macOS (Apple silicon), Node 24.19.0.

  • npx vitest run src/flutter/FlutterPayloadScan.test.ts against 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.
  • A local split fuzz (not committed): 50,000 random payloads with clustered magics and valid hashes, each fed in random 1–80-byte chunks and compared with a single push. The base had 1 mismatch; the fix, before and after the cursor removal, had 0.
  • The end-to-end identify_flutter_build comparison above, run against the base and the fix.
  • npm run typecheck — passed.
  • npx oxfmt --check on both changed files — passed.
  • npm run verify:module-boundaries — passed.
  • npm run lint — the only error is tests/boundary/providers/ghidra/ghidraLauncher.test.ts:431 (max-lines-per-function), which this PR does not touch. The changed files have only the existing no-control-regex warnings.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change; pure in-memory byte scanning.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T13:26:18.204986Z 743dbfb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/flutter/FlutterPayloadScan.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no blocking issue remains.

Summary

SnapshotHashScanner now resumes after each magic consistently across read boundaries. It removes the absolute cursor and keeps only bytes needed for the next read.

  • Flutter build scans find snapshot hashes even when reads split a header.

Reviews (2) · Last reviewed commit: "refactor(flutter): drop the snapshot sca..." · Reviewed by Greptile

Comment thread src/flutter/FlutterPayloadScan.test.ts Resolved
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.
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

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.

  1. thread 1

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.

@morluto
morluto merged commit 5278835 into morluto:main Oct 13, 2026
3 of 4 checks passed
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior P2: medium Medium priority issue labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants