[PR #4953] [CLOSED] fix(firmware): report unexplained selected-input bytes as extraction gaps #6692

Closed
opened 2026-11-01 21:42:20 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4953
Author: @akram1089
Created: 10/18/2026
Status: ❌ Closed

Base: main ← Head: fix/3756-unreported-firmware-input-regions


📝 Commits (1)

  • 4308633 fix(firmware): report unexplained selected-input bytes as extraction gaps

📊 Changes

8 files changed (+215 additions, -7 deletions)

View changed files

📝 docs/firmware-analysis.md (+10 -4)
📝 src/domain/firmware/firmwareAnalysis.ts (+3 -0)
📝 src/firmware/FirmwareProvider.ts (+1 -1)
📝 src/firmware/FirmwarePublication.ts (+18 -0)
📝 src/firmware/FirmwareReports.test.ts (+102 -0)
📝 src/firmware/FirmwareReports.ts (+36 -0)
📝 tests/boundary/firmware/firmwareIntegration.test.ts (+33 -0)
📝 tests/fixtures/firmware/producer.mjs (+12 -2)

📄 Description

Summary

Fixes #3756. extract_firmware (CLI extract-firmware) reported coverage: "complete" with no files, chunks, or gaps when Unblob recognized nothing in the selected input, for example an ESP-IDF merged flash image. The selected bytes were absent from the result, so a caller reading complete would conclude the image was fully extracted. The result now carries an unreported-input-region gap for every selected-input byte range no reported chunk covers, with an actionable continuation, and coverage is reported as partial.

Problem and expected behavior

Unblob 26.6.4 _FileTask.process reports nothing for a whole file without a valid chunk ("we don't consider whole files as unknown chunks"), and calculate_unknown_chunks returns an empty list when there are no chunks. REA's coverage rule only checked for chunks with a null handler or encryption, so zero reported chunks fell through to complete. The tool's contract specifies that unextracted gaps yield truncated or unknown coverage, never equivalence.

Change and scope

  • FirmwareReports.normalizeUnblobReport (the producer boundary owning chunk interpretation) derives unreported_input_regions: the complement of the union of reported $input chunk ranges over [0, selection.length), with root_file_range offset by the selection. Children without chunks are published files whose bytes are their own evidence, so only the selected input yields such regions.
  • Adds unreported-input-region gap kind in the domain contract (src/domain/firmware/firmwareAnalysis.ts).
  • FirmwarePublication.ts emits one row per region with provider_id: null (the producer reported no identity) and an actionable continuation naming inspect_firmware_regions (when Binwalk is configured) or a narrower range.
  • gapSortKey appends the byte offset so rows without producer identity order deterministically.
  • Documentation in docs/firmware-analysis.md and provider limitations describe the derived condition accurately.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Unblob report normalization (src/firmware/FirmwareReports.ts).
  • Contribution scope fit and linked maintainer decision: correctness fix within the existing read-only firmware provider; not applicable.
  • CLI and MCP/tool-catalog contract: additive output enum value unreported-input-region in extraction_gaps[].kind; input schemas unchanged.
  • Provider, bridge, target-format, or platform compatibility: Linux Unblob lane only; no producer behavior changed.
  • Evidence, artifact, provenance, or reconstruction contract: derived rows are labeled as such (null provider_id, $input path); observed chunks are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none committed; npm run test:local -- tests/conformance/readmeConsistency.test.ts passed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process (existing Unblob launch, unchanged).
  • 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: FirmwareReports.test.ts (whole selection unreported; gaps around out-of-order chunks; overlapping/adjoining chunks yield none; child without chunks yields none) and firmwareIntegration.test.ts with fixture producer mode unrecognized-input mirroring Unblob's empty report.
  • Base reproduction: on unrecognized or empty input with Unblob, result yielded coverage: "complete", chunks: [], extraction_gaps: [], published_bytes: 0.
  • Patched behavior: coverage: "partial", one gap {kind: "unreported-input-region", input_path: "$input", provider_id: null, range: {offset: 0, length: N}, root_file_range: {offset: 0, length: N}} with its actionable continuation; published_bytes: 0.
  • Selected sub-range: range offsets are correctly preserved and mapped in root_file_range.
  • Fully covered input: when chunks cover the entire selection, no unreported regions are generated and coverage evaluates to complete.

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

  • npm run test:local -- src/firmware/FirmwareReports.test.ts — 25 passed.
  • npm run test:local -- tests/conformance/readmeConsistency.test.ts — 5 passed.
  • npm run verify:test-discovery — 1578 test files discovered once each.
  • npm run check:fast — clean (turbo typecheck & lint passed).
  • npm run lint — clean (0 errors).
  • npm run typecheck — clean (0 errors).

Compatibility, safety, and release

  • Breaking changes or migration steps: none; additive enum value. Callers that treated zero-chunk extractions as complete now see partial with an explicit gap.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux x64 Unblob lane only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process, network or write paths.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4953 **Author:** [@akram1089](https://github.com/akram1089) **Created:** 10/18/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/3756-unreported-firmware-input-regions` --- ### 📝 Commits (1) - [`4308633`](https://github.com/morluto/rea/commit/430863399290fac5b56d64f0d15ff06ff932498b) fix(firmware): report unexplained selected-input bytes as extraction gaps ### 📊 Changes **8 files changed** (+215 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/firmware-analysis.md` (+10 -4) 📝 `src/domain/firmware/firmwareAnalysis.ts` (+3 -0) 📝 `src/firmware/FirmwareProvider.ts` (+1 -1) 📝 `src/firmware/FirmwarePublication.ts` (+18 -0) 📝 `src/firmware/FirmwareReports.test.ts` (+102 -0) 📝 `src/firmware/FirmwareReports.ts` (+36 -0) 📝 `tests/boundary/firmware/firmwareIntegration.test.ts` (+33 -0) 📝 `tests/fixtures/firmware/producer.mjs` (+12 -2) </details> ### 📄 Description ## Summary Fixes #3756. `extract_firmware` (CLI `extract-firmware`) reported `coverage: "complete"` with no files, chunks, or gaps when Unblob recognized nothing in the selected input, for example an ESP-IDF merged flash image. The selected bytes were absent from the result, so a caller reading `complete` would conclude the image was fully extracted. The result now carries an `unreported-input-region` gap for every selected-input byte range no reported chunk covers, with an actionable continuation, and coverage is reported as `partial`. ## Problem and expected behavior Unblob 26.6.4 `_FileTask.process` reports nothing for a whole file without a valid chunk ("we don't consider whole files as unknown chunks"), and `calculate_unknown_chunks` returns an empty list when there are no chunks. REA's coverage rule only checked for chunks with a null handler or encryption, so zero reported chunks fell through to `complete`. The tool's contract specifies that unextracted gaps yield truncated or unknown coverage, never equivalence. ## Change and scope - `FirmwareReports.normalizeUnblobReport` (the producer boundary owning chunk interpretation) derives `unreported_input_regions`: the complement of the union of reported `$input` chunk ranges over `[0, selection.length)`, with `root_file_range` offset by the selection. Children without chunks are published files whose bytes are their own evidence, so only the selected input yields such regions. - Adds `unreported-input-region` gap kind in the domain contract (`src/domain/firmware/firmwareAnalysis.ts`). - `FirmwarePublication.ts` emits one row per region with `provider_id: null` (the producer reported no identity) and an actionable continuation naming `inspect_firmware_regions` (when Binwalk is configured) or a narrower range. - `gapSortKey` appends the byte offset so rows without producer identity order deterministically. - Documentation in `docs/firmware-analysis.md` and provider limitations describe the derived condition accurately. ## Contract and boundary impact - Semantic owner and earliest changed stage: Unblob report normalization (`src/firmware/FirmwareReports.ts`). - Contribution scope fit and linked maintainer decision: correctness fix within the existing read-only firmware provider; not applicable. - CLI and MCP/tool-catalog contract: additive output enum value `unreported-input-region` in `extraction_gaps[].kind`; input schemas unchanged. - Provider, bridge, target-format, or platform compatibility: Linux Unblob lane only; no producer behavior changed. - Evidence, artifact, provenance, or reconstruction contract: derived rows are labeled as such (null `provider_id`, `$input` path); observed chunks are unchanged. - Target selection, authority, upstream behavior, and cleanup details: unchanged. - Generated metadata, package, or installation impact: none committed; `npm run test:local -- tests/conformance/readmeConsistency.test.ts` passed. Expected effects: - [x] Read existing files or captured data. - [x] Launch or attach to a process (existing Unblob launch, unchanged). - [ ] 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: `FirmwareReports.test.ts` (whole selection unreported; gaps around out-of-order chunks; overlapping/adjoining chunks yield none; child without chunks yields none) and `firmwareIntegration.test.ts` with fixture producer mode `unrecognized-input` mirroring Unblob's empty report. - Base reproduction: on unrecognized or empty input with Unblob, result yielded `coverage: "complete"`, `chunks: []`, `extraction_gaps: []`, `published_bytes: 0`. - Patched behavior: `coverage: "partial"`, one gap `{kind: "unreported-input-region", input_path: "$input", provider_id: null, range: {offset: 0, length: N}, root_file_range: {offset: 0, length: N}}` with its actionable continuation; `published_bytes: 0`. - Selected sub-range: range offsets are correctly preserved and mapped in `root_file_range`. - Fully covered input: when chunks cover the entire selection, no unreported regions are generated and coverage evaluates to `complete`. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/firmware/FirmwareReports.test.ts` — 25 passed. - `npm run test:local -- tests/conformance/readmeConsistency.test.ts` — 5 passed. - `npm run verify:test-discovery` — 1578 test files discovered once each. - `npm run check:fast` — clean (turbo typecheck & lint passed). - `npm run lint` — clean (0 errors). - `npm run typecheck` — clean (0 errors). ## Compatibility, safety, and release - Breaking changes or migration steps: none; additive enum value. Callers that treated zero-chunk extractions as `complete` now see `partial` with an explicit gap. - Real Hopper/Ghidra, browser, or OS coverage: Linux x64 Unblob lane only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new process, network or write paths. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] I reviewed the final diff and relevant existing code, understand the change and edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:42:20 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6692
No description provided.