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:
@@ -62,4 +62,31 @@ architecture arm64e
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["CPU_SUBTYPE_LIB64", 0x80000003],
|
||||
["0x80", 0x80000003],
|
||||
["0x0", 3],
|
||||
])("applies printed x86_64 capabilities %s", (capabilities, code) => {
|
||||
expect(
|
||||
parseLipoArchitectures(
|
||||
`architecture x86_64\n cpusubtype CPU_SUBTYPE_X86_64_ALL\n capabilities ${capabilities}\n`,
|
||||
)[0]?.cpu_subtype_code,
|
||||
).toBe(code);
|
||||
});
|
||||
|
||||
it("leaves the subtype code unknown when lipo prints no capabilities", () => {
|
||||
// macOS 26 lipo prints this blank line for LIB64 and plain x86_64 slices.
|
||||
expect(
|
||||
parseLipoArchitectures(
|
||||
"architecture x86_64\n cputype CPU_TYPE_X86_64\n cpusubtype CPU_SUBTYPE_X86_ALL\n capabilities \n offset 16384\n",
|
||||
),
|
||||
).toMatchObject([
|
||||
{
|
||||
cpu_subtype: "CPU_SUBTYPE_X86_ALL",
|
||||
cpu_subtype_code: null,
|
||||
capabilities: null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ const cpuTypeCode = (value: string | undefined): number | null => {
|
||||
return numeric ?? CPU_TYPES[value] ?? null;
|
||||
};
|
||||
|
||||
/** Normalize the subtype and its separately printed ptrauth capability bits. */
|
||||
/** Normalize the subtype and its separately printed capability bits. */
|
||||
const cpuSubtypeCode = (
|
||||
value: string | undefined,
|
||||
capabilities: string | undefined,
|
||||
@@ -138,7 +138,11 @@ const cpuSubtypeCode = (
|
||||
if (numeric !== null) return numeric;
|
||||
const subtype = CPU_SUBTYPES[value];
|
||||
if (subtype === undefined) return null;
|
||||
if (value !== "CPU_SUBTYPE_ARM64E") return subtype;
|
||||
if (value !== "CPU_SUBTYPE_ARM64E") {
|
||||
// Recent lipo prints an empty capabilities line, even for LIB64 slices.
|
||||
const bits = capabilityBits(capabilities);
|
||||
return bits === null ? null : ((bits << 24) | subtype) >>> 0;
|
||||
}
|
||||
const version = /PTR_AUTH_VERSION\s+USERSPACE\s+(\d+)/u.exec(
|
||||
capabilities ?? "",
|
||||
)?.[1];
|
||||
@@ -153,6 +157,20 @@ const cpuSubtypeCode = (
|
||||
return (0x80000000 | (parsedVersion << 24) | subtype) >>> 0;
|
||||
};
|
||||
|
||||
/** The subtype bits a lipo record names, without its capability byte. */
|
||||
export const lipoSubtypeBits = (value: string | null): number | null => {
|
||||
if (value === null) return null;
|
||||
const subtype = unsigned32(value) ?? CPU_SUBTYPES[value];
|
||||
return subtype === undefined ? null : subtype & 0x00ffffff;
|
||||
};
|
||||
|
||||
/** lipo names the LIB64 capability and prints other capability bits in hex. */
|
||||
const capabilityBits = (capabilities: string | undefined): number | null => {
|
||||
if (capabilities === "CPU_SUBTYPE_LIB64") return 0x80;
|
||||
const bits = /^0x([\da-f]{1,2})$/iu.exec(capabilities ?? "")?.[1];
|
||||
return bits === undefined ? null : Number.parseInt(bits, 16);
|
||||
};
|
||||
|
||||
const unsigned32 = (value: string): number | null => {
|
||||
if (!/^(?:\d+|0x[\da-f]+)$/iu.test(value)) return null;
|
||||
const parsed = Number(value);
|
||||
|
||||
Reference in New Issue
Block a user