Skip to content

fix(native): honor Mach-O chained pointer locations and library ordinals - #1709

Merged
baron merged 7 commits into
morluto:mainfrom
1NormalGuy:fix/macho-chained-pointer-decoding
Oct 12, 2026
Merged

baron merged 7 commits into
morluto:mainfrom
1NormalGuy:fix/macho-chained-pointer-decoding

Conversation

@1NormalGuy

Copy link
Copy Markdown
Contributor

Summary

Restore correct Mach-O pointer decoding and dylib provenance for ObjC/Swift metadata. These defects were reproduced during repository review; there is no related issue.

Problem and expected behavior

LC_DYLD_CHAINED_FIXUPS describes individual pointer locations, but the parser decoded every nonzero pointer in the containing segment. An ordinary 0x100001234 pointer could become 0x200001234, corrupting metadata lookup. A chain-member zero was also treated as null, and valid positive dylib ordinals above the signed integer midpoint lost their library identity.

Only declared chain members should be decoded. Ordinary interleaved pointers, zero-offset rebases and valid dependency identities must remain accurate.

Change and scope

Walk declared page starts and next links, decode only chain members, and use dyld's special-ordinal cutoffs. Validate producer bounds, preserve known facts after malformed chains and expose partial coverage. Give the Swift verifier an explicit module name so hyphenated fixture filenames compile.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Mach-O fixup parsing.
  • CLI and MCP/tool-catalog contract: no schema changes; corrected metadata addresses and library provenance.
  • Provider, bridge, target-format, or platform compatibility: Mach-O chained fixups and the existing supported pointer formats.
  • Evidence, artifact, provenance, or reconstruction contract: preserve dependency identity, ordinary pointer values and explicit incomplete coverage.
  • Process execution, authorization, cleanup, or containment impact: none; inspected target fixtures were not executed.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: chain membership, zero-offset rebases, malformed page starts/links, ordinal boundaries and interleaved ObjC metadata.

  • Base reproductions confirmed ordinary pointer corruption, incorrect null treatment and missing library provenance.

  • User-visible CLI/MCP output: classes, categories, implementation addresses, conformances and witness slots are recovered from 10 compiled fixture variants; ordinary pointer addresses are preserved.

  • Remaining proof gaps: verification covers the selected macOS fixture variants, not all third-party binaries.

  • 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

Validated this standalone PR branch:

  • npm run test:focused -- src/native/AppleMachoFixups.test.ts src/native/AppleDispatchMetadata.test.ts — 46 tests passed.
  • npm run verify:apple-dispatch — 10 real ObjC/Swift fixture variants passed through public CLI/MCP (arm64/arm64e, chained/legacy fixups, symbols/stripped); target code was not executed. Required runtime/skill artifacts built successfully.
  • npm run check — passed, including typecheck, lint (0 errors), formatting, dependency/metadata checks, module boundaries and architecture guards.
  • git diff --check — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real compiled macOS fixture inspection; Hopper/Ghidra/browser not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only parsing, bounded chain walks and no target execution.

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.

Walk declared page starts and next links before decoding chained pointers,
preserving plain pointers between fixups, zero-offset rebases, and known
facts in malformed chains. Interpret positive dylib ordinals with dyld's
special-ordinal cutoff so valid dependency provenance is retained.

Give the Swift verification fixture an explicit module name so link-mode
filenames do not produce invalid identifiers.

Validation: 46 focused regressions; pre-fix reproductions in an isolated
copy; real macOS CLI/MCP verification of 10 compiled Objective-C/Swift,
arm64/arm64e, chained/legacy and symbols/stripped fixture variants.
@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-11T05:32:52.452693Z 344be44 PR opened
ℹ️ 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: 344be44f9a

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"Compressed chained-fixup symbol names are not supported",
);
const starts = base + startsOffset;
const startsEnd = base + importHeader.offset;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound starts tables independently of import ordering

When a valid LC_DYLD_CHAINED_FIXUPS payload places starts_in_image after the import table (starts_offset is not required to precede imports_offset, and LLVM's Mach-O reader accepts and iterates this layout), this assignment makes requireStartsRange(starts, 4) always throw Chained starts table exceeds its fixup data. This regresses noncanonical producer binaries that the old reader accepted; validate the starts structures against the payload and their own sizes/overlaps rather than treating the import offset as their upper bound.

AGENTS.md reference: AGENTS.md:L42-L42

Useful? React with 👍 / 👎.

@dandgabr dandgabr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consolidated review

  • P2 — Bound the starts table independently of import ordering. In src/native/AppleMachoFixups.ts, startsEnd is derived from base + importHeader.offset, so chained-starts validation is capped by the import table's offset. The format declares these offsets independently; a valid layout with starts after imports can be rejected or misread. Validate each table against its own declared bounds and the enclosing fixup blob. This consolidates the still-applicable inline finding; no additional actionable issues were confirmed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@baron baron left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact repaired head dd938d7 and current-main integration. Original contributor 344be44 remains an ancestor; no force/rebase/history rewrite. Independent verification of the resource correction and root review of the combined delta found no remaining source blocker.

The producer now retains compact starts descriptors and normalized physical-page membership facts, rather than rewalking every chain prefix. Both cache-record count and retained bitmap bytes are bounded before retention; physical aliases share facts, unsupported pages do not expand into per-segment maps, and exhausted caching preserves transient decode behavior. Failed tails retain established members, later pages remain queryable, and first failure coverage is bounded per distinct mapped view. Nonzero-page diagnostic locations and deduplicated identical-view failure multiplicity are intentional and tested.

An earlier UNPUBLISHED optional optimization amplified page-map metadata; independent review blocked it, and the representation was corrected before publishing a candidate branch head. The contributor was not blamed for that unpublished defect. No unsupported starts/import-ordering regression is asserted.

Pinned validation: 93 scoped parser/metadata/error/MCP tests, check:fast, full check and build passed. All ten source-owned compiled ObjC/Swift static artifact variants passed real CLI/MCP equivalence, with target_executed=false; only compiler cache arguments were redirected into private /tmp. The new partial-handler matrix observes producer emission as well as transport so fallback cannot mask a missing marker. Main's production flag correction is inherited, not duplicated.

Fresh published-head CI is green, including Static checks, Test (coverage + timing), CI required and the actual Apple artifact CLI/MCP job. Parser-only performance observations are not a whole-product token/CPU/memory claim; no full allocation exploit, real Windows affinity, GUI or caller target execution was performed. Final integration is clean.

@baron
baron merged commit 3b0ea59 into morluto:main Oct 12, 2026
34 checks passed
@morluto morluto mentioned this pull request Oct 13, 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.

4 participants