mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 17:28:08 +00:00
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:
1 parent
c9e7aaca27
commit
626c705c99
3 files changed
+19
-8
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user