Skip to content

fix(targets): project invalid raw-binary loads as caller input - #2004

Merged
morluto merged 2 commits into
morluto:mainfrom
jimpablo:fix/raw-binary-load-input-classification
Oct 12, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
jimpablo:fix/raw-binary-load-input-classification

Conversation

@jimpablo

@jimpablo jimpablo commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2002. Invalid caller-supplied raw-binary load choices (--target-format/--architecture/--entry-point) were projected as problems with the target file: target_unavailable/unsupported_target (or unavailable) with remediation that told the caller to review the file. They now project as caller input — invalid_request/invalid_input, retryable, with remediation naming the load options by their real spellings on both surfaces. An empty file remains a target refusal, and the DOS COM target-kind pairing is reclassified with the same caller-input treatment.

Problem and expected behavior

  • Smallest trigger: rea analyze f.bin --target-format raw-binary --architecture arm --entry-point 0x1 on any readable non-empty file reported unsupported_target with "Review the reported file-format reason and select a supported, well-formed target." — the file was fine; only the entry alignment was wrong.
  • Violated invariant: identity and failure classification belong to the producer. BinaryTargetResolver labeled every admitRawBinary rejection file_format_rejected, although only the empty-file extent is a property of the target; the format-pairing rejection carried no constraint at all and fell to the generic "Check that the path exists…" advice.
  • New behavior: caller-input rejections (missing architecture, malformed/misaligned/out-of-width entry, format pairing, target-kind pairing for both raw-binary and DOS COM) carry a new load_selection_rejected constraint and project as invalid_request/invalid_input with "Correct the reported load argument (--target-format, --architecture, or --entry-point on the CLI; format, architecture, or entry_point through MCP) and retry."; the empty-file extent keeps file_format_rejected → target_unavailable/unsupported_target.

Change and scope

  • src/domain/rawBinary.ts: admitRawBinary rejections are now structured (reason + owning classification: load_selection_rejected for caller input, file_format_rejected for the empty-file target refusal), so the classification is derived at the owner instead of being re-inferred downstream.
  • src/application/BinaryTargetResolver.ts: raw-binary rejections carry the admission's constraint; both target-kind pairings (raw-binary and DOS COM) use it too, so the analogous DOS COM conflict no longer advises selecting a different file; the architecture/entry pairing now reuses rawBinarySelectionError (its existing message owner, already used by the MCP contract layer) instead of a duplicated inline string.
  • src/domain/analysisErrorPresentation.ts + analysisErrorProjection.ts: load_selection_rejected maps to category invalid_input, code invalid_request, its own remediation (option names verified against src/cli/options.ts and src/contracts/sessionLifecycleInputs.ts, following the cross-adapter naming the WASM remediation uses), and drops the path-checking advice from the user message.
  • The constraint is named load_selection_rejected rather than raw-binary-specific so one value covers both headerless formats' caller-input rejections honestly.
  • Not included: DOS COM length validation keeps file_format_rejected (it is a property of the file); Doctor's inspectTarget passes no load arguments and cannot observe these rejections, so it is unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: raw-binary admission classification in src/domain/rawBinary.ts, consumed by target resolution before any provider selection.
  • CLI and MCP/tool-catalog contract: no tool, parameter, or schema change. invalid_request/invalid_input are existing projection values; the new load_selection_rejected string appears in details.constraint (a free-form detail field).
  • Provider, bridge, target-format, or platform compatibility: none; admission happens before provider selection.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none (docs:check green; no code enumeration changed).

