fix(il2cpp): refuse a seed path under a non-directory as caller input (#6271)

Co-authored-by: Abelo9996 <Abelo9996@users.noreply.github.com>
This commit is contained in:
Abel YagubyanandAbelo9996 authored and GitHub committed 2026-10-22 17:48:27 +08:00
1 parent 690a63abd6
commit 2d91e2d578
2 files changed
+45

No files matched your search

+7
View File
@@ -69,6 +69,13 @@ export class Il2cppGhidraSeedWriter implements Il2cppSeedWriterPort {
} catch (cause) {
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
return ok(undefined);
if (cause instanceof Error && "code" in cause && cause.code === "ENOTDIR")
return err(
invalid(
"ghidra_seeds",
`--ghidra-seeds ${output.path} has a parent path component that is not a directory; choose an output path inside an existing directory.`,
),
);
return err(
new EvidenceFileError("write", "io", { path: output.path, cause }),
);
@@ -978,3 +978,41 @@ cliTest(
});
},
);
cliTest.skipIf(process.platform === "win32")(
"refuses a Ghidra seed path below a regular file as caller input",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-il2cpp-seeds-parent-");
const path = join(root, "global-metadata.dat");
const binaryPath = join(root, "libil2cpp.so");
const parent = join(root, "regular-file");
await writeFile(path, createIl2cppMetadataFixture().bytes);
await writeFile(binaryPath, createElfFixture(createIl2cppBinaryFixture()));
await writeFile(parent, "unchanged");
const result = await runFileCli(cli, {
arguments: [
"inspect-il2cpp-metadata",
path,
"--binary",
binaryPath,
"--ghidra-seeds",
join(parent, "seeds.tsv"),
"--json",
],
});
expect(result.exitCode).not.toBe(0);
expect(result.json).toMatchObject({
code: "invalid_request",
category: "invalid_input",
details: {
issues: [
{
path: ["ghidra_seeds"],
message: expect.stringContaining("not a directory"),
},
],
},
});
expect(await readFile(parent, "utf8")).toBe("unchanged");
},
);