Repository navigation
fix(ghidra): report JVM heap exhaustion as a memory constraint - #4275
RishTheFish21 wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] This PR appears safe to merge; the earlier concern about heap advice is fixed. SummaryGhidra failures with a retained JVM
No new actionable issues were found. Whether another PR supersedes this one could not be checked because GitHub credentials were unavailable. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Failed Ghidra session] --> B{Cancelled or remote?}
B -->|Yes| C[Keep existing error]
B -->|No| D{Retained output contains OutOfMemoryError?}
D -->|No| C
D -->|Yes| E[Return memory resource_constraint]
E --> F{Heap failure?}
F -->|Yes| G[Suggest larger heap within host limits]
F -->|No| H[Suggest checking host memory and relevant limits]
Reviews (2) · Last reviewed commit: "fix(ghidra): advise a larger heap only f..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd2ee3785f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| import type { GhidraSessionError } from "./GhidraSessionError.js"; | ||
|
|
||
| const JAVA_OUT_OF_MEMORY = | ||
| /java\.lang\.OutOfMemoryError(?::[ \t]*([^\r\n]*))?/u; |
There was a problem hiding this comment.
Restrict heap guidance to heap-specific OOMs
When Ghidra emits java.lang.OutOfMemoryError: unable to create native thread (which can be caused by OS thread/process limits) or Metaspace, this regex accepts it exactly like Java heap space; ghidraMemoryExhaustionError then labels it a memory constraint and directs the caller to increase GHIDRA_HEADLESS_MAXMEM, although GhidraJavaLaunch.ts uses that setting only for -Xmx. This can misstate the controlling resource and provide ineffective remediation, so apply heap guidance only to heap/GC details or preserve non-heap applicability as unknown.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
Drain output within caller bounds at asynchronous completion owners and classify JVM exhaustion from the failing operation only. Preserve raw-byte scope, credential redaction, configured heap provenance, cancellation and exact cleanup failures. Validation uses controlled processes and provider fixtures; native Ghidra OOM execution was not repeated. Refs #4241, #4275 Co-authored-by: Syed Rishad <[email protected]>
Report the JVM memory area (heap, metaspace, native, unknown) and give non-heap out-of-memory errors guidance that does not rely on GHIDRA_HEADLESS_MAXMEM.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf884f41ef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ): AnalysisResourceConstraintError | undefined => { | ||
| if (failure.kind === "cancelled" || failure.kind === "remote") | ||
| return undefined; | ||
| const observed = ghidraJavaOutOfMemory(failure.diagnostics); |
There was a problem hiding this comment.
Detect OOM before truncating process output
When a Ghidra session emits more than GHIDRA_PROCESS_DIAGNOSTIC_BYTES (8 MiB) before the exception, ProviderProcessSupervisor.#capture stops retaining later bytes and only marks the snapshot truncated, so this downstream scan never sees an OOM printed at the end and the failure remains execution_failure or provider_timeout. Capture a structured OOM observation at the Ghidra process-output boundary while draining instead of deriving it only from the bounded diagnostic prefix.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
|
Conflict check from the CI & conflict-fix track: main's d52a488 ("fix(ghidra): retain scoped failures through process finalization", Refs #4241, #4275, co-authored from this PR) already lands this change. It classifies JVM |
Summary
When Ghidra's JVM runs out of heap during import or analysis, REA reports a generic
execution_failurethat tells the caller to runrea doctor. Doctor reports Ghidra as healthy, so the advice leads nowhere. The real cause (java.lang.OutOfMemoryError: Java heap space) is only visible deep insidedetails.diagnostics.stdout.text.Now, when a failed Ghidra session's own output shows a JVM
OutOfMemoryError, REA reportsresource_constraintwithresource: "memory", the heap size it launched Ghidra with, and memory-specific remediation.Fixes #4241
Problem and expected behavior
docs/binary-diagnostics.mdsays memory allocation failures useresource_constraint, with effective limits (or an explicit unknown) and memory-specific guidance. No Ghidra path recognizedOutOfMemoryError, so every heap exhaustion was projected asProviderAdapterError(execution_failure), or as a timeout if the deadline hit first.Smallest trigger: any target large enough to exhaust a small heap, e.g.
GHIDRA_HEADLESS_MAXMEM=128M rea inspect "$(command -v node)" --provider ghidra --json.Change and scope
src/ghidra/GhidraMemoryExhaustion.ts: looks forjava.lang.OutOfMemoryError(with its detail, e.g. "Java heap space") in the retained Ghidra process stdout/stderr. When found, the failure becomesAnalysisResourceConstraintError("memory"):reported_limits.jvm_max_heapis the heap REA launched with, ornullif unknown.GHIDRA_HEADLESS_MAXMEMabove that value or skip heavy analyzers withREA_GHIDRA_DISABLED_ANALYZERS, then reopen. It also notes thatrea doctordoesn't check heap size.remote) failures and cancellations are unchanged.jvm_max_heap.-Xmxactually passed to the JVM.GHIDRA_HEADLESS_MAXMEM/GHIDRA_MAXMEMis reported. Otherwise it stays unknown.docs/installation.md: documents the new classification under "Ghidra heap and CPU controls".Not included: the issue's second request (naming
REA_GHIDRA_STARTUP_TIMEOUT_MSin startup-timeout remediation) and the optional "Untested Go version" limitation. Both touch different code paths, so I'd do them separately.Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
projectPrimarySessionErrorinsrc/ghidra/GhidraProviderClient.ts); launch diagnostics inGhidraLauncher.ts/GhidraDiagnostics.ts.resource_constraintcode instead ofexecution_failure/provider_timeout. No schema change.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): None.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/ghidra/GhidraMemoryExhaustion.test.ts: readsOutOfMemoryErrorwith and without detail from stdout and stderr; bounds long details; ignores mentions outside the process streams. Heap selection uses the last POSIX-Xmx, and Windows reports only explicit settings.src/ghidra/GhidraProvider.behavior.test.ts: a process failure with heap exhaustion in stdout projects toresource_constraintwithjvm_max_heap: "4G"and the new remediation. A timeout withGC overhead limit exceededand no recorded heap reportsjvm_max_heap: null. Failures without an OOM, and bridge-reported failures, are unchanged.tests/boundary/providers/ghidra/ghidraJavaLaunch.test.ts: a real launch recordsjvmMaxHeap: "1G"and diagnostics expose it.GHIDRA_HEADLESS_MAXMEM=128M rea inspect "$(command -v node)" --provider ghidra --json:"code":"execution_failure". The only mention of the cause is buried in stdout diagnostics:OutOfMemoryError: Java heap space\n\tat java.base/java.lang.Long.valueOf(...)."code":"resource_constraint","jvm_max_heap":"128M", messageGhidra's JVM ran out of memory (java.lang.OutOfMemoryError: Java heap space) with a maximum heap of 128M.OutOfMemoryErrorprinted earlier in a long session will classify a later process failure as memory too, since the classification reads the session's retained output.For evidence-bearing changes:
Validation performed
npm run test:focused -- src/ghidra/GhidraMemoryExhaustion.test.ts src/ghidra/GhidraProvider.behavior.test.ts tests/boundary/providers/ghidra/ghidraJavaLaunch.test.ts: passednpm run check:fast: passednpm run lint: passednpm run knip: passednpm run docs:check: passedexecution_failure→resource_constraintwithjvm_max_heap: "128M"Compatibility, safety, and release
execution_failurefor Ghidra heap exhaustion now receiveresource_constraint(resource: "memory"). Other failures are unchanged.Author readiness
Human owner: @RishTheFish21
Before merge
type(scope): outcome.