Skip to content

fix(native): retain partial metadata when a protocol-list slot is unmapped - #2639

Closed
sx4im wants to merge 10 commits into
morluto:mainfrom
sx4im:fix/2610-native-protocol-list-unmapped-partial
Closed

sx4im wants to merge 10 commits into
morluto:mainfrom
sx4im:fix/2610-native-protocol-list-unmapped-partial

Conversation

@sx4im

@sx4im sx4im commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2610.

A Mach-O image with valid Objective-C class metadata and an unmapped __objc_protolist slot failed its entire static dispatch-metadata decode. The class-list loop already records per-slot mapping failures into partial coverage, but the protocol-list loop read its slot pointer unguarded, so the same unmapped pointer aborted the whole decode before protocolReader.record could handle the record. Now the protocol-list slot uses the same guard as the class-list slot: the failure is recorded, the objc_class_method_ivar_metadata facet coverage becomes partial with a reason naming the mapping failure, and the independently decodable class is retained.

Problem and expected behavior

Smallest trigger: build the 4096-byte fixture from the issue with the protocol-list section address pointing at an unmapped page (base + 0x9000). The decode throws RangeError: Unmapped or ambiguous metadata pointer 0x100009000 out of decodeObjcDispatchFacets at the protolist loop (AppleObjcDispatchFacets.ts:203). Expected: partial coverage with a reason identifying the mapping failure while RetainedClass and its coverage records still reach the caller, matching the existing behavior for an unmapped class-list slot.

Change and scope

Wrapped the per-slot pointer read in the __objc_protolist loop in the same try/catch shape the __objc_classlist loop already uses in the same function: the field address is hoisted, the failure is pushed to failures as <field>: <message>, and the loop continues. pushDispatchCoverage already turns those failure strings into partial facet coverage with a reason, so no other code changes were needed. Added three regression tests in src/native/AppleDispatchMetadata.test.ts using the fixture from the issue verbatim (controls neither, class, protocol).

Scope decision: not applicable. This is a routine fix inside the existing decode boundary; no new providers, no target execution, no new scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Apple dispatch metadata decode (decodeObjcDispatchFacets, src/native/AppleObjcDispatchFacets.ts).
  • Contribution scope fit and linked maintainer decision: routine bug fix within existing boundaries; no scope expansion.
  • CLI and MCP/tool-catalog contract: none; no tool or contract changes.
  • Provider, bridge, target-format, or platform compatibility: Mach-O arm64 static decode only; fully mapped images decode exactly as before.
  • Evidence, artifact, provenance, or reconstruction contract: the coverage reason now names the unmapped protocol slot instead of the whole decode failing with no result.
  • Target selection, authority, upstream behavior, and cleanup details: 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: 3 tests in src/native/AppleDispatchMetadata.test.ts ("Apple dispatch unmapped protocol-list slot"), fixture builder taken verbatim from the issue.
  • Base reproduction or other evidence: on the base revision the bad-protocol control threw RangeError: Unmapped or ambiguous metadata pointer 0x100009000 (new test failed red); after the fix the same control returns RetainedClass with the facet coverage partial and the reason containing 0x100009000. The neither control still returns the class with complete coverage, and the class control still yields partial coverage as before.
  • User-visible CLI/MCP output: not applicable.
  • Remaining proof gaps: the issue's NativeMacOSProvider provider-level repro was not exercised; the decoder test covers the root cause directly and the provider path only wraps this decoder.

For evidence-bearing changes:

  • 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/AppleDispatchMetadata.test.ts - 25/25 passed (22 existing + 3 new; the protocol control failed before the fix, passed after)
  • npm run test:local -- src/native/AppleSwiftVtables.test.ts - 3/3 passed (only other test file importing this code path)
  • npm run check:fast - typecheck + lint green
  • npm run verify:test-discovery - all 1024 test files discovered exactly once

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none; source tests exercise the Mach-O decode path directly.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; decode-only change, no new execution paths.

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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T18:49:40.901193Z 98f985b 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: 1737f6dc44

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains in the reviewed changes.

