Skip to content

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

Merged
morluto merged 7 commits into
morluto:mainfrom
viniciusdsandrade:fix/native-lipo-capability-bits
Oct 12, 2026
Merged

morluto merged 7 commits into
morluto:mainfrom
viniciusdsandrade:fix/native-lipo-capability-bits

Conversation

@viniciusdsandrade

@viniciusdsandrade viniciusdsandrade commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Universal Mach-O files whose x86_64 slice carries the LIB64 capability bit (FAT cpusubtype 0x80000003, common for x86_64 executables) fail slice reading with lipo slice metadata disagrees with the Mach-O FAT table: x86_64 .... The lipo parser applied capability bits only to arm64e, so it reported subtype 3 for these slices. Apply the capability byte lipo prints, and leave the subtype code unknown when lipo prints none.

No existing issue covers this. #1168 and #1765 concern arm64e slices, and open #1772 does not touch the lipo parser.

Problem and expected behavior

On macOS 26.7.1, lipo -detailed_info from Xcode prints this for /Applications/Sublime Text.app/Contents/MacOS/sublime_text:

architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_ALL
    capabilities 
    offset 16384
    size 13873872
    align 2^14 (16384)

otool -f reports cpusubtype 3 and capabilities 0x80 for the same FAT entry. The same lipo prints the same blank line for /bin/ls, whose x86_64 capability byte is 0x0, so the blank line does not identify the subtype. cctools lipo prints capabilities CPU_SUBTYPE_LIB64 for this case instead (misc/lipo.c), which the parser also ignored.

In both cases cpuSubtypeCode returned 3. lipoMatchesSlice compares that with the FAT subtype 0x80000003, finds no matching slice, and MachOSliceArtifactReader throws an integrity failure, the same failure class #1765 shows surfacing as integrity_mismatch. Expected: both slices are listed, as for universal files whose x86_64 entry has no capability bits.

Change and scope

  • capabilityBits reads the capability byte lipo prints next to the subtype: CPU_SUBTYPE_LIB64 (0x80) or a hex byte such as 0x80 or 0x0. Non-arm64e subtype codes include it, as arm64e codes already include their pointer-auth byte.
  • When lipo prints no capability byte, the subtype code is null, the rule arm64e already follows without PTR_AUTH_VERSION, and the entry keeps the existing "retained as unnormalized source text" limitation.
  • Slice matching still compares what the record does name: with a null code, lipoSubtypeMatches compares the subtype bits from lipoSubtypeBits with the FAT entry's low 24 bits, so a record naming another subtype (for example CPU_SUBTYPE_ARM64_ALL for an ARM64_V8 entry) is still rejected.
  • Not included: inspect_macho slice selection within one CPU family, which is a separate problem.

Contract and boundary impact

  • Semantic owner and earliest changed stage: lipo -detailed_info parsing in src/native/parsers/lipo.ts, and its slice comparison in src/artifacts/MachOSliceArtifactReader.ts.
  • CLI and MCP/tool-catalog contract: schemas unchanged. cpu_subtype_code includes printed capability bits and is null when lipo prints none.
  • Provider, bridge, target-format, or platform compatibility: macOS lipo output with named, hex or blank capabilities.
  • Evidence, artifact, provenance, or reconstruction contract: affected universal files yield slice entries instead of an integrity failure; a slice whose capabilities line is blank carries the existing unnormalized-subtype limitation.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/native/parsers/lipo.test.ts covers CPU_SUBTYPE_LIB64, 0x80, 0x0 and the blank line. tests/boundary/providers/native/artifactProvider.machOSlices.test.ts reads a FAT image whose x86_64 entry carries 0x80000003 with the macOS 26 lipo output and expects both slices (on the base revision that read throws the integrity failure), and still rejects a blank-capability record naming CPU_SUBTYPE_X86_64_H for that entry.
  • Base reproduction or other evidence: the lipo -detailed_info and otool -f output above, observed on macOS 26.7.1 for Sublime Text and /bin/ls, and cctools misc/lipo.c for the named LIB64 form. The failure path through cpuSubtypeCode and lipoMatchesSlice is source-derived.
  • User-visible CLI/MCP output (if applicable): before, lipo slice metadata disagrees with the Mach-O FAT table: x86_64 (cputype=CPU_TYPE_X86_64, cpusubtype=CPU_SUBTYPE_X86_ALL, offset=16384, ...); after, the x86_64 and arm64 slices.
  • Remaining proof gaps: REA itself was not run against the affected applications; the evidence is the producer output above plus source reading.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • No project commands were run locally: dependencies are not installed. Only the system lipo -detailed_info and otool -f were run on the binaries named above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. cpu_subtype_code changes from an assumed value to null only where lipo prints no capability byte.
  • Real Hopper/Ghidra, browser, or OS coverage: producer output observed on macOS 26.7.1; no REA lane was run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; slice ranges are still checked against the structural FAT index.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T22:49:22.781186Z 951bec1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc932e23bd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/parsers/lipo.ts Resolved
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.
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.
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.
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.
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.
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.
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.
@viniciusdsandrade
viniciusdsandrade force-pushed the fix/native-lipo-capability-bits branch from af483b4 to 951bec1 Compare October 11, 2026 22:44
@morluto
morluto merged commit 4b653fe into morluto:main Oct 12, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants