[PR #2361] [MERGED] fix(ghidra): bound the Java version probe output #5187

Closed
opened 2026-10-31 01:04:39 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2361
Author: @DeryFerd
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/ghidra-probe-output-budget


📝 Commits (1)

  • 4a46eed fix(ghidra): bound the Java version probe output

📊 Changes

2 files changed (+50 additions, -1 deletions)

View changed files

📝 src/ghidra/GhidraInstallation.ts (+10 -1)
📝 tests/boundary/filesystem/ghidraJavaProbe.test.ts (+40 -0)

📄 Description

Summary

The Ghidra installation check runs the caller-selected Java launcher with -XshowSettings:properties -version to read java.version, java.home, and the VM name. That probe captured stdout and stderr with maxBuffer set to Number.POSITIVE_INFINITY, so a launcher that prints without limit could grow the capture until REA ran out of memory. This change gives the probe a 1 MiB capture budget, the same budget REA already uses for other Java listings. There is no linked issue.

Problem and expected behavior

inspectGhidraInstallation resolves the Java command from JAVA_HOME or PATH and calls probeJava on the installation host. In the production host, probeJava is a synchronous spawnSync whose options set maxBuffer: Number.POSITIVE_INFINITY. Node buffers every byte the child writes to stdout and stderr, and with no cap those buffers can reach whatever the child produces. A JVM that is misconfigured, wrapped by a script that echoes a large banner, or simply hostile can therefore make a read-only installation check consume unbounded memory.

The smallest trigger is a Java launcher that writes more than the capture budget while the probe is running. The violated invariant is that a bounded, read-only installation check should never allocate memory in proportion to a child's unbounded output. The expected behavior is that a probe which produces more text than a sane JVM ever would is treated as a probe that could not be read, not as a reason to keep allocating.

Change and scope

Add a module constant JAVA_PROBE_MAX_OUTPUT_BYTES = 1024 * 1024 next to the existing EXECUTABLE_HEADER_PROBE_BYTES, and pass it as maxBuffer in probeJava. One mebibyte is far more than a well-behaved JVM needs, since -XshowSettings:properties prints a few kilobytes. It is also the budget REA already chose for the analogous Java module listing in src/android/JadxConfiguration.ts, so the two Java probes now agree on what "too much output" means.

When the child exceeds maxBuffer, spawnSync returns an ENOBUFS error and a null status. The probe already bails on any error or non-zero status and returns no observation, so the overflow path needs no new branch. javaCheck then reports the Java check as failed with runtime_missing, which is the same outcome the check already produces whenever the probe yields nothing.

I did not change the timeout, the argv, the encoding flags, or the parsing. I also did not add a distinct rejection code for an over-budget probe. The installation check has no "unknown" status to carry, and runtime_missing is the existing code for "the probe produced no observation", so a separate code would be a larger contract change than this fix needs.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/ghidra/GhidraInstallation.ts, in the production GhidraInstallationHost.probeJava implementation. The observation type and the javaCheck mapping are unchanged.
  • Contribution scope fit and linked maintainer decision: routine fix inside existing boundaries. The probe reads Ghidra's application.properties and runs the caller-selected Java launcher, both of which the installation check already did. Not applicable for a maintainer scope decision.
  • CLI and MCP/tool-catalog contract: no change. No tool schema, catalog entry, or handler changes.
  • Provider, bridge, target-format, or platform compatibility: no change. The bounded probe behaves the same on every platform.
  • Evidence, artifact, provenance, or reconstruction contract: the Java check still reports its detail and remediation. An over-budget probe loses the truncated text, which the probe already discards on any failure.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none new. The probe does not touch the analysis target.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none. No generated catalog, skill, or package file changes.

Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible.

  • 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: tests/boundary/filesystem/ghidraJavaProbe.test.ts gains one case, "bounds the Java version probe and reports an over-budget probe as a failed Java check". It mocks spawnSync to return status: null with an ENOBUFS error, the shape Node produces when the capture overflows, and asserts that the probe passed maxBuffer: 1024 * 1024, that no Java version is reported, that the configured JAVA_HOME is preserved, and that the Java check is { status: "failed", code: "runtime_missing" }.
  • Base reproduction or other evidence: the new case fails on the unmodified source. With maxBuffer: Number.POSITIVE_INFINITY, the assertion expect(options.maxBuffer).toBe(1024 * 1024) reports - Infinity + 1048576. That is the red state this change fixes.
  • User-visible CLI/MCP output (if applicable): the Java installation check is what surfaces in rea doctor and provider diagnostics. An over-budget launcher now produces the same check shape a launcher that cannot be read produces, { name: "java", status: "failed", code: "runtime_missing" }, and the detail line falls back to the launcher command while the remediation still tells the caller how to point JAVA_HOME at a supported JDK.
  • Remaining proof gaps: the case is a boundary test with a mocked spawnSync. I did not reproduce the memory growth with a real unbounded JVM, because that would mean deliberately exhausting the machine. The Node maxBuffer and ENOBUFS behavior the test relies on is stable across the supported Node versions, and CI runs the real suite.

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

  • npx vitest run tests/boundary/filesystem/ghidraJavaProbe.test.ts — 4 passed, including the new bounded-probe case.
  • npm run check:fast — typecheck and lint passed, run as the pre-push hook on the rebased commit.
  • npx vitest run src/ghidra/GhidraInstallation.test.ts src/ghidra/GhidraDoctor.test.ts — GhidraInstallation.test.ts passed fully. GhidraDoctor.test.ts reported 2 failures in its Windows native-authority group. I reproduced those same 2 failures on an unmodified checkout of main, so they are pre-existing and unrelated to this change.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A launcher that stays under 1 MiB behaves exactly as before.
  • Real Hopper/Ghidra, browser, or OS coverage: no real-provider run. This is a synchronous spawn change covered by a boundary test; the probe already ran the same argv on every platform.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: this closes a memory-exhaustion path where a caller-selected launcher could grow the installation probe without bound. The fix uses the existing failure path and adds 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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2361 **Author:** [@DeryFerd](https://github.com/DeryFerd) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/ghidra-probe-output-budget` --- ### 📝 Commits (1) - [`4a46eed`](https://github.com/morluto/rea/commit/4a46eed2def2ab4cac68ac814a9fd8c3987adf62) fix(ghidra): bound the Java version probe output ### 📊 Changes **2 files changed** (+50 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/ghidra/GhidraInstallation.ts` (+10 -1) 📝 `tests/boundary/filesystem/ghidraJavaProbe.test.ts` (+40 -0) </details> ### 📄 Description ## Summary The Ghidra installation check runs the caller-selected Java launcher with `-XshowSettings:properties -version` to read `java.version`, `java.home`, and the VM name. That probe captured stdout and stderr with `maxBuffer` set to `Number.POSITIVE_INFINITY`, so a launcher that prints without limit could grow the capture until REA ran out of memory. This change gives the probe a 1 MiB capture budget, the same budget REA already uses for other Java listings. There is no linked issue. ## Problem and expected behavior `inspectGhidraInstallation` resolves the Java command from `JAVA_HOME` or `PATH` and calls `probeJava` on the installation host. In the production host, `probeJava` is a synchronous `spawnSync` whose options set `maxBuffer: Number.POSITIVE_INFINITY`. Node buffers every byte the child writes to stdout and stderr, and with no cap those buffers can reach whatever the child produces. A JVM that is misconfigured, wrapped by a script that echoes a large banner, or simply hostile can therefore make a read-only installation check consume unbounded memory. The smallest trigger is a Java launcher that writes more than the capture budget while the probe is running. The violated invariant is that a bounded, read-only installation check should never allocate memory in proportion to a child's unbounded output. The expected behavior is that a probe which produces more text than a sane JVM ever would is treated as a probe that could not be read, not as a reason to keep allocating. ## Change and scope Add a module constant `JAVA_PROBE_MAX_OUTPUT_BYTES = 1024 * 1024` next to the existing `EXECUTABLE_HEADER_PROBE_BYTES`, and pass it as `maxBuffer` in `probeJava`. One mebibyte is far more than a well-behaved JVM needs, since `-XshowSettings:properties` prints a few kilobytes. It is also the budget REA already chose for the analogous Java module listing in `src/android/JadxConfiguration.ts`, so the two Java probes now agree on what "too much output" means. When the child exceeds `maxBuffer`, `spawnSync` returns an `ENOBUFS` error and a null status. The probe already bails on any error or non-zero status and returns no observation, so the overflow path needs no new branch. `javaCheck` then reports the Java check as failed with `runtime_missing`, which is the same outcome the check already produces whenever the probe yields nothing. I did not change the timeout, the argv, the encoding flags, or the parsing. I also did not add a distinct rejection code for an over-budget probe. The installation check has no "unknown" status to carry, and `runtime_missing` is the existing code for "the probe produced no observation", so a separate code would be a larger contract change than this fix needs. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/ghidra/GhidraInstallation.ts`, in the production `GhidraInstallationHost.probeJava` implementation. The observation type and the `javaCheck` mapping are unchanged. - Contribution scope fit and linked maintainer decision: routine fix inside existing boundaries. The probe reads Ghidra's `application.properties` and runs the caller-selected Java launcher, both of which the installation check already did. Not applicable for a maintainer scope decision. - CLI and MCP/tool-catalog contract: no change. No tool schema, catalog entry, or handler changes. - Provider, bridge, target-format, or platform compatibility: no change. The bounded probe behaves the same on every platform. - Evidence, artifact, provenance, or reconstruction contract: the Java check still reports its detail and remediation. An over-budget probe loses the truncated text, which the probe already discards on any failure. - Target selection, authority, upstream behavior, and cleanup details (if applicable): none new. The probe does not touch the analysis target. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. No generated catalog, skill, or package file changes. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [x] 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: `tests/boundary/filesystem/ghidraJavaProbe.test.ts` gains one case, "bounds the Java version probe and reports an over-budget probe as a failed Java check". It mocks `spawnSync` to return `status: null` with an `ENOBUFS` error, the shape Node produces when the capture overflows, and asserts that the probe passed `maxBuffer: 1024 * 1024`, that no Java version is reported, that the configured `JAVA_HOME` is preserved, and that the Java check is `{ status: "failed", code: "runtime_missing" }`. - Base reproduction or other evidence: the new case fails on the unmodified source. With `maxBuffer: Number.POSITIVE_INFINITY`, the assertion `expect(options.maxBuffer).toBe(1024 * 1024)` reports `- Infinity + 1048576`. That is the red state this change fixes. - User-visible CLI/MCP output (if applicable): the Java installation check is what surfaces in `rea doctor` and provider diagnostics. An over-budget launcher now produces the same check shape a launcher that cannot be read produces, `{ name: "java", status: "failed", code: "runtime_missing" }`, and the detail line falls back to the launcher command while the remediation still tells the caller how to point `JAVA_HOME` at a supported JDK. - Remaining proof gaps: the case is a boundary test with a mocked `spawnSync`. I did not reproduce the memory growth with a real unbounded JVM, because that would mean deliberately exhausting the machine. The Node `maxBuffer` and `ENOBUFS` behavior the test relies on is stable across the supported Node versions, and CI runs the real suite. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run tests/boundary/filesystem/ghidraJavaProbe.test.ts` — 4 passed, including the new bounded-probe case. - `npm run check:fast` — typecheck and lint passed, run as the pre-push hook on the rebased commit. - `npx vitest run src/ghidra/GhidraInstallation.test.ts src/ghidra/GhidraDoctor.test.ts` — `GhidraInstallation.test.ts` passed fully. `GhidraDoctor.test.ts` reported 2 failures in its Windows native-authority group. I reproduced those same 2 failures on an unmodified checkout of `main`, so they are pre-existing and unrelated to this change. ## Compatibility, safety, and release - Breaking changes or migration steps: none. A launcher that stays under 1 MiB behaves exactly as before. - Real Hopper/Ghidra, browser, or OS coverage: no real-provider run. This is a synchronous spawn change covered by a boundary test; the probe already ran the same argv on every platform. - Package or release metadata impact: none. - Security, privacy, process, or containment review: this closes a memory-exhaustion path where a caller-selected launcher could grow the installation probe without bound. The fix uses the existing failure path and adds no new authority. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:04:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5187
No description provided.