Summary

Retains independently readable Objective-C classes when a protocol-list slot cannot be mapped.

  • Objective-C metadata keeps decoding when a list slot cannot be read.

Reviews (15) · Last reviewed commit: "refactor(test): split Apple dispatch bud..." · Reviewed by Greptile

Comment thread src/native/AppleObjcDispatchFacets.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@sx4im
sx4im force-pushed the fix/2610-native-protocol-list-unmapped-partial branch from f68caf5 to e93f81f Compare October 13, 2026 09:35

@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: e93f81f0aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/AppleObjcDispatchFacets.ts Resolved
Comment thread src/native/AppleObjcDispatchFacets.ts Resolved

@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: 60c53c8b85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/AppleObjcDispatchFacets.ts Resolved
@sx4im

sx4im commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Quick note on the red CI for this head: the failing checks are all in tests unrelated to this diff — tests/boundary/cli/dylibResolutionCli.test.ts (FAT-binary host-arch assertion on the runner) and tests/boundary/filesystem/releaseCheckpoint.test.ts (release-please preflight). Neither file touches the ObjC dispatch code changed here. The native suites for this area (AppleDispatchMetadata including the new regression tests, 180/180) pass, with tsc and oxlint clean. Happy to rebase again once main is green if that helps.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@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: 8d03a3f9a5

ℹ️ 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/AppleObjcDispatchFacets.ts Resolved

@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: 8f674a9cd4

ℹ️ 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/AppleObjcDispatchFacets.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

Protocol and class list scans now share the same readListSlot failure/budget owner. The class-list scanner no longer has an independent unbounded catch path; the existing large class-section regression remains in the branch.

Current source: 8f674a9. Validation: source inspection only; tests and checks were skipped at the user's explicit request.

  1. thread 1

Slot-pointer failures are accounted for before record decoding. Once a mapped pointer reaches readClass, that decoder owns its admission; the class error catch only preserves the decoding failure and never charges the same class again.

Current source: 8f674a9. Validation: source inspection only; tests and checks were skipped at the user's explicit request.

  1. thread 1

The failed-pointer slot is now charged once by a shared readListSlot owner used by both protocol and class lists. Failed slots consume max_records, preserve their actual read failure, and cannot drive work based only on an enormous declared section size.

Current source: 8f674a9. Validation: source inspection only; tests and checks were skipped at the user's explicit request.

  1. thread 1

Zero and duplicate mapped pointers bypass record admission, so a record-only bound did not bound list scanning. The shared slot reader now charges every protocol/class list attempt against one scan limit derived from the caller-selected max_records, separately from record admission. Existing record decoders still charge each actual record once. Class coverage counts only attempted reads; nested protocol and category scanners were inspected and already admit before each slot.

Current source: 8f674a9. Validation: source inspection only; tests and checks were skipped at the user's explicit request.

Comment thread src/native/AppleDispatchCoverage.ts Resolved

@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: c9b7b7e8f7

ℹ️ 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/AppleDispatchCoverage.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

List-scan exhaustion was being written into the global record-admission budget even when no record was consumed. The Objective-C list producer now returns its own scan-truncation fact, and coverage applies it only to objc_class_method_ivar_metadata. Category, relative-pointer and Swift coverage still use their own decode facts and actual global record exhaustion. Updated the coverage consumers and fixtures, and added the two-zero-protocol-slot regression with max_records=1 asserting independent facets remain complete. Failed-slot record accounting and bounded scanning remain intact.

Current source: c9b7b7e. Validation: source inspection only; authored regressions were not executed. Tests, checks, builds and provider execution were skipped at the user's explicit request. No passing runtime or real-provider result is claimed. Directly related representation and consumer cleanup is included.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior P2: medium Medium priority issue labels Oct 13, 2026

@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: a81b75c801

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/AppleDispatchCoverage.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

