Repository navigation
fix(native): retain every repeated otool load-command field - #4048
Conversation
`inspect-macho` stored each `otool -l` row in a flat record, so a key printed more than once kept only its last value. A two-string LC_LINKER_OPTION lost `-framework` and kept `#2 Foundation`, and a multi-tool LC_BUILD_VERSION kept only its last tool, while the collection still claimed exhaustive coverage. Linker-option strings are now keyed by otool's own `string #n` label with the exact option text and must match the declared count. Any other repeated key is labeled `key #n` in print order. Dylib encoding checks read the parsed rows, so repeated `options` rows are still rejected. Fixes #4008 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryPreserves repeated
No actionable defects or new security issues were found. Tests were not run during this review. Superseded status could not be checked because GitHub authentication was unavailable. kaoru0822-kitauji explicitly identifies rejection of newline-containing options and renamed public keys as intentional in the PR description. Reviews (1) · Last reviewed commit: "fix(native): retain every repeated otool..." · Reviewed by Greptile |
Summary
Fixes #4008.
inspect-macholost everyLC_LINKER_OPTIONstring except the last one. The surviving value kept otool's#nprefix, and the collection still reportedexhaustive: truewith no limitations. Each string is now retained exactly, in order, and checked against the declaredcount. The same root cause also dropped all but the last tool from a multi-toolLC_BUILD_VERSIONrecord, and that is fixed too.Problem and expected behavior
parseFieldsinsrc/native/parsers/otool.tsturned everyotool -lrow into one entry of a flatkey → valuerecord, so a key printed twice overwrote the earlier value. Reproduced on main with the issue's command and a real clang object:{"cmd":"LC_LINKER_OPTION","cmdsize":40,"count":2,"string":"#2 Foundation"}otool -lprintsstring #1 -frameworkandstring #2 Foundation. A three-toolLC_BUILD_VERSION(built withvtool) kept onlytool: 2, version: "6.0"infields. Itsbuild_metadatawas already complete, because that path re-reads the block.Change and scope
parseFields/parseField):string #1,string #2, …), at every count. The value is the exact option text, including surrounding spaces, and is never coerced to a number.key #nin print order. Keys printed once are unchanged, so existing single-tool and other records keep their shape.validateLinkerOptionLines:countmust be unique, and the remaining rows must be exactlystring #1..count, in order. A mismatch, a repeated or out-of-order ordinal, or an unlabeled row throws, the same way the existing build-tool, section-count and dylib framing checks do.validateDylibCommandLinesnow checks encoding-field presence on the parsed rows rather than the labeled record. Repeatedoptionsrows are still rejected with the existing reason.docs/native-investigation.mddocuments thename #nandstring #nkeys.fieldsremainsrecord<string, string | number | null>.Contract and boundary impact
Semantic owner and earliest changed stage:
src/native/parsers/otool.ts(parseOtoolLoadCommands), which owns the parsing of otool load-command text. No downstream code readsfieldskeys.Contribution scope fit and linked maintainer decision: a bug fix within the existing static, read-only boundary; not applicable.
CLI and MCP/tool-catalog contract: output schema unchanged.
load_commands.items[].fieldsnow keeps every repeated row. A singlestringkey onLC_LINKER_OPTIONbecomesstring #n.Provider, bridge, target-format, or platform compatibility: macOS native provider (
otool) only.Evidence, artifact, provenance, or reconstruction contract: removes silent loss from exhaustive Evidence. Malformed linker-option framing now fails closed instead of returning a lossy record. On such input
llvm-nmalready fails the inspection.Target selection, authority, upstream behavior, and cleanup details: not applicable.
Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Evidence and regression coverage
tests/boundary/cli/nativeMachoLinkerOptionsCli.test.ts(macOS only): a public CLI workflow on a realxcrun clang -cobject with two linker options.tests/boundary/providers/native/nativeLoadKinds.golden.test.ts:count, out-of-order or repeated ordinals, and an unlabeled row;fieldsof the existing two-toolLC_BUILD_VERSIONcase, plus the unchanged single-tool shape.otool.tsrestored, these tests fail (8 failed / 47 passed across the two files). With the fix, they pass.inspect-macho --json:LC_LINKER_OPTION(count 2)"string":"#2 Foundation""string #1":"-framework","string #2":"Foundation"LC_LINKER_OPTION(count 3)"string":"#3 -ObjC""string #1":"-weak_framework","string #2":"Security","string #3":"-ObjC"LC_BUILD_VERSION(3 tools,vtool)"tool":2,"version":"6.0""tool #1":3,"version #1":"1100.1",…,"tool #3":2,"version #3":"6.0"options.o)parseOtoolLoadCommandson/opt/homebrew/bin/node'sotool -h -loutput (45 commands, 364 lines, no repeated keys) has a median of 0.234 ms on base and 0.294 ms with the fix, over 200 runs after warm-up. The serialized commands are byte-identical (9,542 bytes). The CLI inspection takes ~1.1 s either way, dominated by the external tools.LC_LINKER_OPTIONstrings containing a newline (which otool prints ambiguously) now fail closed rather than being guessed. That behavior is exercised only through the unlabeled-row test.Validation performed
npm run test:focused -- <8 native Mach-O parser/CLI test files>— 126 passed.npx vitest run tests/boundary/providers/native tests/boundary/native tests/boundary/cli/nativeMacho tests/boundary/cli/dylib tests/boundary/mcp/analysisView— 38 files, 375 passed.npm run check:fast,npx oxfmt --checkon the changed files,npm run docs:check— passed..linker_optionobject, avtoolthree-tool executable, and/opt/homebrew/bin/node, run through the built CLI (node scripts/rea.mjs inspect-macho … --json).Compatibility, safety, and release
fieldsis an untyped raw-row record.LC_LINKER_OPTIONrecords now carrystring #1..countinstead of onestringkey. That key only ever held the last option, with otool's#nprefix, so it never carried a complete value. Records whose keys appear once are unchanged. Maintainers may prefer a!marker; I can add one on request.Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code