fix(formats): preserve high bits in Windows signature checks

Decode MZ and Windows signature bytes without ASCII high-bit masking. Move malformed signature cases into the shared Go diagnostics fixtures so provider, compiled CLI, and MCP workflows cover NE, LE, LX, and PE lookalikes; remove the superseded provider-only cases.

Validation: runtime build, check:ci, and focused DOS/Go/target/CLI/MCP tests. Windows-only reference-import cases await CI.
This commit is contained in:
morluto
2026-10-13 04:24:29 +08:00
parent fd9588089d
commit ac57c88efe
4 changed files with 31 additions and 28 deletions
@@ -49,20 +49,6 @@ it.each([32, 64] as const)(
},
);
it.each([{ signature: [0xce, 0xc5] }, { signature: [0xcc, 0xd8] }])(
"rejects high-bit lookalikes of Windows signatures %j",
async ({ signature }) => {
const root = await createTestTempDirectory("rea-go-pe-signature-");
const fixture = createGoBinaryFixture({ format: "pe" });
fixture.bytes.set(signature, 128);
const path = join(root, "corrupt-signature.exe");
await writeFile(path, fixture.bytes);
const result = await new GoBinaryProvider().inspect({ path });
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error).toBeInstanceOf(AnalysisInputError);
},
);
it("preserves the actual build-info byte guard as a resource failure", async () => {
const fixture = createGoBinaryFixture();
fixture.bytes.set([0x81, 0x80, 0x40], fixture.headerOffset + 32);
+9
View File
@@ -203,6 +203,14 @@ export const createGoBinaryDiagnosticFixtures = () => {
}
const damagedPe = createGoBinaryFixture({ format: "pe" }).bytes;
damagedPe.write("NO", 128, "ascii");
const highBitSignatures = ["NE", "LE", "LX", "PE"].map((signature) => {
const bytes = createGoBinaryFixture({ format: "pe" }).bytes;
bytes.set(
[...Buffer.from(signature)].map((byte) => byte | 0x80),
128,
);
return { name: `high-bit-${signature.toLowerCase()}`, bytes };
});
const absentDirectories = createGoBinaryFixture({ format: "pe" }).bytes;
absentDirectories.writeUInt32LE(1, 152 + 108);
const shortOptionalHeaders = [0, 1].map((size) => {
@@ -220,6 +228,7 @@ export const createGoBinaryDiagnosticFixtures = () => {
})),
...[
{ name: "damaged-pe", bytes: damagedPe },
...highBitSignatures,
{ name: "absent-directories", bytes: absentDirectories },
...shortOptionalHeaders,
].map((fixture) => ({