A class-list slot can be skipped when the scan limit is consumed by zero, duplicate, or unmapped slots before a later class. The decoder now tracks class-list truncation separately and marks the class-dependent Objective-C property and relative-pointer facets partial with the resource-limit reason, while leaving facets read independently unaffected. The fix is public in e26cf8cc34798d51209289ef03bb83df87686361, retained in live head a81b75c8017cd522cfd103c4cef8d8bf78fe3ad4. Validation was source inspection and Git ancestry review only. Tests, builds, checks, and CI reruns were skipped as instructed; no runtime claim is made. No directly related source cleanup remains.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

The producer replaced an unresolved relative-pointer reason when the record cap was reached, losing one independent coverage gap. Coverage now composes both max_records_reached and relative_pointer_targets_unresolved. Public at e0420b5; no tests/checks ran.

@morluto
morluto force-pushed the fix/2610-native-protocol-list-unmapped-partial branch from fef9bb7 to 070f538 Compare October 13, 2026 18:29
sx4im and others added 5 commits October 14, 2026 02:42
…apped

A Mach-O image with valid ObjC class metadata plus one unmapped __objc_protolist
slot failed its ENTIRE dispatch-metadata inspection. The class-list loop already
produced partial coverage on bad slots; the protocol-list guard now mirrors it.

Failed protocol slots now also spend one read-budget unit each (previously they
bypassed the budget, so a crafted image declaring a huge unmapped section could
hang/OOM inspection); crafted sections truncate at maxRecords.

Rebased onto morluto/rea e05d339 to pick up the upstream FAT-fixture CI fix.
Same budget-bypass flaw the protocol-list guard fixed: read.pointer(field)
throws before readClass can run, so failed class-list slots never spent the
record budget and a crafted tiny Mach-O declaring a huge unmapped
__objc_classlist section drove unbounded CPU and unbounded failure strings.
The class-list catch now mirrors the protocol-list one: each failed slot
admits once to the budget, truncating at maxRecords with
max_records_reached; successful slots keep spending exactly one unit via
readClass's internal admit.

Regression test: "bounds failed class-list slots by the record budget"
(10,000 declared unmapped slots -> failures <= 100, reason contains
max_records_reached); red before, green after.
readClass and protocolReader.record admit the record budget themselves
before anything in them can throw, so the loop catch admitting again
counted one mapped-but-malformed class/protocol twice: at the budget
boundary it broke before appending the failure reason (reporting only
max_records_reached), and with larger limits malformed entries starved
valid ones behind them.

Split each loop's single try/catch into two stages: the slot-pointer
read keeps the admit-on-failure guard (unmapped slots must still spend
budget, bounding crafted file-declared section sizes); the
readClass/record stage only records the failure, since its slot was
already admitted inside the callee.
@morluto
morluto force-pushed the fix/2610-native-protocol-list-unmapped-partial branch from 070f538 to 98f985b Compare October 13, 2026 18:42
morluto added a commit that referenced this pull request Oct 14, 2026
Preserve XML and Interface Builder identity at their parsing boundary, retain usable Objective-C slots with precise coverage, and keep native trace failures distinct from absence. Add caller-selected Interface Builder summaries backed by complete retained Evidence, and preserve comparison limitations.

Reviewed fixes: #1969, #2088, #2108, #2513, #2639, #2684, #2731, #2759, #2875, #2888, #2889, #2970, #2971, #3002.

Validation: relevant native/domain focused lane passed 142 tests; earlier Interface Builder/MCP checks passed 24 tests. Real native UI and Ghidra producer coverage was not repeated.
@sx4im

sx4im commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — 55dd21a carries the same fix on main (verified the file matches) with additional coverage. Thanks for taking it the rest of the way.

@sx4im sx4im closed this Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @sx4im for finding that one unmapped Objective-C protocol-list slot could discard otherwise usable metadata. Main now retains the partial facts and reports the corresponding coverage gap (main).

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 P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(native): retain partial metadata when a protocol-list slot is unmapped

2 participants