fix(pe): classify declared legacy Windows signatures at header admission

Keep opportunistic resource probes outside unadmitted PE layouts; move repeated malformed controls to the public adapter matrix.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
N0zoM1z0andgensokyo-dev authored and gensokyo-dev committed 2026-11-11 17:11:06 +08:00
1 parent c9e7aaca27
commit 626c705c99
3 files changed
+19 -8

No files matched your search

+9 -1
View File
@@ -101,6 +101,11 @@ export const readPeHeaders = (bytes: Buffer, fileSize = bytes.length) => {
"unsupported",
"DOS MZ images do not contain PE resource or certificate tables",
);
if (observed.state === "declared" && observed.signature !== "PE")
throw new BinaryFormatFailure(
"unsupported",
`${observed.signature} images do not contain PE resource or certificate tables`,
);
if (observed.state === "candidate" || observed.state === "signature-needed")
requirePeRange(bytes, observed.offset, 24);
if (observed.state !== "declared" || observed.signature !== "PE")
@@ -316,7 +321,10 @@ const openPeResourceTree = (
maxEntries,
);
} catch (cause) {
if (cause instanceof ArtifactReaderFailure && cause.reason === "format")
if (
(cause instanceof ArtifactReaderFailure && cause.reason === "format") ||
(cause instanceof BinaryFormatFailure && cause.kind === "unsupported")
)
return undefined;
throw cause;
}
+10
View File
@@ -1,3 +1,4 @@
import { dosMz, nonPeWindowsMz } from "../../domain/binaryTarget.fixture.js";
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
import { createHash } from "node:crypto";
import { describe, expect, it } from "vitest";
@@ -779,3 +780,12 @@ it("keeps raw name probing separate from full resource-name alignment admission"
message: expect.stringMatching(/unaligned.*resource name/iu),
});
});
it.each(["DOS", "NE", "LE", "LX"] as const)(
"leaves %s targets outside the opportunistic PE resource probe",
async (format) => {
const bytes = format === "DOS" ? dosMz(1024) : nonPeWindowsMz(format);
await expect(probeSeaName(bytes)).resolves.toBe(false);
await expect(payloadsOf(bytes)).resolves.toEqual([]);
},
);
@@ -41,13 +41,6 @@ it.each(
details: { operation: `inspect_pe_${operation}`, path },
});
expect(Buffer.compare(await readFile(path), bytes)).toBe(0);
await writeFile(path, Buffer.from("MZ"));
const malformed = await provider.inspect(input);
if (malformed.ok) throw new Error("Expected malformed input");
expect(projectAnalysisError(malformed.error)).toMatchObject({
code: "invalid_request",
category: "invalid_input",
});
} finally {
await provider.close();
}