Skip to content

fix(apple): read LC_LAZY_LOAD_DYLIB_INFO dependency payloads - #5650

Merged
morluto merged 10 commits into
mainfrom
cursor/macho-lazy-dylib-info-eba5
Oct 20, 2026
Merged

morluto merged 10 commits into
mainfrom
cursor/macho-lazy-dylib-info-eba5

Conversation

@morluto

@morluto morluto commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #5551 and #5649. trace-dylib-resolution dropped LC_LAZY_LOAD_DYLIB_INFO (0x3a) and still reported complete coverage. inspect-macho kept that command as a raw load command and still marked the dependency list exhaustive.

Seed audit on main b3aadaf47: #5606 is already closed by 2b263a7fe. #5542 and #5462 are already rejected at FAT admission by 497037e6e (machoContainer.test.ts and binaryTarget.test.ts still pass). This PR does not reopen those.

Problem and expected behavior

A Mach-O linked with the current lazy-load info command stores the install name in a linkedit payload, not in a classic dylib_command. The load-command reader ignored command 0x3a, so the trace listed only the other dependencies and set coverage.status to complete. otool -l prints the command without a name field; the inspection normalizer treated the resulting dependency list as exhaustive.

The payload install name is a dependency. It is resolved like LC_LAZY_LOAD_DYLIB and not traversed, because dyld loads it on first use. An absent image is lazy-load-unresolved, not a required launch failure. When the may-be-missing flag is set (weak: true), that finding says dyld continues if the image is absent. A required lazy image still says first use would fail. Versions are null because this payload has none. The may-be-missing flag is weak. Unrecognized flag bits leave the image unsupported instead of inventing weak: false. Flag and chain-start image offsets outside the slice VM range leave the image malformed. Payload strings must start after the 24-byte header. Distinct payload bytes and payload-range lookups stay within the 16 MiB limit, and a file range already read is reused. String scanning and UTF-8 checks count every reference, including repeats and overlaps, and stop at that same aggregate. Symbol references, including repeats, stop at 65536 per slice before those strings are cached. A cached string is reused only when its start and terminating NUL both lie inside the later payload. A load-path NUL in the payload's final byte is unterminated. A slice retains at most 1024 of these commands. inspect-macho keeps the raw otool command and marks dependencies non-exhaustive, with a limitation naming the omitted command. It does not invent an install name from otool text.

Change and scope

The Mach-O load-command reader owns the payload parse and emits the dependency in load-command order, including FAT slices. The VM range is dyld's one-page floor extended by every segment except __LINKEDIT, measured from the __TEXT vmaddr. The trace skips traversal for both lazy commands. The otool parser records payload-only dependency commands, and inspection uses that to clear exhaustive coverage.

