Skip to content

feat(artifacts): add bounded static Android sparse image reader - #14395

Closed
saariuslystoned wants to merge 4 commits into
morluto:mainfrom
saariuslystoned:feat/artifacts-android-sparse
Closed

saariuslystoned wants to merge 4 commits into
morluto:mainfrom
saariuslystoned:feat/artifacts-android-sparse

Conversation

@saariuslystoned

Copy link
Copy Markdown
Contributor

Summary

Adds strictly read-only, bounded static container recognition, inspection, summary projection, and physical RAW chunk extraction for AOSP Android sparse (simg, 0xed26ff3a) images (android-sparse-image) across inspect-artifact / inspect_artifact, extract-artifact / extract_artifact, and BinaryTargetResolver.

Problem and expected behavior

Previously, REA rejected Android sparse images (0xed26ff3a LE headers commonly used for system.img, vendor.img, vendor_dlkm.img, and super.img). Now REA recognizes the little-endian 0xed26ff3a magic prefix as android-sparse-image, validates the 28-byte sparse_header_t and 12-byte chunk_header_t records across RAW (0xCAC1), FILL (0xCAC2), DONT_CARE (0xCAC3), and CRC32 (0xCAC4), reports structured container metadata (unsparsed_size, block/chunk totals, bounded positional chunk descriptors, and android-sparse-image-summary for --detail summary / detail: "summary"), and exposes stored RAW chunk byte slices (chunks/chunk-<index>-raw.bin) by carrier offset without materializing gigabytes of virtual FILL or DONT_CARE blocks.

Change and scope

  • Domain parser & format limits (src/domain/androidSparseImageFormat.ts):
    • Parses 28-byte LE sparse_header_t (magic === 0xed26ff3a, major_version === 1, file_hdr_sz >= 28 <= 4096, chunk_hdr_sz >= 12 <= 1024, non-zero 4-byte-aligned blk_sz, total_blks, total_chunks <= 65536, image_checksum).
    • Validates chunks using exact BigInt arithmetic to reject chunk_sz * blk_sz / total_blks * blk_sz overflows, 32-bit block-sum wraparound, total_sz framing mismatches, CRC32 non-zero chunk_sz, unknown chunk_type, carrier extent overflows/truncations, and total_blks mismatches.
    • Accumulates full-container chunk/block/virtual-byte counts in O(1) memory while capping inline chunks descriptors at 256 (chunks_omitted) and crc32_chunk_values at 64 (crc32_chunk_values_omitted), recording trailing_bytes with complete: false (coverage.status = "unknown") when unparsed bytes trail declared chunks.
  • Positional container reader (src/artifacts/AndroidSparseImageArtifactReader.ts):
    • Extends PositionalArtifactReader using 4 KiB header read windows and zero-copy carrier byte slices (RAW chunks only), preserving carrier identity rechecks, cancellation checks, and forwarding ANDROID_SPARSE_FIXED_LIMITS into artifactFixedLimitFailure (registered in scripts/verify/fixed-ceiling-registry.json).
  • Format vocabularies, recognition, schemas, and summary view:
    • Wired "android-sparse-image" across targetFormats.ts, artifactGraph.ts, androidAndSystemMetadata.ts, artifactFormatMetadata.ts, artifactFormatRecognition.ts, androidSparseImageSummary.ts, espFlashImageSummary.ts, artifactInventoryView.ts, ArtifactReader.ts, artifactFormats.ts, and TargetFormatVocabularies.test.ts.
  • Documentation:
    • Added docs/android-sparse-image.md and updated docs/.vitepress/documentation.ts, docs/README.md, docs/getting-started/cli.md, docs/guides/firmware/firmware-analysis.md, .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md, and .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md.

Contract and boundary impact

  • Semantic owner: src/domain/androidSparseImageFormat.ts (header/chunk grammar, bounds, ceilings, accounting) consumed by both src/domain/artifactFormatRecognition.ts and src/artifacts/AndroidSparseImageArtifactReader.ts.
  • No external runtime dependencies, no code execution, no virtual zero/fill block expansion: Only RAW chunk byte ranges in the carrier file are hashed or extracted; FILL and DONT_CARE regions remain non-materialized metadata, and image_checksum / CRC32 chunk checksums remain unverified (crc32_verified: false).
  • Expected effects:
    • Read existing files or captured data.

