Repository navigation
fix(native): honor Mach-O chained pointer locations and library ordinals - #1709
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Consolidated review
- P2 — Bound the starts table independently of import ordering. In
src/native/AppleMachoFixups.ts,startsEndis derived frombase + 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.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
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.
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_FIXUPSdescribes individual pointer locations, but the parser decoded every nonzero pointer in the containing segment. An ordinary0x100001234pointer could become0x200001234, 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
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
Review checklist
type(scope): outcome.