Skip to content

fix(ghidra): reject contradictory NativeAOT reports - #759

Closed
kaoru0822-kitauji wants to merge 1 commit into
morluto:mainfrom
kaoru0822-kitauji:fix/ghidra-nativeaot-report-consistency
Closed

kaoru0822-kitauji wants to merge 1 commit into
morluto:mainfrom
kaoru0822-kitauji:fix/ghidra-nativeaot-report-consistency

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Reject NativeAOT extension reports whose non-recovery status contradicts their payload. A report labeled not_applicable, unsupported, or failed must now include an actionable nonblank reason, report zero method tables, and omit recovered type, derived-memory, and coverage payloads.

Problem and expected behavior

The NativeAOT adapter validator previously applied recovery-shape checks only to complete and partial reports. A producer response could therefore claim not_applicable while reporting recovered method tables, or omit the reason for that unavailable outcome, and still pass the authenticated bridge handshake. That lets contradictory producer metadata enter the session evidence boundary.

The validator should reject those reports as malformed while preserving discovery/version fields that a legitimate failed or unsupported analysis may have observed before stopping.

Change and scope

  • Add a non-recovery invariant to the NativeAOT producer validator.
  • Require a nonblank reason and the absence of recovered payloads for non-recovery statuses.
  • Add regression coverage across all three non-recovery statuses for contradictory table counts and null, empty, or whitespace-only reasons, while proving discovery/version context remains valid.
  • Keep the existing dedicated loader-failure envelope and successful recovery validation unchanged.

Related to #743.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra NativeAOT extension result admission, before provider output enters Evidence.
  • CLI/MCP/tool catalog: no schema or catalog change; malformed producer output now becomes the existing typed provider-adapter failure.
  • Provider/bridge/target compatibility: no Java bridge, target-format, host, or runtime coverage change.
  • Evidence/provenance: contradictory non-recovery metadata can no longer be admitted.
  • Process/authorization/cleanup: unchanged.

Evidence and regression coverage

  • Base reproduction: the new focused test failed on current main because validateGhidraExtensionResults returned null for a not_applicable report with method_tables: 1.
  • The same boundary also accepted null, empty, and whitespace-only non-recovery reasons.
  • After the fix, the extension boundary and surrounding provider behavior suites pass: 46 tests.
  • No real Ghidra run was required for this pure result-validation change.
  • Material unverified coverage: no real Ghidra/NativeAOT toolchain run, Windows run, or full deterministic test suite.

Validation performed

  • vitest run src/ghidra/extensions/GhidraExtensions.test.ts src/ghidra/GhidraProvider.behavior.test.ts --coverage.enabled=false — 46 passed.
  • npm exec [email protected] -- tsc --noEmit — passed.
  • npm run lint — passed with existing repository warnings and no changed-file warnings.
  • npm run lint -- --deny-warnings <changed files> — passed.
  • npm run knip — passed.
  • npm run metadata:check — passed.
  • Targeted oxfmt --check and git diff --check — passed.
  • npm run check could not complete in this container because the repository TypeScript 7 binary requires /proc/self/exe, which is unavailable here. A separate whole-tree formatter scan also encountered the environment's unavailable resident-memory syscall while checking an unrelated fixture; changed-file formatting passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Generated metadata, package, installation, or documentation impact: none.
  • Security/privacy: this strengthens an executable-extension trust boundary without expanding authority or retaining new data.
  • AI-assisted implementation and tests; I reviewed the final diff and validation output.

Review checklist

  • The PR has one focused outcome and the title follows type(scope): outcome.
  • A related issue is linked.
  • Tests cover changed observable behavior and meaningful failure paths.
  • No owning docs, public contracts, or generated metadata require updates.
  • Unsupported and failed outcomes remain explicit.
  • The final diff contains no unrelated cleanup or unsupported coverage claims.

@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Reviewed: non-recovery invariant (not_applicable/unsupported/failed must have non-blank reason, method_tables:0, no types/derived_memory/coverage payloads) is correctly placed entirely in src/ghidra/extensions/nativeaot/ before Evidence admission — no domain/app/contract change, failure reasons preserved as distinct messages, no identity guessing. Honest scoping with no real-Ghidra claim, 44 targeted tests. APPROVE. Two minor suggestions: parametrize the new test over all three statuses (currently only not_applicable), and add a positive test that discovery/version fields on non-recovery still validate.

@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Review — APPROVE

Related #743.

Summary

validateNativeAotReport gains a non-recovery invariant: not_applicable / unsupported / failed reports must carry a non-blank reason, method_tables: 0, and no types / derived_memory / coverage payloads — otherwise rejected as malformed before entering Evidence.

Verification

  • Layering: change lives entirely in src/ghidra/extensions/nativeaot/ (provider-owned boundary), validates the pinned producer representation before Evidence admission, and touches no domain, application, contract, or catalog code. No Java-bridge, target-format, host, or authority change.
  • Failure reasons preserved as distinct messages (recovery-omission vs. non-recovery-contradiction vs. malformed); nothing guesses identities — it only rejects contradictory ones.
  • Appropriately scoped real-verification claim: author explicitly states no real Ghidra/NativeAOT/Windows run and lists it as unverified, claiming only pure-validation behavior backed by 44 targeted tests.
  • Edge cases checked: reason null/empty/whitespace-only rejected; method_tables: 1 on not_applicable rejected (the base-behavior repro); loader-failure envelope bypass is safe (carries no contradicting fields); types: [] with method_tables: 0 rejected (!== undefined) — strict but defensible at a trust boundary.
  • CI: all 20 checks SUCCESS. No schema/catalog change — correct.

Suggestions (minor, non-blocking)

  1. src/ghidra/extensions/GhidraExtensions.test.ts:414 — the new test only exercises not_applicable. Consider parametrizing over all three statuses (it.each(["not_applicable", "unsupported", "failed"])) to lock the invariant (~3 extra lines).
  2. Consider a positive test that a non-recovery report with discovery / format_major / header_address set (but no payloads) still validates — this pins the "preserving discovery/version fields" half of the contract.

@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/ghidra-nativeaot-report-consistency branch 4 times, most recently from cae7282 to 8b4db34 Compare October 6, 2026 21:51
@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Superseded by #815, which integrated this change and has now merged (3af3811). Thanks @kaoru0822-kitauji for the fix and tests — much appreciated!

@morluto morluto closed this Oct 7, 2026
@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
@morluto morluto added the provider: ghidra Analysis provider / engine: ghidra label Nov 23, 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 provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants