Skip to content

fix(ghidra): warn when callee/caller reads stop at a truncated function body - #2360

Merged
morluto merged 1 commit into
morluto:mainfrom
sx4im:fix/2326-ghidra-truncated-body-warnings
Oct 13, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
sx4im:fix/2326-ghidra-truncated-body-warnings

Conversation

@sx4im

@sx4im sx4im commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2326. procedure_callees and procedure_callers returned a bare address list. When an inferred no-return call truncates Ghidra's analyzed function body, real call and caller edges outside the body were silently dropped with no warning. Both views now return the function-observation envelope (value + limitations) carrying noReturnCallLimitations notes, the same treatment the five other function views got in 69a8b3a.

Problem and expected behavior

Smallest trigger: read procedure_callees for a function whose body Ghidra cut short at an inferred no-return call. Before: the response carried the surviving edges only and no caveat, so a caller could not tell edges were missing. The provider design places such caveats in limitations. Expected: terminal-call observations appear in Evidence limitations for these two views, exactly as they already do for procedure_info, procedure_assembly, procedure_pseudo_code, read_function_instructions, and analyze_function.

Change and scope

  • bridge/ghidra/ReaGhidraBridge.java: procedureCalls now returns functionObservation(result, noReturnCallLimitations(...)) over the same instruction listing procedureInfo uses. No new helpers; the existing helper is reused verbatim.
  • src/ghidra/GhidraFunctionValues.ts: procedure_callees and procedure_callers join functionBoundaryObservationOperations, so the TS parser requires the envelope and surfaces its limitations into Evidence.
  • src/ghidra/GhidraAnalysisProfile.ts: boundary-observation contract versioned to ghidra-terminal-call-limitations-v2, so older unqualified snapshots cannot replay.
  • src/contracts/officialToolContracts.ts and docs/ghidra-provider.md: document the limitation for these views.

Contribution scope fit: ordinary fix within existing boundaries; no new capability, no execution or mutation behavior. Maintainer scope decision: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra Java bridge response shape for two operations; TS envelope parser owns the parse.
  • Contribution scope fit and linked maintainer decision: in-scope bug fix; not applicable.
  • CLI and MCP/tool-catalog contract: tool descriptions gain one sentence each; value schemas unchanged (still address lists).
  • Provider, bridge, target-format, or platform compatibility: bridge output shape changes for procedure_callees/procedure_callers (bare array to {value, limitations}); TS parser is the only consumer and expects the new shape. Other providers untouched.
  • Evidence, artifact, provenance, or reconstruction contract: limitations now carry terminal-call observations for these views; raw result shape follows the envelope convention.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable; read-only bridge.
  • Generated metadata: none committed; CI generates catalogs.

Expected effects:

  • 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

  • Tests added or updated:
    • src/ghidra/GhidraFunctionValues.test.ts: new red-green test requiring the envelope for both operations (bare array rejected; envelope with limitations preserved). Test-local operation set updated.
    • tests/boundary/mcp/ghidraEvidenceMcp.test.ts: terminal-call qualification test extended to procedure_callees/procedure_callers, proving limitations flow through Evidence and snapshot replay.
    • tests/boundary/mcp/ghidraMcpHarness.ts and src/ghidra/GhidraProvider.behavior.test.ts: bridge fixtures updated to the envelope shape.
  • Base reproduction or other evidence: the new unit test failed before the fix (bare array accepted, ok: true) and passes after. No Ghidra host available here, so no real-provider reproduction of a truncated body; the Java change is a mechanical wrap identical to the existing procedureInfo call pattern.
  • User-visible CLI/MCP output: unchanged value shape; limitations now include terminal-call notes, e.g. "Ghidra Listing reports a terminal call at 0x... to 0x...; fallthrough is excluded by Ghidra's flow model."
  • Remaining proof gaps: real Ghidra host lane (verify-real-ghidra-function) not run locally; the Java-side wrap is unverified against a live bridge beyond matching the established pattern.

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:focused -- src/ghidra/GhidraFunctionValues.test.ts — 43 passed (new envelope test red before, green after)
  • npm run test:focused -- tests/boundary/mcp/ghidraEvidenceMcp.test.ts src/ghidra/GhidraProvider.behavior.test.ts — 53 passed
  • 8 MCP boundary test files using the Ghidra harness (analysisViewMcp, ghidraCompactReferencesMcp, ghidraFailureDiagnostics, ghidraInventoryMcp, ghidraNativeApiMcp, ghidraRoutingMcp, inlineEvidenceCompositionMcp, ghidraEvidenceMcp) — 25 passed
  • npm run check:fast — typecheck + lint successful
  • npm run docs:check — passed
  • npm run verify:test-discovery — 982 test files discovered exactly once
  • Remote head/tree verified: fork branch fix/2326-ghidra-truncated-body-warnings at 926bd5b, tree 378c4f4 identical to local commit, parent fd95880 (upstream main).

