Skip to content

fix(apple): preflight XML plist nesting before keyed archive decoding - #2161

Merged
morluto merged 2 commits into
morluto:mainfrom
Zburgers:fix/2105-xml-plist-depth-preflight
Oct 12, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
Zburgers:fix/2105-xml-plist-depth-preflight

Conversation

@Zburgers

Copy link
Copy Markdown
Contributor

Closes #2105.

Problem

inspect_keyed_archive documents a 128-level nesting limit, but the XML plist path reached recursive decoding before any depth check. plist and the prototype-key traversal in parseXmlPropertyList recurse once per nesting level, so a ~75 KiB, 3,000-level XML plist exhausted the call stack and reported Maximum call stack size exceeded instead of the bounded-resource diagnostic that shallower over-limit documents (129, 200) already produced. The CLI classified both as runcated/limit, so this is not a crash or a classification bypass — the diagnostic was the defect. The binary plist path already had an expansion/depth preflight; the XML path did not.

Fix

�ssertXmlPlistDepthWithinLimit in src/domain/propertyListKeys.ts runs at the top of the XML branch of parseXmlPropertyList, before the DOM substitution and before plist.parse. It is a single-pass, iterative token scan that counts value nesting the way projectPlistValue does — container members nest one level deeper, dictionary keys name members rather than nesting them, and a self-closing element is the value at its own level — and throws the projection's own RangeError("Plist exceeds 128 nesting levels") against the shared, now exported MAX_PLIST_DEPTH.

Consequences of that shape:

  • The guard rejects exactly the documents the projection rejected, at the same boundary: a bare 129-level chain and a valid envelope with a 127-level payload both fail before decoding, while an in-limit envelope decodes as before. Verified empirically at 126/127 (envelope) and 128/129 (bare chain).
  • Callers keep the limit/ runcated classification with no error-handler translation, because the error is the same RangeError type and message the projection already raised for over-limit documents.
  • The guard sits at the shared decoder boundary, so Interface Builder decoding, app-bundle Info.plist resolution, and native inspect_plist gain the same deterministic limit (Interface Builder already preflights at least as strictly, so its behavior is unchanged). The binary plist path keeps its own expansion preflight.

The XML token pattern mirrors the existing Interface Builder estimator. OpenStep autodetection is untouched by this guard, matching the existing preflight's XML-only depth scope.

Behavior

Before vs. after on the issue's synthetic fixtures (exit code 1 in both cases):

Depth Before details.detail After
129 / 200 ... Plist exceeds 128 nesting levels unchanged
3,000 / 4,000 ... Maximum call stack size exceeded ... Plist exceeds 128 nesting levels

Top-level code: "truncated", category: "truncated", details.reason: "limit" are unchanged; only the 3,000+ diagnostic becomes the documented limit.

Tests

  • src/domain/propertyListKeys.test.ts — over-limit rejection with the limit diagnostic for dictionary and array nesting (129/3,000/4,000), in-limit decoding at exactly 128 (including a self-closing empty container chain), and opaque markup (comments, CDATA, doctype with an internal subset) not counting as nesting.
  • src/artifacts/apple/KeyedArchiveReader.test.ts — the issue's deep fixtures (129/200/3,000/4,000) rejected through decodeKeyedArchiveBytes with the limit error rather than a stack error; a valid NSKeyedArchiver XML envelope at the limit decodes with its leaf value preserved; one level past the limit is rejected before decoding.
  • ests/boundary/filesystem/keyedArchiveXmlNesting.test.ts — production boundary through inspectBundleKeyedArchive (reason limit).
  • ests/boundary/cli/keyedArchiveXmlNestingCli.test.ts — the issue's public reproduction through the compiled CLI: exit 1, code: "truncated", category: "truncated", details.reason: "limit".

Validation

  • Reproduced on Windows Node v24.16.0 before the fix (Maximum call stack size exceeded at 3,000/4,000) and confirmed the deterministic limit diagnostic after, both at module level and through the compiled CLI end to end.

pm run test:local (source tests), plus targeted �dapters, domain, �oundary, cli-boundary, and mcp-boundary runs for keyed-archive suites. Pre-existing environmental failures on this host (Windows native addon/IDA/setup-TTY dependent files) were confirmed identical on a pristine main checkout and are unrelated.

  • sc --noEmit, oxlint, oxfmt, �erify:module-boundaries, knip, jscpd (gate green), and docs:check.

Not covered here

  • Real-provider verification (
    pm run verify:keyed-archive) requires macOS/Xcode and was not run; the portable CLI boundary test covers the public path instead.
  • Deeply nested OpenStep ({...}/(...)) plists are not preflighted, consistent with the existing Interface Builder estimator's XML-only depth scope; the XML path is the reported defect.

inspect_keyed_archive documented a 128-level nesting limit, but the XML
plist path reached recursive decoding before any depth check: plist and
the prototype-key traversal in parseXmlPropertyList recurse once per
nesting level, so a ~75 KiB, 3000-level XML plist exhausted the call
stack and reported Maximum call stack size exceeded instead of the
bounded-resource limit that shallower over-limit documents (129, 200)
already produced. The CLI classified both as truncated, so no crash or
classification bypass was involved; the diagnostic was the defect.

Reject excessive nesting in parseXmlPropertyList before any recursive
pass, using the projection's own limit (MAX_PLIST_DEPTH) so the error is
identical to the one projectPlistValue raises: callers keep the
limit/truncated classification with no error-handler translation. Depth
counts values the way the projection does - container members nest one
level deeper, dictionary keys name members rather than nesting, and a
self-closing element is the value at its own level - so the guard
rejects exactly the documents the projection rejected, at the same
boundary, and every in-limit document decodes unchanged. The guard sits
at the shared decoder boundary, so Interface Builder, app Info.plist
resolution and native inspect_plist gain the same deterministic limit;
the binary plist path keeps its existing expansion preflight.

Binary plist behavior, ordinary XML decode, __proto__ omission counting,
and archive digest/Evidence provenance are unchanged. OpenStep
autodetection is untouched by this guard, as the existing Interface
Builder preflight also scopes its depth check to XML.

Regression coverage: decoder unit tests at and just past the limit for
dictionary and array nesting with self-closing and opaque markup,
module tests through decodeKeyedArchiveBytes including a valid
NSKeyedArchiver XML envelope at the limit, a production-boundary test
through inspectBundleKeyedArchive, and the compiled public CLI
reporting code truncated / reason limit for a 3000-level plist.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-12T12:13:20.120093Z 7204786 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.

Reuse the iterative XML decoder document for depth preflight and prototype-key lookup. Bound recursive plist wrappers alongside dictionaries and arrays without interpreting markup inside attributes or DOCTYPE declarations as values.

Validated with 104 focused tests including compiled CLI, MCP prototype-key, and Interface Builder coverage; npm run check and verify:test-discovery passed. No real-provider verification was run.
@morluto
morluto merged commit 7711b00 into morluto:main Oct 12, 2026
28 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto

morluto commented Oct 12, 2026

Copy link
Copy Markdown
Owner

@Zburgers, thank you for adding an iterative XML depth preflight before the plist decoder reaches its recursive passes. Sharing the projection’s 128-level limit means deeply nested files get the established bounded-resource diagnosis instead of an opaque stack-overflow message; the 3,000-level regression makes that failure mode tangible. Welcome to REA!

@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 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_keyed_archive skips XML plist depth preflight before recursive decoding

2 participants