Repository navigation
fix(apple): read LC_LAZY_LOAD_DYLIB_INFO dependency payloads - #5650
Conversation
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>
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: 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".
[Medium impact] The PR appears safe to merge; no blocking issue remains in the reviewed changes. SummaryAdds
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]
Reviews (8) · Last reviewed commit: "fix(apple): cap lazy-info symbol string ..." · Reviewed by Greptile |
|
Heads-up: Note that PR #5582 ( |
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>
|
@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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@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>
|
@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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@codex review |
There was a problem hiding this comment.
💡 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".
| 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); |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Fixes #5551 and #5649.
trace-dylib-resolutiondroppedLC_LAZY_LOAD_DYLIB_INFO(0x3a) and still reported complete coverage.inspect-machokept that command as a raw load command and still marked the dependency list exhaustive.Seed audit on main
b3aadaf47: #5606 is already closed by2b263a7fe. #5542 and #5462 are already rejected at FAT admission by497037e6e(machoContainer.test.tsandbinaryTarget.test.tsstill 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 command0x3a, so the trace listed only the other dependencies and setcoverage.statustocomplete.otool -lprints the command without anamefield; the inspection normalizer treated the resulting dependency list as exhaustive.The payload install name is a dependency. It is resolved like
LC_LAZY_LOAD_DYLIBand not traversed, because dyld loads it on first use. An absent image islazy-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 isweak. Unrecognized flag bits leave the image unsupported instead of inventingweak: 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-machokeeps 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__TEXTvmaddr. 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
MachoLoadCommandReaderfor structural dependency facts;parseOtoolLoadCommandsfor the otool dependency inventory. Both change before trace coverage and inspect-macho presentation.trace_dylib_resolutionedges may includecommand: LC_LAZY_LOAD_DYLIB_INFOandencoding: lazy_load_dylib_info, with null versions.inspect_machodependencies are non-exhaustive when that command is present. Catalog text mentions the payload. CI regenerates ignored catalogs.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; 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.
Evidence and regression coverage
__TEXT/__LINKEDITVM 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 andlazy-load-unresolved; a missing may-be-missing lazy image stayslazy-load-unresolvedand says dyld continues; inspect-macho non-exhaustive dependency inventory.@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-fixinspectNativeMachoexecution that was not captured. The regression was run after the fix. Offset checks followmach_o::LazyLoadDylib::validand dyld's linkeditmaxVmOffset(Image::validLinkedit).completewithout findings. An absent required one addslazy-load-unresolvedand 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 setsdependencies.exhaustivefalse and mentions1 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.otool -l/dyldreplay, no MCP transport replay, and no check that current Apple linkers still use only flag bit 0.For evidence-bearing changes:
Validation performed
npm run check:fast— typecheck and lint passed aftere8f68f18d.npm run test:local -- src/artifacts/apple/MachoLoadCommandReader.test.ts— 45 passed.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 --writeon the touched reader, test, and doc.Not run:
npm run check:pr,npm run docs:check, macOStrace-dylib-resolution/inspect-machoCLI, or the #5551 clang script.Compatibility, safety, and release
current_versionwas always a string, can now seeLC_LAZY_LOAD_DYLIB_INFOand null versions.inspect_machodependencies are no longer exhaustive when this command is present. A slice with more than 65536 lazy-info symbol references is unsupported.Author readiness
Human owner: @morluto
Before merge
type(scope): outcome.