Evidence and regression coverage

  • Tests added or updated: src/domain/rawBinary.test.ts asserts the owning classification for the unaligned, width-overflow, malformed/missing-argument, and empty-file rejections; tests/boundary/filesystem/targetDiagnostics.test.ts projects the misaligned arm entry, the x86 width overflow, the pairing-without-format, the raw-binary and DOS COM target-kind pairings, and the empty file through the public parseBinaryTarget → projectAnalysisError boundary, including message text, remediation, and absence of path advice; tests/boundary/cli/rawBinaryCli.test.ts now pins invalid_request for the missing-architecture and unaligned-arm64 cases through the real CLI.

  • Base reproduction: with the source changes stashed, the new filesystem-boundary tests fail on e19879328 (they receive target_unavailable/unsupported_target/unavailable); the empty-file test passes on base by design, pinning the behavior that must not change. The CLI boundary expectations fail on base with the new code and pass with it.

  • Real public CLI before/after on a 64-byte fixture (macOS 27 arm64, Node 24.18.0), matching the issue's table:

    Invocation Before After
    --target-format raw-binary --architecture arm --entry-point 0x1 target_unavailable/unsupported_target, "Review the reported file-format reason…" invalid_request/invalid_input, retryable, remediation naming the CLI/MCP option spellings
    --target-format raw-binary --architecture x86 --entry-point 0xffffffffff same as above invalid_request/invalid_input
    --architecture arm --entry-point 0x0 (no format) target_unavailable/unavailable + "Check that the path exists…" invalid_request/invalid_input, no path advice
    empty file, valid load arguments target_unavailable/unsupported_target unchanged
  • Remaining proof gaps: MCP-path behavior is covered through the shared projection, not a separate stdio MCP session run; non-macOS hosts were not exercised (path is platform-neutral).

  • 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:focused -- src/domain/rawBinary.test.ts tests/boundary/filesystem/targetDiagnostics.test.ts tests/boundary/cli/rawBinaryCli.test.ts — 41 passed (including real-CLI boundary runs)
  • npm run check:fast — green
  • npm run check — green (typecheck, lint, format, knip, metadata, architecture guards)
  • npm run docs:check — green
  • Real rea analyze runs before/after as tabled above
  • Base-failure check via git stash of the source changes

Compatibility, safety, and release

  • Breaking changes or migration steps: none required. The error code/category for these rejections changes from target-shaped to input-shaped, which is the requested behavior; callers keying on details.constraint === "file_format_rejected" for raw-binary argument errors (introduced in [Bug] NE, LE and LX refusals give misleading "check the path" advice #1979, four days old) see the new load_selection_rejected value instead.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (admission precedes provider selection); real CLI on macOS 27 arm64.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; no new subprocess, path, or write behavior.

Review checklist

  • This PR addresses a concrete problem, not an unscoped refactor.
  • The PR has one focused outcome, and the title follows type(scope): outcome.
  • Related issue is linked.
  • 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 (tabled above).
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-12T01:31:22.545357Z 6deebe0 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.

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

I filed #2002 and had a local fix in progress when this opened, so I'll leave this one to you. Two things my branch hit that this diff doesn't touch yet:

  1. tests/boundary/cli/rawBinaryCli.test.ts pins code: "target_unavailable" for two of these cases: --target-format raw-binary without --architecture (line 35), and the unaligned arm64 --entry-point 0x8000001 (line 64). With this change both project as invalid_request, so that boundary suite should fail on its next shard run unless the expectations are updated.
  2. The DOS COM counterpart in BinaryTargetResolver ("DOS COM format requires an executable target kind") is the same kind of caller target-kind conflict as the raw-binary one this PR reclassifies, but it is still labelled file_format_rejected, so it keeps the "select a supported, well-formed target" advice.

Verified locally through the real CLI on e19879328; the empty-file control stays file_format_rejected as intended.

@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: 21cc7c5b11

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/analysisErrorPresentation.ts Outdated
error instanceof BinaryTargetError &&
error.constraint === "raw_binary_load_rejected"
)
return "Correct the reported raw-binary load argument (target_format, architecture, entry_point) and retry.";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use public raw-binary option names in remediation

When this new branch handles any raw_binary_load_rejected, the remediation tells both adapters to correct target_format, but that is not a caller input on either surface. I checked the CLI contract and guide (src/cli/options.ts:39-43, docs/raw-binary.md:9-23), which expose --target-format/--entry-point, and the MCP contract (src/contracts/sessionLifecycleInputs.ts:33-50), which exposes format/entry_point. A user following this action can therefore submit an unknown flag or field; name both surface spellings (or avoid parameter identifiers) in this shared message.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6deebe0: the remediation now names the real option spellings on both surfaces — --target-format, --architecture, or --entry-point on the CLI and format, architecture, or entry_point through MCP — following the cross-adapter naming the WASM remediation already uses.

@jimpablo

Copy link
Copy Markdown
Contributor Author

Thank you — both points addressed in 6deebe0:

  1. rawBinaryCli.test.ts expectations updated for the missing-architecture and unaligned-arm64 cases; the suite passes locally with the new invalid_request codes. (My earlier sweep excluded that file by a filename filter — good catch.)
  2. The DOS COM target-kind pairing now carries the same caller-input classification. To keep one constraint honest across both formats it is named load_selection_rejected rather than raw_binary_…, with a boundary test for the DOS COM case.
  3. The remediation now names the real option spellings on both surfaces (--target-format/--architecture/--entry-point on the CLI, format/architecture/entry_point through MCP), per the Codex review.

@morluto
morluto merged commit edf4624 into morluto:main Oct 12, 2026
29 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid raw-binary load choices are reported as unsupported or missing targets

3 participants