refactor(native): extract FAT header format switch in Mach-O slice selection (#632)

Replace inline magic comparisons with an exhaustive fatHeaderFormat
switch and add a regression test locking in rejection of 32-bit
slice payloads inside little-endian containers. Behavior-preserving:
the new test passes on the old implementation.
This commit is contained in:
morluto
2026-10-06 04:36:13 +08:00
committed by GitHub
parent feeb19b8b3
commit 38b293329c
2 changed files with 28 additions and 4 deletions
+8
View File
@@ -253,6 +253,14 @@ describe("byte-swapped universal Apple dispatch metadata", () => {
);
});
it("rejects a 32-bit slice payload inside a little-endian container", () => {
const bytes = wrapped(false);
bytes.writeUInt32BE(0xfeedface, 256);
expect(() => decodeAppleDispatchMetadata(bytes, 100, provenance)).toThrow(
"Only little-endian 64-bit Mach-O metadata is supported",
);
});
it("checks the full little-endian FAT64 slice extent", () => {
const bytes = wrapped(true);
bytes.writeBigUInt64LE(0x100000000n, 16);