Skip to content

fix(native)!: correct Mach-O dispatch admission and errors - #7701

Closed
dreinst wants to merge 3 commits into
morluto:mainfrom
dreinst:dreinst/bug-dispatch-metadata-rejects-a-walkable-4097-co
Closed

dreinst wants to merge 3 commits into
morluto:mainfrom
dreinst:dreinst/bug-dispatch-metadata-rejects-a-walkable-4097-co

Conversation

@dreinst

@dreinst dreinst commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

Fixes #7696. inspect-native-dispatch-metadata rejected a fully present, aligned Mach-O command table with 4097 commands as execution_failure ("Malformed Mach-O command bounds") and suggested rea doctor. The same table with 4096 commands succeeded. It now decodes both.

Problem and expected behavior

parseMachoLayout (src/native/AppleMachoSelection.ts) combined a hardcoded commands > 4096 check with the out-of-file extent check. Neither the Mach-O format, dyld's command walker nor docs/native-investigation.md defines a 4096 command ceiling, so a count alone should not mark a walkable table as malformed.

Change and scope

Drop the count operand and keep the extent check (commandEnd > sliceEnd). The shared MachoLoadCommandCursor already proves framing: every command needs at least 8 bytes inside sizeofcmds, and finish() requires both ncmds and sizeofcmds to be consumed exactly. A huge declared ncmds with a small sizeofcmds still stops at the first command beyond the declared bytes, so the walk stays bounded by the file budget.

The related malformed and unsupported format refusals are now classified at the dispatch boundary as unsupported_target, preserving their reasons rather than advising provider repair. Fixes #7652. Unexpected execution failures remain provider failures.

Scope decision: not applicable (fix within an existing read-only static reader).

Contract and boundary impact

  • Semantic owner and earliest changed stage: parseMachoLayout admission of the selected slice's command table; framing remains owned by MachoLoadCommandCursor. No superseded paths remain.
  • Contribution scope fit and linked maintainer decision: ordinary fix, not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. Inputs with more than 4096 walkable commands now return dispatch metadata instead of execution_failure.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata, package, or installation impact: none.

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

  • Tests added or updated: src/native/AppleMachoSelection.test.ts adds a test that a 4097 command LC_SOURCE_VERSION table parses, and that declaring 4097 commands with only 4096×16 bytes is still rejected (load command 4096 starts beyond sizeofcmds).
  • Base reproduction or other evidence: with the > 4096 check restored, the new test fails (executed).
  • User-visible CLI/MCP output: with the issue's fixtures after npm run build:cached, node scripts/rea.mjs inspect-native-dispatch-metadata <fixture> --format json exits 0 with objc_classes: [] for both 4096 and 4097 commands (executed).
  • Remaining proof gaps: MCP path, real binaries with many commands, and other architectures were not exercised.

Boundary regressions covered: malformed framing (count beyond declared bytes) stays rejected; valid input above the former cap is accepted. No lifecycle stages involved.

  • 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

  • npm run test:local -- src/native/AppleMachoSelection.test.ts src/native/AppleDispatchMetadata.test.ts src/domain/apple/machoLoadCommands.test.ts: 174 passed
  • npm run check:fast: passed
  • npm run build:cached and the CLI comparison above: both fixtures exit 0

Runs used Node.js v24.16.0 (dependencies installed with npm ci --engine-strict=false), not the pinned 24.22.1.

Follow-up validation for #7652

  • 171 Mach-O layout, dispatch and classification source tests passed, including misaligned Objective-C class, protocol and category lists, Swift type and conformance sections, and malformed load-command framing.
  • Built public CLI regression passed: a walkable 4097-command table succeeds and an unaligned class-list section returns unsupported_target with its format reason.
  • npm run check:fast and git diff --check passed with pinned Node 24.22.1. MCP and real malformed binaries were not verified.

Compatibility, safety, and release

  • Breaking change: malformed or unsupported Mach-O format refusals now use unsupported_target instead of execution_failure. Clients matching error codes should account for this classification.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; static reader only, macOS arm64 host.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the walk remains bounded by sizeofcmds and the file input budget.

Related dispatch fallback failure (#7651)

If direct binary metadata reading fails and symbol fallback also fails or returns malformed output, the fallback error now retains the original reader failure alongside the fallback observation. The 32-bit reader refusal remains available instead of being lost.

Validation on this PR head: npm run test:focused -- src/application/native/NativeDispatchMetadataInspection.fallback.test.ts tests/acceptance/nativeDispatchFallbackFailure.test.ts tests/boundary/cli/nativeDispatchFormatAdmission.test.ts passed 4 tests; npm run check:fast passed. No real disassembler provider was used.

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.

parseMachoLayout rejected any table with more than 4096 load commands as
malformed bounds, even when the table was fully present and aligned. The
shared cursor already bounds the walk by sizeofcmds, so drop the count
operand and keep the out-of-file extent check.

Fixes morluto#7696
@chatgpt-codex-connector

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-28T02:52:04.598783Z
We couldn’t complete this review. Comment @codex review to try again.
823f50f PR opened
ℹ️ 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

This PR removes the 4096-command ceiling while keeping Mach-O framing checks. It also classifies malformed metadata as unsupported_target and preserves the binary reader’s reason when symbol fallback fails.

  • Mach-O readers accept complete command tables above 4096 commands.
  • Malformed Mach-O metadata is reported as a target-format refusal.
  • Failed symbol fallback keeps the original binary-reader reason.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read binary dispatch metadata] --> B{Result}
  B -->|Success| C[Return validated metadata]
  B -->|Unsupported capability, cleanup complete| D[Read symbols]
  B -->|Other failure| E[Return binary reader error]
  D --> F{Result}
  F -->|Valid inventory| G[Return symbol-only metadata]
  F -->|Failure or invalid inventory| H[Return fallback error with binary reader diagnostics]
Loading

Reviews (3) · Last reviewed commit: "fix(native): retain dispatch reader fail..." · Reviewed by Greptile

@morluto morluto changed the title fix(native): walk Mach-O dispatch command tables without a count cap fix(native)!: correct Mach-O dispatch admission and errors Oct 28, 2026
@dreinst dreinst closed this Oct 29, 2026
gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
@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

2 participants