Skip to content

fix(native): preserve Mach-O install-name whitespace - #4979

Merged
morluto merged 3 commits into
morluto:mainfrom
flyl1u:codex/fix-macho-install-name-whitespace
Oct 22, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
flyl1u:codex/fix-macho-install-name-whitespace

Conversation

@flyl1u

@flyl1u flyl1u commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3384. Preserve whitespace in Mach-O install names and rpaths so inspect-macho reports the recorded dependency identity, including " leading.dylib ", consistently with import sources.

Continues the closed, unmerged #3430 by @bharadwajdaya. The original fix is cherry-picked with its author metadata preserved; this PR adapts it to current main and adds broader regressions and real CLI/stdio MCP verification.

Problem and expected behavior

The generic field parser trims the install name and can misread name version 2.dylib as a name version key. The offset-removal expression also consumes trailing whitespace belonging to the name. Parse the exact name/path <value> (offset N) format before generic fields and remove only the final display annotation.

Change and scope

Keep the correction at the owning otool parser. Preserve upstream linker-option parsing and the exclusion of LC_ID_DYLIB from dependencies. Extend the existing Apple verifier with independent compiled inputs; fixture executables are never run. CR/LF names remain outside this fix.

Contract and boundary impact

  • Semantic owner: parseOtoolLoadCommands; consumers use its parsed fields and dependency names directly.
  • Scope decision: not applicable; routine correctness fix within existing static-inspection boundaries.
  • CLI/MCP/catalog: existing arguments and schemas; corrected string values.
  • Compatibility: Apple otool load-command output; no new provider or dependency.
  • Evidence: preserve source names, raw load-command fields, provenance and adapter parity.
  • Authority/cleanup: existing inspection authority; verifier owns and removes its temporary inputs and closes MCP transports.
  • Generated metadata/package/install: no changes.

Expected product effects:

  • Read existing files or captured data.

Evidence and regression coverage

  • On base b83b9caf4, the expanded native-load test fails 3 cases (spaces, tabs, version prefix), with 57 passing. With the fix, all 60 pass.
  • Additional controls preserve an embedded (offset 99), a numeric name and an ordinary name; each checks dependency values and raw name/path fields.
  • Six relevant parser/provider files pass 132 tests, including malformed framing, missing/repeated fields, dylib-use options, linker options and self-identity coverage.
  • The Apple verifier compiles ordinary/spaced install names, checks real otool output and import sources, compares public CLI/MCP results, and verifies input bytes remain unchanged.
  • The ordinary control expects dyld_info's native leading abbreviation. The padded name retains its full import source; the verifier checks both cases explicitly.
  • Real macOS CLI/MCP E2E passed on this PR's exact head, 7f66bccdadfe16abf72d0b3802b58470f3490b6a.
  • Remaining gate: upstream PR workflows await maintainer approval for the external contribution. Historical fix(native): preserve whitespace in otool load-command strings #3430 results are not claimed as this PR's validation.

Verified field projection from both adapters (other dependency/import items omitted):

{
  "dependencies": { "items": [{ "path": "  leading.dylib  " }] },
  "imports": { "items": [{ "name": "_exported_value", "source": "  leading.dylib  " }] }
}

Validation performed

  • Windows x64, Node 24.18.0 / npm 11.16.0.
  • Focused tests below: 132 passed.
  • npm run check: passed (typecheck, lint, formatting, knip, metadata and architecture guards).
  • npm run check:fast: passed in pre-push.
  • git diff --check: passed.
  • npm run verify:macos-bundle: passed with real Apple utilities and public CLI/stdio MCP on the macos-15 runner; both install-name cases retained their bytes and matched across adapters.
  • The Apple lane's existing focused regressions: 19 files, 261 passed, 4 skipped.
  • Full fork CI: passed, 39 jobs concluded with no failures, on exact head 7f66bccdadfe16abf72d0b3802b58470f3490b6a. This is fork verification; upstream PR workflows still require maintainer approval.
Focused test command and local prerequisite
npm run test:focused -- tests/boundary/providers/native/nativeLoadKinds.golden.test.ts tests/boundary/providers/native/nativeLoadText.golden.test.ts tests/boundary/providers/native/nativeInventory.golden.test.ts tests/boundary/providers/native/nativeMachoHeader.golden.test.ts tests/boundary/providers/native/nativeTextRobustness.test.ts src/native/NativeMachoInspection.test.ts

The first attempt stopped before tests because Windows native controls were absent. The matching 6.6.0 controls were restored from upstream CI run 39100876382 at the same base SHA; subsequent baseline and fixed runs completed. These ignored artifacts are not included in the PR.

Compatibility, safety, and release

  • No schema migration or package metadata changes.
  • Real platform coverage: macos-15 CLI/MCP lane passed; no Hopper/Ghidra claim.
  • Static parsing only. Verification compiles disposable self-owned inputs and launches CLT/REA subprocesses without executing the fixture programs.

Merge follow-up: integrated main 15ec8e98d, adapting the install-name verifier to the current advertised MCP-schema helper and named output contract. On macOS with Node 24.18.0, all six focused parser/provider files passed 142 tests and check:ci:fast passed all five tasks. npm run verify:macos-bundle passed locally with real Apple tools, public CLI and stdio MCP: ordinary and whitespace-padded install names and padded rpaths matched across adapters, original bytes remained unchanged, and temporary DMG cleanup completed. Hosted checks on the merged head are pending.

Author readiness

Human owner: @flyl1u

  • 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.

Co-authored-by: Bhaaraadwaj [email protected]

bharadwajdaya and others added 2 commits October 18, 2026 14:18
otool prints dylib install names and rpaths as `<key> %s (offset %u)`
with exactly one separator space around the recorded string. The parser
trimmed the value and stripped the offset suffix with `\s+`, so a valid
install name such as "  leading.dylib  " became "leading.dylib" in both
the dependency inventory and the raw load-command fields.

Parse these offset-suffixed string fields by their exact format and
strip only the single-space offset suffix.

Fixes morluto#3384

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@flyl1u
flyl1u force-pushed the codex/fix-macho-install-name-whitespace branch from 099de26 to 7f66bcc Compare October 18, 2026 06:38
@flyl1u
flyl1u marked this pull request as ready for review October 18, 2026 07:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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 ⚠️ Failed 2026-10-18T07:08:45.328609Z 7f66bcc Draft marked ready
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Preserves whitespace in Mach-O install names and rpaths at the owning otool parser.

  • Mach-O inspection keeps whitespace inside install names and rpaths.

Reviews (2) · Last reviewed commit: "chore: merge main into Mach-O install-na..." · Reviewed by Greptile

@morluto
morluto merged commit 8b478d0 into morluto:main Oct 22, 2026
4 of 6 checks passed
@morluto

morluto commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Welcome to REA, @flyl1u, and thanks for carrying @bharadwajdaya's Mach-O fix forward. The added whitespace cases and CLI/MCP checks help keep dependency names faithful to what the binary records.

@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior 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: 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.

[Bug] Mach-O dependency inspection removes install-name whitespace

3 participants