fix(native): accept universal binaries with LIB64 x86_64 slices (#1982)

* fix(native): apply printed lipo capability bits to CPU subtypes

lipo -detailed_info prints a slice's capability byte separately from its
symbolic subtype: CPU_SUBTYPE_LIB64 for x86_64 and ppc64, and other bits
as hex. Only the arm64e pointer-auth form was applied, so a LIB64 x86_64
slice normalized to subtype 3 while its FAT entry carries 0x80000003,
and slice validation rejected the universal binary as an integrity
mismatch. Fold the printed capability byte into the subtype code.

* fix(native): leave lipo CPU subtypes unknown without capability bits

The lipo shipped with macOS 26 prints an empty capabilities line for
x86_64 slices whose FAT capability byte is 0x80 as well as 0x00, so a
symbolic subtype alone does not identify the slice's CPU subtype. The
parser assumed no capability bits and still reported subtype 3 for
LIB64 slices, which made universal applications such as Sublime Text
fail slice validation. Report the subtype code as unknown when lipo
prints no capability byte, as arm64e already does; slice validation
then relies on the remaining physical facts.

* test(native): cover printed and blank lipo capability bits

Fold CPU_SUBTYPE_LIB64 and hex capability bytes into x86_64 subtype
codes, and keep the code unknown for the blank capabilities line that
macOS 26 lipo prints.

* test(native): match a LIB64 x86_64 slice with blank lipo capabilities

Read a universal image whose x86_64 FAT entry carries 0x80000003 while
lipo reports CPU_SUBTYPE_X86_ALL with a blank capabilities line, as
macOS 26 lipo does, and expect both slices instead of an integrity
failure.

* fix(native): compare named lipo subtype bits without capability bytes

A blank capabilities line leaves the subtype code unknown, and slice
matching then skipped the subtype entirely. A FAT entry whose named
subtype differs, such as CPU_SUBTYPE_ARM64_V8 recorded by lipo as
CPU_SUBTYPE_ARM64_ALL, was accepted. Keep comparing the complete
subtype when lipo printed its capability byte, and otherwise compare
the subtype bits its record names.

* test(native): share LIB64 slice reader setup

Read the LIB64 universal fixture through one helper that takes the
x86_64 subtype lipo reports, so further cases reuse the same image and
lipo record. The existing expectation is unchanged.

* test(native): reject a blank-capability lipo subtype naming other bits

With the capabilities line blank, a lipo record naming
CPU_SUBTYPE_X86_64_H for the x86_64 LIB64 slice still disagrees with
the FAT entry's subtype bits and fails slice validation.
This commit is contained in:
Vinícius Andrade
2026-10-12 08:41:40 +08:00
committed by GitHub
parent 0d11f71e0d
commit 4b653fe6ad
4 changed files with 121 additions and 4 deletions
@@ -291,3 +291,61 @@ describe("artifact Mach-O arm64e variant slices", () => {
},
);
});
// macOS 26 lipo leaves capabilities blank, even for a LIB64 x86_64 slice.
describe("artifact Mach-O LIB64 slices", () => {
const LIB64 = { type: 0x01000007, subtype: 0x80000003 } as const;
const lib64Slices = async (x86Subtype: string) => {
const root = await createTestTempDirectory("rea-slices-lib64-");
const binary = join(root, "fat");
const x86 = machoImage({ cpu: LIB64 });
const arm = machoImage({ cpu: CPU.arm64 });
await writeFile(
binary,
fatImage([
{ cpu: LIB64, bytes: x86 },
{ cpu: CPU.arm64, bytes: arm },
]),
);
const reader = new MachOSliceArtifactReader(
binary,
{},
lipoRunner(
[
"architecture x86_64",
" cputype CPU_TYPE_X86_64",
` cpusubtype ${x86Subtype}`,
" capabilities ",
" offset 4096",
` size ${String(x86.length)}`,
" align 2^12 (4096)",
"architecture arm64",
" cputype CPU_TYPE_ARM64",
" cpusubtype CPU_SUBTYPE_ARM64_ALL",
" capabilities ",
" offset 8192",
` size ${String(arm.length)}`,
" align 2^12 (4096)",
"",
].join("\n"),
),
);
onTestFinished(() => reader.close());
const entries = [];
for await (const entry of reader.entries()) entries.push(entry);
return entries.map(({ path, byteOffset }) => [path, byteOffset]);
};
it("matches an x86_64 LIB64 slice whose lipo capabilities are blank", async () => {
expect(await lib64Slices("CPU_SUBTYPE_X86_ALL")).toEqual([
["slices/x86_64", 4096],
["slices/arm64", 8192],
]);
});
it("still rejects a blank-capability subtype that names other bits", async () => {
await expect(lib64Slices("CPU_SUBTYPE_X86_64_H")).rejects.toMatchObject({
reason: "integrity",
});
});
});