Skip to content

fix(native)!: own Mach-O load commands in binary reader - #7952

Merged
morluto merged 12 commits into
mainfrom
codex/macho-multiline-name-7391
Oct 29, 2026
Merged

morluto merged 12 commits into
mainfrom
codex/macho-multiline-name-7391

Conversation

@morluto

@morluto morluto commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #7391. A linker-generated section name containing a newline no longer makes inspect_macho misinterpret name bytes as load-command framing.

Problem and expected behavior

otool emits names as unescaped text. Newlines or field-shaped names can therefore change the parser's interpretation of command and section boundaries. Inspection must preserve the selected binary's facts without treating name contents as control text.

Change and scope

Read load-command framing and modeled fields from a bounded, identity-verified binary source; remove the superseded text command parser. Resolve and verify the selected FAT declaration and thin header, retain source and cleanup ownership, bound locations and image-base derivation to the selected slice, and preserve exact format failure reasons. The selected-slice identity fix from #7940 is now on main.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the binary reader owns command framing and fields; inspection, UUID reconciliation, CLI and MCP consume its projection.
  • Contribution scope fit and linked maintainer decision: ordinary read-only native inspection fix; no new target execution authority.
  • CLI and MCP/tool-catalog contract: the same operation and one Evidence schema; names can be null with exact byte hex when undecodable, and unsafe integers have exact hex adjuncts. Consumers must handle these unknowns.
  • Provider, bridge, target-format, or platform compatibility: legacy command records remain admitted. Unknown and partially modeled command fields have explicit limitations and binary offset, size and available digest. Row completeness remains distinct from field completeness.
  • Evidence, artifact, provenance, or reconstruction contract: historical Evidence without optional byte/hex fields remains readable. The output no longer includes arbitrary fields invented by otool; undecoded payload bytes remain in the selected artifact, not in the response.
  • Target selection, authority, upstream behavior, and cleanup details: file identity and digest are checked around the operation, including thrown failures; failed cleanup retains its owner. Structural FAT fallback is used only for a unique matching row.
  • Generated metadata, package, or installation impact: generated catalog validated; no generated artifacts committed.

Expected effects:

  • 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

Real macOS ARM64 CLI tests use an Apple linker-generated multiline section name and a patched invalid UTF-8 name, verify bytes are preserved, and check the target is unchanged. Binary-backed boundaries cover misleading names, legacy commands, selected FAT rows, missing and contradictory lipo ranges, malformed counts, out-of-slice locations, and SDK-converted MCP schemas. Lifecycle tests cover mutation, cancellation during successful and failed close, retained completed Evidence, mixed primary/cleanup failures, and retry. Retained command bytes own their backing storage; projected sections, nested records, strings and fixed envelope are charged before retention. Other Apple architectures and toolchains were not independently exercised.

  • 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

  • Combined focused acceptance, provider-boundary and MCP suite — 193 tests passed on macOS ARM64.
  • Source reader, projection, inspection, slice and lifecycle tests — 76 tests passed.
  • Follow-up source tests — 59 passed, including malformed command classification and image-base bounds; 39 focused CLI/provider tests passed after the bounds fix.
  • Follow-up: 34 source tests and 46 focused CLI, MCP, slice-ownership and direct-analysis cleanup tests passed on macOS ARM64.
  • npm run check:fast — passed on the follow-up diff.
  • npm run docs:check — passed.
  • git diff --check — passed.

Compatibility, safety, and release

  • Breaking change: consumers that assumed every name is a string must handle null and optional byte hex; unsafe numeric sizes and offsets can be null with exact hex. Historical Evidence remains accepted by the same schema. This cannot safely retain a fabricated text identity for undecodable bytes.
  • Real provider coverage: macOS ARM64 only; no real Hopper or Ghidra coverage applies. The projection allowance is a conservative serialized-size estimate, not a measured cap on total process memory.
  • No target mutation or additional network access is introduced.

Author readiness

Human owner:

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-29T00:32:05.185301Z b4c4e2e New commits
ℹ️ 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: fa19c869ce

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

Comment thread src/native/MachoBinaryProjection.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no new actionable issue remains.

Summary

inspect_macho now reads load commands from identity-checked binary bytes instead of otool text.

  • Mach-O inspection reads load commands from the selected binary bytes.
  • Mach-O inspection checks the selected slice before using its fields and locations.
  • Mach-O Evidence keeps exact name bytes and unsafe number values available to callers.
  • Failed direct analyses keep the caller's exact path in partial Evidence.

This review used source and regression-test inspection; no tests were run. Whether another PR supersedes this one could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Selected artifact] --> B[Verify file identity and digest]
  B --> C[Resolve selected slice]
  C --> D[Read bounded binary commands]
  D --> E[Project facts and explicit unknowns]
  E --> F[Verify source again]
  F --> G[Close descriptor]
  G --> H[Return observation]
  G --> I[Close failure or late cancellation]
  I --> J[Retain verified Evidence and cleanup owner]
Loading

Reviews (3) · Last reviewed commit: "fix: reserve Mach-O projection envelope ..." · Reviewed by Greptile

Comment thread src/native/MachoBinaryProjection.ts Resolved
Comment thread src/native/MachoBinaryProjection.ts Resolved
Comment thread src/native/NativeMacOSProvider.ts Resolved
Comment thread src/native/NativeMacOSProvider.ts Resolved
Base automatically changed from codex/macho-selected-row-7350 to main October 28, 2026 23:57
Comment thread src/native/MachoCommandNames.ts Resolved
@morluto
morluto merged commit 640e19d into main Oct 29, 2026
4 of 6 checks passed
@morluto
morluto deleted the codex/macho-multiline-name-7391 branch October 29, 2026 00:37
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 29, 2026
Upstream main at 70a8325 fails oxfmt 0.72.0 on these files (from
morluto#7952 and a docs table). Formatting only; the integration branch's
format check needs it until main formats them.
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 22, 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] inspect-macho aborts on a linker-generated section name containing a line break

1 participant