mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
test(go): expect loader-equivalent PE header facts in the MZ diagnostics (#14293)
#14253 made the static PE readers read the optional header at its fixed offsets and admit a declared directory count below 16, as the Windows loader does. The Go MZ diagnostic fixtures still expected the older refusals, so inspect_go_binary MCP and CLI diagnostics failed on main. A short SizeOfOptionalHeader with an unknown magic at the fixed offset is now an unsupported optional header, and a PE declaring one data directory is admitted and keeps its build information, which the MCP test now asserts.
This commit is contained in:
1 parent
669147e9eb
commit
a43bfa62ee
2 files changed
+29
-8
No files matched your search
@@ -29,6 +29,7 @@ import {
|
||||
createGoBinaryByteStringFixture,
|
||||
createGoBinaryDiagnosticFixtures,
|
||||
createGoBinaryFixture,
|
||||
createGoBinaryOneDirectoryFixture,
|
||||
createGoBinaryPathFailureFixture,
|
||||
} from "../../fixtures/go/image.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
@@ -288,6 +289,20 @@ goMcpTest(
|
||||
},
|
||||
});
|
||||
}
|
||||
// A declared directory count below 16 is admitted, as the loader admits it.
|
||||
const path = join(root, "one-directory.exe");
|
||||
await writeFile(path, createGoBinaryOneDirectoryFixture().bytes);
|
||||
const admitted = await client.callTool({
|
||||
name: "inspect_go_binary",
|
||||
arguments: { path },
|
||||
});
|
||||
expect(admitted.isError, JSON.stringify(admitted.content)).not.toBe(true);
|
||||
expect(
|
||||
goBinarySchema.parse(
|
||||
(admitted.structuredContent as { normalized_result: unknown })
|
||||
.normalized_result,
|
||||
).build_info,
|
||||
).toMatchObject({ go_version: "go1.26.0" });
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Vendored
+14
-8
@@ -440,12 +440,11 @@ export const createGoBinaryDiagnosticFixtures = () => {
|
||||
{ name: "damaged-pe", bytes: damagedPe },
|
||||
...highBitSignatures,
|
||||
];
|
||||
const absentDirectories = createGoBinaryFixture({ format: "pe" }).bytes;
|
||||
absentDirectories.writeUInt32LE(1, 152 + 108);
|
||||
// The loader reads the optional header at its fixed offsets whatever
|
||||
// SizeOfOptionalHeader declares, so an unknown magic there is unsupported.
|
||||
const shortOptionalHeaders = [0, 1].map((size) => {
|
||||
const bytes = createGoBinaryFixture({ format: "pe" }).bytes;
|
||||
bytes.writeUInt16LE(size, 148);
|
||||
// Bytes following the declared header must not supply its magic field.
|
||||
bytes.fill(0xff, 152 + size, 154);
|
||||
return { name: `optional-header-${String(size)}-bytes`, bytes };
|
||||
});
|
||||
@@ -460,20 +459,27 @@ export const createGoBinaryDiagnosticFixtures = () => {
|
||||
code: "unsupported_target" as const,
|
||||
details: { operation: "inspect_go_binary" },
|
||||
})),
|
||||
...[
|
||||
{ name: "absent-directories", bytes: absentDirectories },
|
||||
...shortOptionalHeaders,
|
||||
].map((fixture) => ({
|
||||
...shortOptionalHeaders.map((fixture) => ({
|
||||
...fixture,
|
||||
code: "unsupported_target" as const,
|
||||
details: {
|
||||
operation: "inspect_go_binary",
|
||||
format_failure: "malformed",
|
||||
reason: "Only PE32 and PE32+ image optional headers are supported",
|
||||
},
|
||||
})),
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* A PE that declares one data directory. The loader admits it, and the Go
|
||||
* build information is found by section scan, so inspection succeeds.
|
||||
*/
|
||||
export const createGoBinaryOneDirectoryFixture = () => {
|
||||
const fixture = createGoBinaryFixture({ format: "pe" });
|
||||
fixture.bytes.writeUInt32LE(1, 152 + 108);
|
||||
return fixture;
|
||||
};
|
||||
|
||||
const encodeVarint = (input: number): Buffer => {
|
||||
let value = BigInt(input);
|
||||
const bytes: number[] = [];
|
||||
|
||||
Reference in new issue
Block a user