Skip to content

fix(native): preserve whitespace in otool load-command strings - #3430

Closed
bharadwajdaya wants to merge 1 commit into
morluto:mainfrom
bharadwajdaya:fix/3384-macho-install-name-whitespace
Closed

bharadwajdaya wants to merge 1 commit into
morluto:mainfrom
bharadwajdaya:fix/3384-macho-install-name-whitespace

Conversation

@bharadwajdaya

Copy link
Copy Markdown
Contributor

Summary

Fixes #3384. inspect-macho stripped surrounding whitespace from dylib install names, so the valid LC_LOAD_DYLIB name " leading.dylib " was reported as "leading.dylib" while the import source kept the spaced name. With this change the dependency path and the raw load-command name keep the recorded bytes.

Problem and expected behavior

otool prints load-command strings as <key> %s (offset %u), with exactly one separator space on each side of the recorded string. parseField trimmed the value (dropping leading spaces), and stripOffsetSuffix removed the suffix with \s+\(offset\s+\d+\) (dropping trailing spaces). Leading and trailing whitespace is part of the install name, can change loader resolution, and must survive per AGENTS.md identity/source-value preservation.

Change and scope

  • src/native/parsers/otool.ts: name/path fields that end in (offset N) are parsed by their exact otool format, without trimming the value. stripOffsetSuffix now removes only the single-space (offset N) suffix. This keeps normalization at the owning parser (the only producer of dependencies[].path), so no consumer changes are needed.
  • This also stops a name like version 2.dylib from being misread as a name version key, since the exact field match runs before the generic key regex.
  • LC_RPATH path gets the same treatment in raw fields, since otool prints it in the same format.
  • Not included: names containing CR/LF (separate line-framing issue, cf. [Bug] Mach-O export inspection merges names ending in carriage return #3390).

Contract and boundary impact

  • Semantic owner and earliest changed stage: otool load-command parser (parseOtoolLoadCommands).

  • Contribution scope fit and linked maintainer decision: focused bug fix inside existing boundaries; not applicable.

  • CLI and MCP/tool-catalog contract: unchanged schema; values now preserve whitespace.

  • Provider, bridge, target-format, or platform compatibility: macOS otool output only.

  • Evidence, artifact, provenance, or reconstruction contract: dependency path and raw load-command fields now match native output.

  • 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 added or updated: nativeLoadKinds.golden.test.ts — preserves dependency install-name whitespace for a spaced name and an ordinary-name control, checking dependencies[].path and the raw name/path fields.
  • Base reproduction: with the parser change stashed, the new spaced-name case fails (1 failed | 49 passed) and the control passes.
  • User-visible CLI output (issue reproduction, executed on macOS arm64 against the built runtime):
otool:  ·········name···leading.dylib···(offset·24)
exit=0
.normalized_result.load_commands.items[13].fields.name '  leading.dylib   (offset 24)'
.normalized_result.dependencies.items[0].path '  leading.dylib  '
  • Remaining proof gaps: did not run the full check:pr gate; Linux/Windows otool equivalents not exercised.

Validation performed

  • npm run test:focused -- tests/boundary/providers/native/native{LoadKinds,LoadText,Inventory,MachoHeader,TextRobustness}*.test.ts — 5 files, 103 tests passed
  • npm run check:fast — typecheck and lint passed
  • Issue reproduction via node scripts/rea.mjs inspect-macho consumer --json — exit 0, spaced install name preserved (output above)

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS arm64 with Apple otool/clang.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: static parsing only; no new side effects.

Author readiness

Human owner: @bharadwajdaya

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

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T06:17:10.165603Z 0909726 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 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Preserves surrounding whitespace in Mach-O strings at the owning parser.

  • Mach-O load-command names keep their recorded spaces.

No actionable issues were found. Tests were inspected but not run. The live supersession check was blocked because GitHub credentials were unavailable.

Reviews (1) · Last reviewed commit: "fix(native): preserve whitespace in otoo..." · Reviewed by Greptile

@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

2 participants