Repository navigation
Conversation
[Medium impact] The change reaches the bounded workflow for analyzing Xtensa ELF files. The runtime summary schemas must match the ELF-only Xtensa type before merging. Findings
Fix with agent prompt### Issue 1
src/domain/binaryTargetTypes.ts:undefined-72
This change excludes `xtensa` from `HeaderArchitecture`, but `headerArchitectureSchema` in `src/domain/liveBinaryTargetSummary.ts` still includes it through `BINARY_ARCHITECTURES`. The CLI/MCP output schemas therefore advertise Xtensa PE and Mach-O targets, although `BinaryTarget` permits Xtensa only for ELF.
Add `xtensa` to the runtime exclusion and test that summaries accept Xtensa ELF but reject those other combinations. The repository requires runtime schemas and exported types to agree when constrained values change. That requirement must be satisfied before merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds ELF machine 94 recognition and admits the resulting
Reviews (2) · Last reviewed commit: "fix(elf): admit Xtensa binaries through ..." · Reviewed by Greptile |
| | ElfMetadataArchitecture | ||
| | RawOnlyArchitecture | ||
| | "hexagon" | ||
| | "xtensa" |
There was a problem hiding this comment.
Schemas allow impossible Xtensa targets
This change excludes xtensa from HeaderArchitecture, but headerArchitectureSchema in src/domain/liveBinaryTargetSummary.ts still includes it through BINARY_ARCHITECTURES. The CLI/MCP output schemas therefore advertise Xtensa PE and Mach-O targets, although BinaryTarget permits Xtensa only for ELF.
Add xtensa to the runtime exclusion and test that summaries accept Xtensa ELF but reject those other combinations. The repository requires runtime schemas and exported types to agree when constrained values change. That requirement must be satisfied before merging.
Context Used: docs/agents/mcp-tooling.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/binaryTargetTypes.ts
Line: 72
Comment:
**Schemas allow impossible Xtensa targets**
This change excludes `xtensa` from `HeaderArchitecture`, but `headerArchitectureSchema` in `src/domain/liveBinaryTargetSummary.ts` still includes it through `BINARY_ARCHITECTURES`. The CLI/MCP output schemas therefore advertise Xtensa PE and Mach-O targets, although `BinaryTarget` permits Xtensa only for ELF.
Add `xtensa` to the runtime exclusion and test that summaries accept Xtensa ELF but reject those other combinations. The repository requires runtime schemas and exported types to agree when constrained values change. That requirement must be satisfied before merging.
**Context Used:** docs/agents/mcp-tooling.md ([source](https://github.com/morluto/preference/blob/main/docs/agents/mcp-tooling.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
XiaoBinGan
left a comment
There was a problem hiding this comment.
I traced xtensa through every consumer of BINARY_ARCHITECTURES and found one place where the change is incomplete, in a way tsc cannot see.
The finding. src/domain/binaryTargetTypes.ts correctly excludes xtensa from HeaderArchitecture (the type says a header-only family cannot claim it). But src/domain/liveBinaryTargetSummary.ts:16-21 builds the matching runtime schema from a hand-written list:
const headerArchitectureSchema = architectureSchema.exclude([
...ELF_METADATA_ARCHITECTURES,
...RAW_ONLY_ARCHITECTURES,
"hexagon",
"arm64_32",
]);"xtensa" is not in that list, and nothing in the file mentions it. So the type and the schema now disagree, and the schema wins at runtime:
| input | expected | actual |
|---|---|---|
format: "pe", architecture: "xtensa" |
rejected — xtensa is not a header family |
accepted |
format: "mach-o", architecture: "xtensa" |
rejected | accepted |
format: "dos-com", architecture: "xtensa" |
rejected | accepted |
format: "pe", architecture: "hexagon" |
rejected | rejected |
I called liveBinaryTargetSummarySchema.safeParse directly on those values to confirm it, rather than reasoning from the code. hexagon rejects in exactly the same four formats, which is what makes this a gap rather than a design choice: hexagon is excluded in both the type and the schema, and xtensa is now excluded only in the type.
Why no check caught it. architectureSchema.exclude([...]) is a runtime array literal; TypeScript has no way to tie it to the Exclude<…, "hexagon" | "xtensa" | "arm64_32"> in HeaderArchitecture. tsc --noEmit is 0 errors on this branch. This is the one shape of architecture addition that the compiler cannot enforce, so it has to be a checklist item.
The fix is one line — add "xtensa" beside "hexagon" at liveBinaryTargetSummary.ts:19. A test that asserts headerArchitectureSchema and HeaderArchitecture agree would be better still: this file is now the only place a new family has to be registered twice, and the second registration is invisible to the type system.
Two smaller notes on the PR.
src/domain/binaryTarget.ts:534-544 adds the second architecture === "xtensa" branch, but parseElf already returns through the earlier ok({...}) for ElfMetadataArchitecture. I checked that xtensa is not in ELF_METADATA_ARCHITECTURES (binaryTargetTypes.ts:52-56 lists mips, riscv, powerpc), so the new branch is reached — just worth confirming it is not dead code by intent of the earlier guard.
pr_screenshots/rea-10765-{before,after}.svg add a top-level directory that nothing references (git grep pr_screenshots in src/tests/docs returns nothing) and that is not in package.json's files. AGENTS.md closes with "Never commit binaries, … or local planning artifacts", and an illustrated before/after of a source diff is a planning artifact; the diff and the PR body already carry it.
What I could not verify: no Xtensa hardware, no Ghidra, and no ESP32-S3 binary here, so the claim that Ghidra's Xtensa language module admits these images is taken from the issue and the PR description. Everything above is source-level and reproducible on any host.
Admit ELF machine 94 as the canonical Xtensa family through Ghidra's header-selected import. Share generic-header exclusions between static target types and live CLI/MCP summaries, preserving ELF-only format constraints and other providers' decline paths. Fixes #10765. Adapted from #10774. Co-authored-by: Josh <[email protected]> Co-authored-by: gensokyo-dev <[email protected]>
Summary
Fixes #10765.
Xtensa ELF files (
EM_XTENSA = 94), including ESP32-S3 firmware, are now admitted through the normal Ghidra ELF path instead of being rejected before analysis.Problem and expected behavior
The ELF header parser did not recognize machine 94, so
parseElfreturnedunsupported ELF architecturebefore a provider could run. Even if that gate was opened, the canonical architecture enum and Ghidra admission set also lackedxtensa.Expected behavior is for Xtensa ELF files to produce the canonical
xtensatarget family, pass Ghidra support admission, and use Ghidra'sauto-from-headerlanguage selection. Other providers without a verified Xtensa lane should continue to decline it explicitly.Change and scope
xtensa.xtensato the canonical binary architecture set and ELF target metadata.xtensato Ghidra's supported architecture set.No new processor profile, calling-convention policy, CLI/MCP tool, generated catalog, or package/install behavior is included.
Contract and boundary impact
Semantic owner and earliest changed stage: ELF header parsing owns the machine-to-family fact; canonical target typing and Ghidra admission consume that fact.
Contribution scope fit and linked maintainer decision: routine support fix within existing ELF/Ghidra boundaries; maintainer scope decision not applicable.
CLI and MCP/tool-catalog contract: no schema or tool change; existing CLI/MCP artifact workflows can now reach the provider for this ELF family.
Provider, bridge, target-format, or platform compatibility: adds ELF Xtensa recognition; Ghidra uses its header-selected Xtensa language, while Hopper remains explicitly unsupported.
Evidence, artifact, provenance, or reconstruction contract: adds one canonical architecture value and preserves the existing target identity/evidence flow.
Target selection, authority, upstream behavior, and cleanup details: no new target execution, injection, mutation, network, or persistence behavior.
Generated metadata, package, or installation impact: none.
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
e_machine = EM_XTENSA (94)are rejected before analysis, although Ghidra supports Xtensa #10765 reports an ESP32-S3 ELF failing withunsupported ELF architecture: e_machine 94before analysis; source inspection confirms the missing parser and provider gates on the base revision. The issue reporter supplied real Ghidra verification, but that runtime was not available on this host.Before/after source-and-verification snapshots:
Validation performed
npm exec vitest -- run src/domain/binaryTarget.test.ts src/ghidra/GhidraProvider.behavior.test.ts src/hopper/HopperProvider.test.ts— 3 files passed; 363 tests passed.npm run check:fast— typecheck and lint passed; 2 tasks successful.npm exec oxfmt -- ...changed files...— formatting passed.xmllint --noout pr_screenshots/rea-10765-before.svg pr_screenshots/rea-10765-after.svg— both evidence assets parsed successfully.git diff --check— no whitespace errors.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.