Follow the contribution scope.
This is an ordinary parser fix inside existing read-only Mach-O inspection. No new provider, target execution, injection, mutation, or protection recovery. Maintainer scope decision: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: MachoLoadCommandReader for structural dependency facts; parseOtoolLoadCommands for the otool dependency inventory. Both change before trace coverage and inspect-macho presentation.
  • Contribution scope fit and linked maintainer decision: existing read-only format inspection; maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: trace_dylib_resolution edges may include command: LC_LAZY_LOAD_DYLIB_INFO and encoding: lazy_load_dylib_info, with null versions. inspect_macho dependencies are non-exhaustive when that command is present. Catalog text mentions the payload. CI regenerates ignored catalogs.
  • Provider, bridge, target-format, or platform compatibility: little-endian Mach-O only, same as the existing reader. Big-endian slices stay unsupported.
  • Evidence, artifact, provenance, or reconstruction contract: trace evidence gains the lazy edge or an unsupported-image reason. inspect-macho does not claim an install name it did not read from otool.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged. No process launch.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): tool description text only. No package or install change.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: payload order, weak flag, FAT slice offset, truncated payload, bad path offset, unknown flags, flag and chain-start offsets, __TEXT / __LINKEDIT VM range, short segment, shared payload range, contained payload range, aggregate payload limit, payload-range lookup limit, header and symbol offsets inside the 24-byte header, cached string past a shorter payload, repeated and overlapping symbol scans, path NUL in the final payload byte, 65536 symbol references in one payload and across two payloads; filesystem trace with the library present and absent; domain non-traversal and lazy-load-unresolved; a missing may-be-missing lazy image stays lazy-load-unresolved and says dyld continues; inspect-macho non-exhaustive dependency inventory.
  • Base reproduction or other evidence: [Bug] trace-dylib-resolution omits lazy dylib dependencies while reporting complete coverage #5551 records the macOS CLI omission. This environment has no Apple clang or otool, so that CLI script was not replayed. The structural fixture uses the same install name @rpath/libl.dylib, symbol _lf, and 56-byte payload size reported there. [Bug] inspect-macho treats dependencies as exhaustive when LC_LAZY_LOAD_DYLIB_INFO is present #5649 is source-derived from the otool normalizer; its opening text overstates a pre-fix inspectNativeMacho execution that was not captured. The regression was run after the fix. Offset checks follow mach_o::LazyLoadDylib::valid and dyld's linkedit maxVmOffset (Image::validLinkedit).
  • User-visible CLI/MCP output (if applicable): a present lazy edge resolves and coverage stays complete without findings. An absent required one adds lazy-load-unresolved and does not traverse the library. An absent may-be-missing one uses the same kind and says dyld continues if the image is absent. inspect-macho sets dependencies.exhaustive false and mentions 1 LC_LAZY_LOAD_DYLIB_INFO. An out-of-range image offset, a header or symbol string offset, a cached string that runs past a shorter payload, or an over-budget payload, range lookup, string scan, or symbol-reference count leaves the image malformed or unsupported, so coverage does not claim a complete resolution.
  • Remaining proof gaps: no real otool -l / dyld replay, no MCP transport replay, and no check that current Apple linkers still use only flag bit 0.

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

  • npm run check:fast — typecheck and lint passed after e8f68f18d.
  • npm run test:local -- src/artifacts/apple/MachoLoadCommandReader.test.ts — 45 passed.
  • Earlier on this branch, npm run test:local -- src/domain/apple/dylibResolution.test.ts src/artifacts/apple/MachoLoadCommandReader.test.ts — 133 passed, before the symbol-reference cap. The domain file was not rerun for this cap.
  • oxfmt --write on the touched reader, test, and doc.

Not run: npm run check:pr, npm run docs:check, macOS trace-dylib-resolution / inspect-macho CLI, or the #5551 clang script.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for request shape. Callers that assumed every traced dependency was a classic dylib command, or that current_version was always a string, can now see LC_LAZY_LOAD_DYLIB_INFO and null versions. inspect_macho dependencies are no longer exhaustive when this command is present. A slice with more than 65536 lazy-info symbol references is unsupported.
  • Real Hopper/Ghidra, browser, or OS coverage: not run. No engine launch.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only header and payload parsing. Unknown flag bits stay unsupported. Identical and contained payload ranges are not reread, and range lookups stop at 16 MiB comparisons. String validation counts every reference, including repeats and overlaps, and stops at 16 MiB per slice. Symbol references stop at 65536 per slice before those strings are cached. A header or symbol offset inside the 24-byte header cannot become an install name. No new process authority.

Author readiness

Human owner: @morluto

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • 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.
Open in Web Open in Cursor 

Parse the linkedit install name for lazy-load info commands, resolve those
edges without traversing them, and stop inspect-macho from treating an otool
dependency list as exhaustive when that payload is omitted.

Fixes #5551
Fixes #5649

Co-authored-by: morluto <morluto@users.noreply.github.com>
@morluto
morluto marked this pull request as ready for review October 20, 2026 18:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T19:35:02.740873Z e8f68f1 Manual request
ℹ️ 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: f9482b64e7

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

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains in the reviewed changes.

Summary

Adds LC_LAZY_LOAD_DYLIB_INFO dependencies to read-only Mach-O tracing.

  • Mach-O traces now include lazy dependencies stored in linkedit payloads.
  • Mach-O inspection marks payload-only dependency commands as incomplete.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Mach-O load commands] --> B{Dependency encoding}
  B -->|Classic| C[Read command string]
  B -->|Lazy info| D[Check payload bounds and work limits]
  D --> E[Read install name and weak flag]
  C --> F[Resolve dependency]
  E --> F
  F --> G{Lazy command?}
  G -->|Yes| H[Record edge without traversal]
  G -->|No| I[Traverse resolved image]
  D -->|Limit exceeded| J[Unsupported image and partial coverage]
Loading

Reviews (8) · Last reviewed commit: "fix(apple): cap lazy-info symbol string ..." · Reviewed by Greptile

@matbrgz

matbrgz commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Heads-up: Note that PR #5582 (fix(apple): trace LC_LAZY_LOAD_DYLIB_INFO lazy dylib dependencies) was opened earlier by @kaoru0822-kitauji addressing the same LC_LAZY_LOAD_DYLIB_INFO dependency tracing on issues #5551 / #5649 (Cluster BC). Cross-referencing to coordinate review with @morluto.

Reuse identical LC_LAZY_LOAD_DYLIB_INFO ranges, cap their combined size,
and reject flag or chain-start offsets outside the slice VM range.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

Reject payload strings that start in the 24-byte header, validate each
file-offset string once, and reuse payload bytes already read for a
containing range.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@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: 938bb694ad

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

Remember each cached string's terminating offset and require that NUL to
fall inside the payload being decoded.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

Count containment checks across earlier payload reads and stop at the
existing 16 MiB work limit.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

Charge repeated and overlapping LC_LAZY_LOAD_DYLIB_INFO scans against the
16 MiB validation budget, and stop a scan once that budget is exhausted.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@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: c7c5eab41c

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

Stop after 1024 LC_LAZY_LOAD_DYLIB_INFO commands so a load-command region
full of identical commands cannot become a million traced edges.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@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: e7cd50f27d

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

dyld stops the load-path scan before the payload's last byte, so a
terminator in that byte leaves the image malformed.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@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: bcd0e66502

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

A missing LC_LAZY_LOAD_DYLIB_INFO with the may-be-missing bit is weak, so the lazy finding says dyld continues on first use instead of failing.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@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: fcc2a4fef3

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

A payload of distinct one-byte symbol strings stayed under the byte budgets while caching one entry per offset. A slice now stops at 65536 symbol references.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

@codex review

@morluto
morluto merged commit 23196da into main Oct 20, 2026
7 of 10 checks passed
@morluto
morluto deleted the cursor/macho-lazy-dylib-info-eba5 branch October 20, 2026 19:33

@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: e8f68f18d2

ℹ️ 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 on lines +424 to +427
if (command === LC_SEGMENT || command === LC_SEGMENT_64) {
const span = readSegmentSpan(body, command === LC_SEGMENT_64);
if (span === undefined) unreadableSegment ??= index;
else segments.push(span);

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 Skip segment-span allocation without lazy-info commands

When an image has no LC_LAZY_LOAD_DYLIB_INFO, these spans are never used, but a crafted 16 MiB load-command region can contain roughly 300,000 56-byte LC_SEGMENT commands, causing every command to decode a string and retain an object with two bigint values until decoding completes. This adds substantial CPU and heap expansion to ordinary Mach-O parsing solely for metadata needed by the new lazy-info path; first detect whether a lazy-info command exists or otherwise avoid retaining segment spans unless that validation is required.

AGENTS.md reference: AGENTS.md:L77-L77

Useful? React with 👍 / 👎.

@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
3 tasks done
@morluto morluto added area: build Build, CI, packaging, and publishing bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] trace-dylib-resolution omits lazy dylib dependencies while reporting complete coverage

3 participants