ReadyToRun images compiled for Linux, macOS or the BSDs store the COFF machine XORed with IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE (dotnet/runtime src/coreclr/inc/pedecoder.h). Every framework assembly in a Linux .NET install has machine 0xFD1D, so target admission and the managed PE reader rejected them as an unsupported architecture. Decode the PE machine once in src/domain/peMachine.ts, replacing the two duplicated switches, and accept an OS override only on images with a CLI directory.
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { inspectManagedArtifactBytes } from "./ManagedArtifactInspector.js";
|
|
import { inspectManagedMembersBytes } from "./ManagedMemberInspector.js";
|
|
import { inspectManagedNativeBoundariesBytes } from "./ManagedNativeBoundaryInspector.js";
|
|
import {
|
|
buildManagedPeFixture,
|
|
buildNativePeFixture,
|
|
managedPeFixtureTarget,
|
|
} from "./ManagedPe.fixture.js";
|
|
|
|
describe("managed artifact failure classification", () => {
|
|
it("distinguishes native, malformed, and unsupported metadata", () => {
|
|
const nativeBytes = buildNativePeFixture();
|
|
const native = inspectManagedArtifactBytes(
|
|
nativeBytes,
|
|
managedPeFixtureTarget(nativeBytes),
|
|
);
|
|
expect(native).toMatchObject({
|
|
classification: { status: "not-managed" },
|
|
metadata: { status: "absent" },
|
|
coverage: { state: "unavailable" },
|
|
});
|
|
|
|
const malformedBytes = buildManagedPeFixture({
|
|
corruptMetadataSignature: true,
|
|
});
|
|
const malformed = inspectManagedArtifactBytes(
|
|
malformedBytes,
|
|
managedPeFixtureTarget(malformedBytes),
|
|
);
|
|
expect(malformed.classification.status).toBe("malformed");
|
|
expect(malformed.coverage.issues).toEqual([
|
|
expect.objectContaining({ code: "invalid-metadata-root" }),
|
|
]);
|
|
|
|
const unsupportedTableBytes = buildManagedPeFixture({
|
|
metadataValidMaskExtra: 1n << 50n,
|
|
});
|
|
const unsupportedTable = inspectManagedArtifactBytes(
|
|
unsupportedTableBytes,
|
|
managedPeFixtureTarget(unsupportedTableBytes),
|
|
);
|
|
expect(unsupportedTable.coverage.issues).toEqual([
|
|
expect.objectContaining({ code: "invalid-tables" }),
|
|
]);
|
|
});
|
|
|
|
it("rejects a ReadyToRun OS-override machine without a CLI directory", () => {
|
|
const bytes = buildNativePeFixture();
|
|
bytes.writeUInt16LE(0x014c ^ 0x7b79, bytes.readUInt32LE(0x3c) + 4);
|
|
expect(() =>
|
|
inspectManagedArtifactBytes(bytes, managedPeFixtureTarget(bytes)),
|
|
).toThrow("Unsupported PE machine 0x7a35");
|
|
});
|
|
|
|
it("keeps malformed reference and attribute issues across inventory callers", () => {
|
|
const bytes = buildManagedPeFixture({
|
|
references: [
|
|
"System.Runtime",
|
|
"System.Runtime",
|
|
"UnityEngine.CoreModule",
|
|
],
|
|
malformedAssemblyReferenceRows: [3],
|
|
malformedCustomAttributeRows: [1],
|
|
});
|
|
const target = managedPeFixtureTarget(bytes);
|
|
const artifact = inspectManagedArtifactBytes(bytes, target);
|
|
const members = inspectManagedMembersBytes(bytes, target);
|
|
const boundaries = inspectManagedNativeBoundariesBytes(bytes, target);
|
|
const issueCodes = ["invalid-heap-index", "invalid-row"];
|
|
|
|
expect(artifact.references.map(({ name }) => name)).toEqual([
|
|
"System.Runtime",
|
|
"System.Runtime",
|
|
]);
|
|
expect(artifact.attributes).toEqual([]);
|
|
expect(artifact.coverage.issues.map(({ code }) => code)).toEqual(
|
|
issueCodes,
|
|
);
|
|
expect(members.coverage.issues.map(({ code }) => code)).toEqual(issueCodes);
|
|
expect(boundaries.coverage).toMatchObject({
|
|
state: "partial",
|
|
issues: [
|
|
expect.objectContaining({ code: "invalid-heap-index" }),
|
|
expect.objectContaining({ code: "invalid-row" }),
|
|
],
|
|
});
|
|
});
|
|
});
|