fix(apple): validate physical slices and dylib platform compatibility

This commit is contained in:
morluto
2026-10-09 00:49:30 +08:00
parent 16f4609d68
commit 15f92f2988
15 changed files with 1019 additions and 95 deletions
+30
View File
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import {
CPU,
fatImage,
machoImage,
} from "../artifacts/apple/MachoImage.fixture.js";
import { parseMachoLayout } from "./AppleMachoSelection.js";
describe("native Mach-O slice selection", () => {
it("accepts a FAT slice whose table identity and embedded header agree", () => {
const fat = fatImage([{ cpu: CPU.arm64, bytes: machoImage({}) }]);
expect(parseMachoLayout(Buffer.from(fat), "arm64").segments).toEqual([]);
});
it("rejects FAT subtype disagreement and unaligned slice offsets", () => {
const original = fatImage([{ cpu: CPU.arm64, bytes: machoImage({}) }]);
const mismatched = original.slice();
new DataView(mismatched.buffer).setUint32(12, 2, false);
expect(() => parseMachoLayout(Buffer.from(mismatched), "arm64")).toThrow(
/disagrees/u,
);
const unaligned = original.slice();
new DataView(unaligned.buffer).setUint32(16, 4097, false);
expect(() => parseMachoLayout(Buffer.from(unaligned), "arm64")).toThrow(
/not aligned/u,
);
});
});