Compatibility, safety, and release

  • Breaking changes or migration steps: bridge wire shape for the two operations changes from bare array to {value, limitations}; the in-repo TS parser is updated in the same change. No migration for callers of the MCP/CLI surface, where the value schema is unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: real Ghidra host lane unavailable in this environment (no Ghidra installed); simulated-provider harness and source tests cover the parsing and evidence flow.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only change; no new authority.

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.

…on body

procedure_callees and procedure_callers returned a bare address list, so an
inferred no-return call that truncates Ghidra's function body silently dropped
real edges (fixes morluto#2326). Wrap both views in the function-observation envelope
with noReturnCallLimitations, matching procedure_info, procedure_assembly,
procedure_pseudo_code, read_function_instructions, and analyze_function
(precedent: 69a8b3a). Version the boundary-observation contract to
ghidra-terminal-call-limitations-v2 so older snapshots cannot replay
unqualified results.

Validation: red->green unit test for the envelope requirement, MCP boundary
evidence test extended for both views (limitations retained through Evidence
and snapshot replay), 8 harness test files + ghidra behavior tests green,
check:fast, docs:check, verify:test-discovery green. Real Ghidra host lane
unavailable here (no Ghidra installed); Java change mirrors the existing
procedureInfo call pattern.
@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.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: This PR works on real Ghidra. The callee and caller reads now carry the same terminal-call line as procedure_info, and the edge lists do not change. It does not cover the cleanup blocks from #2326, which is fine.

I filed #2326. Thanks, sx4im, for the quick fix. I ran head d9d39ef and base 3ee6ff4 on real Ghidra 12.1.4 over MCP. The target was a stripped esmtool from OpenMW 0.51.0 (GPL-3.0). I read 163 functions per build, twice, with the same counts.

Results

Group Functions Head matches procedure_info Base lines Edges and coverage same as base
Cause A: cut after a listed no-return call 18 18 0 18
Cause A and B together 21 21 0 21
Cause B only, no line in procedure_info 33 33 0 33
Cause B only, line about another call 11 11 0 11
No call lost, no line 17 17 0 16
No call lost, with line 11 11 0 11
Others I read to be thorough 52 52 0 52

On head, callee and caller reads match procedure_info in all 163 functions. No function gets a line that procedure_info lacks, or the reverse. get_call_graph and trace_call_path pass the lines into their limitations list. Their graphs and not_reached results stay the same. One callers list (0x13e480) changes between two sessions of the same build, on base and on head alike, so it is not this PR.

Cause B and callers

#2326 asks for cause B as its own line, so I see it as a follow-up to this PR. For cause B only, head stays silent in 33 of 44 functions. In the other 11, the line names a different call, so it does not explain the cut.

A missing caller is lost in the caller's body, but the read checks the target's body. In 12 cases a real caller was missing. No head read carried that caller's line. #2326 said a read on the target can't see it.

Tests

The PR's 3 test files pass on Node 22.23.1, 24.18.0 and 26.11.1, with 96 tests each. On base, with only the PR's test changes copied in, 4 tests fail and 92 pass. The 4 are the 2 new envelope tests, the relationship-coverage fixture and the v2 profile check.

Not run

  • The whole file, and any other program.
  • The repo's full test suite and npm run verify:ghidra.
  • build_call_path, analyze_function and compare_functions.
  • Hopper, IDA and Windows.
Table of 62 functions: 18 cause A, 16 cause B, 28 with no call lost

Cause is the kind of gap in front of each lost call. A is a gap after a listed no-return call. B is a gap after a return or jump. Real calls come from objdump on the unstripped file. Returned is the size of the head callee list. Info lines is the count of terminal-call lines in procedure_info. Head lines is that count in the callee read, then in the caller read. Same edges means the callee list, caller list and coverage match base. Both runs gave the same row. One row says no: 0x13e480, the callers list that changes between sessions. The 52 others are not in this table. They are 42 more functions from my whole-file search for cause B, plus the 10 targets in the callers fold.

Address Cause Real calls Returned Info lines Head lines Same edges
0x132c50 A 11 7 3 3 and 3 yes
0x122ff0 A 19 1 1 1 and 1 yes
0x115fb0 A 16 1 1 1 and 1 yes
0x122dae A 15 1 1 1 and 1 yes
0x124a43 A 18 4 1 1 and 1 yes
0x11f06c A 14 1 1 1 and 1 yes
0x120dc6 A 14 1 1 1 and 1 yes
0x11d8a0 A 15 3 1 1 and 1 yes
0x1228de A 16 4 1 1 and 1 yes
0x123da2 A 13 1 1 1 and 1 yes
0x115d09 A 13 2 1 1 and 1 yes
0x11a948 A 12 1 1 1 and 1 yes
0x12031c A 12 1 1 1 and 1 yes
0x116d4c A 11 1 1 1 and 1 yes
0x119296 A 11 1 1 1 and 1 yes
0x11a1f4 A 11 1 1 1 and 1 yes
0x11cf16 A 11 1 1 1 and 1 yes
0x122c9e A 11 1 1 1 and 1 yes
0x112cc0 B 5 2 1 1 and 1 yes
0x14a000 B 34 1 1 1 and 1 yes
0x123edc A+B 18 6 1 1 and 1 yes
0x1133b2 A+B 21 10 1 1 and 1 yes
0x112d84 B 5 2 1 1 and 1 yes
0x131420 B 5 2 0 0 and 0 yes
0x1329e0 B 6 3 0 0 and 0 yes
0x1e7280 B 4 2 0 0 and 0 yes
0x134e90 B 4 2 0 0 and 0 yes
0x1e6860 B 4 2 0 0 and 0 yes
0x1dd7b0 B 8 4 0 0 and 0 yes
0x170640 B 5 3 0 0 and 0 yes
0x13fb00 B 5 4 0 0 and 0 yes
0x1f0030 A+B 29 19 14 14 and 14 yes
0x11bad2 A+B 10 5 1 1 and 1 yes
0x119190 B 8 1 0 0 and 0 yes
0x12a890 no lost call 0 0 0 0 and 0 yes
0x12f0f0 no lost call 0 0 0 0 and 0 yes
0x139090 no lost call 0 0 0 0 and 0 yes
0x13e480 no lost call 0 0 0 0 and 0 no
0x1586d0 no lost call 1 1 0 0 and 0 yes
0x158f20 no lost call 2 2 0 0 and 0 yes
0x15f2b0 no lost call 9 9 0 0 and 0 yes
0x16fe90 no lost call 1 1 0 0 and 0 yes
0x175670 no lost call 1 1 0 0 and 0 yes
0x17a770 no lost call 0 0 0 0 and 0 yes
0x18c2b0 no lost call 2 2 0 0 and 0 yes
0x194860 no lost call 0 0 0 0 and 0 yes
0x1a7360 no lost call 0 0 0 0 and 0 yes
0x1d36f0 no lost call 1 1 0 0 and 0 yes
0x1de600 no lost call 3 3 0 0 and 0 yes
0x1e63d0 no lost call 0 0 0 0 and 0 yes
0x1f67d0 no lost call 2 2 0 0 and 0 yes
0x130120 no lost call 1 1 1 1 and 1 yes
0x150ba0 no lost call 11 12 2 2 and 2 yes
0x158b40 no lost call 0 1 1 1 and 1 yes
0x15aab0 no lost call 1 1 1 1 and 1 yes
0x16bd10 no lost call 1 1 1 1 and 1 yes
0x180cf0 no lost call 4 6 2 2 and 2 yes
0x19c2c0 no lost call 9 9 3 3 and 3 yes
0x1accb0 no lost call 1 2 1 1 and 1 yes
0x1bab40 no lost call 5 6 2 2 and 2 yes
0x1c9330 no lost call 19 26 44 44 and 44 yes
0x1ea490 no lost call 3 3 1 1 and 1 yes
Callers: 12 cases with a missing caller

The first ten are the 10 targets from #2326. The last two are missing callers I found among the 50 functions there. In all 12, the call sits outside the caller's body. Target's own lines is the count in the target's procedure_info. Lines in the head read is the count in the head caller read of the target. None of them came from the missing caller's body. The head read had no line at all in 3 cases, and a line about the target's own calls in 9.

Target Missing caller Target's own lines Lines in the head read From the missing caller
0x13ce10 0x14a000 0 0 none
0x1dd750 0x122ff0 1 1 none
0x1d2670 0x115fb0 1 1 none
0x133960 0x122dae 3 3 none
0x1f6040 0x124a43 6 6 none
0x1bf7f0 0x11f06c 2 2 none
0x112880 0x120dc6 1 1 none
0x112600 0x11d8a0 1 1 none
0x112ad0 0x1228de 1 1 none
0x1e6520 0x123da2 0 0 none
0x13e480 0x14a000 0 0 none
0x1accb0 0x11a1f4 1 1 none
Call graph and trace: 6 cases

The lines appear in the result's limitations list. They do not appear in the per-node limitations or in the Evidence limitations.

Call Terminal-call lines in limitations: base, head goal_status: base, head Nodes and edges same
get_call_graph 0x122ff0, forward 0, 2 n/a, n/a yes
get_call_graph 0x112cc0, forward 0, 3 n/a, n/a yes
get_call_graph 0x1dd750, backward 0, 1 n/a, n/a yes
trace_call_path forward, to 0x1dd750, from 0x122ff0 0, 2 not_reached, not_reached yes
trace_call_path forward, to 0x112930, from 0x112cc0 0, 3 not_reached, not_reached yes
trace_call_path backward, to 0x122ff0, from 0x1dd750 0, 1 not_reached, not_reached yes
Commands
Step Command Result
Builds npm ci, npm run build, npm run test:prepare in head and in base (Node 24.18.0) 0 each
Sessions 4 Ghidra sessions: base, head, base again, head again. Each ran on Node 24.18.0 and made 496 MCP calls inside a systemd-run scope with an 8 GB cap all closed
Reads open_binary, procedure_info, procedure_callees, procedure_callers, get_call_graph, trace_call_path no tool errors
Real calls objdump -d on the unstripped file, as in #2326 0
Cleanup blocks decode the file's exception table with pyelftools and match each landing pad to a gap 0
Tests on head npm run test:focused on 3 files, Node 22, 24 and 26 0 each
Tests on 7 more files that use the same harness npm run test:focused, Node 24 0
Tests on base same 3 files, with only the PR's test changes copied in 1, with 4 tests failed
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: d9d39ef / 3ee6ff4 (fix(ghidra): warn when callee/caller reads stop at a truncated function body #2360)
  • Other: Ghidra 12.1.4 (Apache-2.0) with JDK 21.0.12.1; GNU objdump 2.46.1; pyelftools 0.33
  • Target: stripped esmtool from the OpenMW 0.51.0 Linux tarball, sha256 68510563bcb9026f0554712307be115d56d3e3f7167968df3b832886f28ff585
  • Shared box: other test jobs ran at the same time

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable defect was identified.

Summary

procedure_callees and procedure_callers now return the existing function-observation envelope. Their address lists stay unchanged, while terminal-call warnings reach Evidence.

  • Caller and callee reads now include Ghidra’s terminal-call caveats.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Ghidra caller or callee read"] --> B["Address list + terminal-call warnings"]
  B --> C["Envelope parser"]
  C --> D["Evidence: unchanged value + limitations"]
  D --> E["Snapshot bound to v2 analysis profile"]
Loading

Reviews (1) · Last reviewed commit: "fix(ghidra): warn when callee/caller rea..." · Reviewed by Greptile

@morluto
morluto merged commit 6637161 into morluto:main Oct 13, 2026
35 checks passed
@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.

[Bug] Callee and caller reads give no warning when Ghidra's function body stops short

3 participants