From 626c705c990cbcb224c97d3df93fb1f6549cf3db Mon Sep 17 00:00:00 2001 From: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:05:51 +0000 Subject: [PATCH] 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> --- src/native/pe/PeResourceLayout.ts | 10 +++++++++- src/native/pe/PeResourceParser.test.ts | 10 ++++++++++ src/native/pe/PeUnsupportedTargets.test.ts | 7 ------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/native/pe/PeResourceLayout.ts b/src/native/pe/PeResourceLayout.ts index 31cb1a0b06..0364f5916f 100644 --- a/src/native/pe/PeResourceLayout.ts +++ b/src/native/pe/PeResourceLayout.ts @@ -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; } diff --git a/src/native/pe/PeResourceParser.test.ts b/src/native/pe/PeResourceParser.test.ts index 1981be3daf..3107908ba2 100644 --- a/src/native/pe/PeResourceParser.test.ts +++ b/src/native/pe/PeResourceParser.test.ts @@ -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([]); + }, +); diff --git a/src/native/pe/PeUnsupportedTargets.test.ts b/src/native/pe/PeUnsupportedTargets.test.ts index 1e6fbc60fd..0eaa67a8b1 100644 --- a/src/native/pe/PeUnsupportedTargets.test.ts +++ b/src/native/pe/PeUnsupportedTargets.test.ts @@ -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(); }