Evidence and regression coverage

  • Clean-room synthetic fixtures only (tests/fixtures/androidSparseImage.ts).
  • Tests added/updated:
    • src/domain/androidSparseImageFormat.test.ts (magic, multi-GiB virtual FILL/DONT_CARE without allocation, header/chunk bounds, integer overflows, total_blks wrap/mismatch, truncation, trailing bytes, bounded inline previews, fixed ceilings)
    • src/domain/artifactFormatRecognition.test.ts (0xed26ff3a prefix recognition)
    • src/domain/analysisView/androidSparseImageSummary.test.ts (android-sparse-image-summary schema & projection)
    • src/application/binary/TargetFormatVocabularies.test.ts (exhaustive target format fixture)
    • src/artifacts/AndroidSparseImageArtifactReader.test.ts (streamed RAW slices, 0-raw-chunk sparse containers, trailing bytes)
    • src/artifacts/AndroidSparseImageArtifactReader.boundaries.test.ts (artifactReaderLifecycleCases, artifactPreparationRecoveryCases, fixed ceilings, post-prepare carrier mutation)
    • tests/acceptance/androidSparseImageCli.test.ts (compiled CLI inspect-artifact, --detail summary, extract-artifact, structured malformed/truncated/ceiling errors)
    • tests/boundary/mcp/androidSparseImageMcp.test.ts (compiled MCP open_binary, inspect_artifact, summary detail, extract_artifact)

Validation performed

Verified on HEAD f17123668154e2bda8824f722b30c89e1c138e55:

  • npm run format:check — exit 0 (8834 files)
  • npm run check:fast — exit 0 (turbo 2/2; verify:architecture-guards 3116 source files)
  • npm run verify:test-discovery — exit 0 (3905 test and spec files)
  • npm run metadata:check — exit 0
  • npm run build:cached — exit 0 (3/3)
  • npm run docs:check — exit 0 (docs:check:built 6/6; tests/conformance/readmeConsistency.test.ts 8/8)
  • npx vitest run src/domain/androidSparseImageFormat.test.ts src/domain/artifactFormatRecognition.test.ts src/domain/analysisView/androidSparseImageSummary.test.ts src/domain/analysisView/artifactInventoryView.test.ts src/application/binary/TargetFormatVocabularies.test.ts src/artifacts/AndroidSparseImageArtifactReader.test.ts src/artifacts/AndroidSparseImageArtifactReader.boundaries.test.ts tests/acceptance/androidSparseImageCli.test.ts tests/boundary/mcp/androidSparseImageMcp.test.ts — exit 0 (9 test files, 108/108 tests passed)

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T22:09:25.802528Z
We couldn’t complete this review. Comment @codex review to try again.
f171236 PR opened
ℹ️ 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; all previous findings are addressed.

Summary

Adds static Android sparse image inspection and extraction of stored RAW chunks without expanding virtual blocks.

  • REA reads Android sparse images and exposes their stored RAW chunks.
  • Sparse image summaries stay compact, and callers can raise the chunk limit.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[New operation] --> B[Resolve complete reader limits]
  B --> C[Parse sparse headers and chunks]
  C --> D[Metadata and stored RAW slices]
  E[Saved Evidence] --> F[Authenticate record]
  F --> G[Read recorded limits without defaults]
  G --> H[Summary or comparison]
Loading

Reviews (4) · Last reviewed commit: "fix(artifacts): preserve recorded effect..." · Reviewed by Greptile

Comment thread src/domain/androidSparseImageFormat.ts Resolved
…oid-sparse

# Conflicts:
#	.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md
#	.cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md
#	docs/getting-started/cli.md
#	src/artifacts/artifactFormats.ts
#	src/domain/artifactFormatMetadata.ts
#	src/domain/artifactFormatRecognition.ts
#	src/domain/artifactGraph.ts
#	src/domain/formatMetadata/androidAndSystemMetadata.ts
#	src/domain/targetFormats.ts
#	src/resources/ArtifactReader.ts
Comment thread src/domain/artifactReaderLimits.ts Resolved
@vincentkoc

Copy link
Copy Markdown
Collaborator

this overlaps #13244, whose full-image expansion is a distinct workflow. keeping the bounded inspection/RAW-slice work open; please add the human owner and Author readiness before landing review.

@vincentkoc

Copy link
Copy Markdown
Collaborator

The shared sparse parser and expanded-image path have landed in #13244. Your metadata-only inspection and RAW-slice behavior remain distinct; please build those on the landed parser owner. Keeping this open for that follow-up.

@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 26, 2026
@morluto

morluto commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by #13244 (192177f0c9), which landed the canonical Android sparse image parser (src/domain/firmware/androidSparseImage.ts) and artifact reader on main. Any distinct RAW-slice or metadata-only view should be built on that landed parser owner in a fresh PR.

@morluto morluto closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants