Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(ghidra): refuse unrecognized JVM native architectures
  • Loading branch information
morluto committed Oct 13, 2026
commit 295d81ce36c97b60a3772a265b57a087f06d4f3b
41 changes: 25 additions & 16 deletions src/ghidra/GhidraInstallation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {
// the real probeJava against captured `-XshowSettings:properties` output.
// Every other test overrides probeJava, so the stub never fires for them.
vi.mock("node:child_process", async (importOriginal) => {
const original =
await importOriginal<typeof import("node:child_process")>();
const original = await importOriginal<typeof import("node:child_process")>();
return { ...original, spawnSync: vi.fn() };
});

Expand Down Expand Up @@ -941,20 +940,30 @@ describe("Ghidra native decompiler admission", () => {
expect(result.status).toBe("available");
});

it("keeps an unrecognized JVM os.arch unknown instead of failing the install", () => {
const result = inspectGhidraInstallation(
{
environment: {},
installDir: INSTALL,
platform: "darwin",
architecture: "arm64",
},
host({
probeJava: () => ({ ...JAVA, osArch: "riscv64" }),
}),
);
expect(result.status).toBe("available");
});
it.each(["riscv64", "sparcv9", ""])(
"refuses an unrecognized JVM os.arch (%s) instead of assuming alignment",
(osArch) => {
const result = inspectGhidraInstallation(
{
environment: {},
installDir: INSTALL,
platform: "darwin",
architecture: "arm64",
},
host({
probeJava: () => ({ ...JAVA, osArch }),
}),
);
expect(result.status).toBe("unavailable");
if (result.status !== "unavailable") return;
expect(
result.checks.find(({ name }) => name === "native_decompiler"),
).toMatchObject({
status: "failed",
detail: expect.stringContaining("unrecognized os.arch="),
});
},
);
});

describe("Ghidra Java probe os.arch extraction", () => {
Expand Down
12 changes: 10 additions & 2 deletions src/ghidra/GhidraInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,14 @@ const nativeDecompilerCheck = ({
const osArch = coordinates.java?.osArch;
const selectedDirectory = jvmOsArchNativeDirectory(platform, osArch);
const validatedDirectory = NATIVE_PLATFORMS[platform]?.[architecture];
if (osArch !== undefined && selectedDirectory === undefined)
Comment thread
morluto marked this conversation as resolved.
Resolved
return installationCheck({
name: "native_decompiler",
passed: false,
code: "executable_missing",
detail: `JVM reports unrecognized os.arch=${osArch}; its selected native decompiler directory is unknown and cannot be matched to the validated host directory`,
remediation: `Point JAVA_HOME at a JDK whose reported architecture maps to the validated Ghidra decompiler (${validatedDirectory ?? "unsupported host"}). REA does not build or install native tools.`,
});
if (
osArch !== undefined &&
selectedDirectory !== undefined &&
Expand Down Expand Up @@ -683,8 +691,8 @@ const nativeDecompilerCheck = ({

/**
* Map a JVM os.arch value to the Ghidra native directory that JVM selects.
* Unknown values stay unknown: they must not fail an installation the other
* checks already accept.
* Unknown values stay unknown; admission must not treat them as aligned with
* the validated host directory.
*/
const jvmOsArchNativeDirectory = (
platform: NodeJS.Platform,
Expand Down