Skip to content

fix(apple): bound Interface Builder XML plists by shared value depth - #4114

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/3949-ib-xml-plist-depth
Oct 15, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/3949-ib-xml-plist-depth

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #3949. Interface Builder decoding omitted valid XML plist archives as over budget even though keyed-archive inspection decodes the same files. Its preflight counted raw XML element depth against 128, while REA's shared plist parser bounds zero-based value depth at 128. The plist envelope and dictionary keys add elements but not value depth. The duplicate rule is removed, and the shared parser's limit now decides, so both commands agree.

Problem and expected behavior

The cause was in estimateXmlPlistExpansion (src/artifacts/apple/InterfaceBuilderDecodeBudget.ts). It threw aggregate_decode_budget_exhausted when the open-element depth exceeded 128. At the issue's depth 124, the deepest value sits at plist value depth 127 but XML element depth 129. At depth 125 those are 128 and 130.

Reproduced with the issue's script through the built CLI (decode-interface-builder):

nesting main this PR
123 1 document, Build control, archive_decode complete unchanged
124 (value depth 127) 0 documents, partial, aggregate_decode_budget_exhausted, omitted 1 1 document, Build control, complete
125 (value depth 128) 0 documents, partial, budget exhausted 1 document, Build control, complete
126 (value depth 129) 0 documents, partial, budget exhausted unchanged: explicit budget omission

At 126, inspect-keyed-archive also refuses the archive (Plist exceeds 128 nesting levels), so both commands now share one limit.

Change and scope

  • Removed the element-depth check from the IB XML preflight, along with its now-unused closing/selfClosing token fields. The preflight still applies the representation-size estimate and the DOCTYPE internal-subset refusal.
  • The value-depth limit belongs to parseXmlPropertyList, which already bounds nesting before its recursive decode. IB's XML decode path converts that RangeError into the existing InterfaceBuilderDecodeBudgetExceeded("aggregate_decode_budget_exhausted", …). A too-deep archive therefore stays an explicit omission with partial coverage, not an "invalid" archive. The repository already treats a plist decode RangeError as a resource limit (KeyedArchiveReader).
  • Binary plists and NIBArchive budgets are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: plist value depth is owned by the shared parser (src/domain/propertyListKeys.ts). The IB preflight no longer reinterprets it.

  • Contribution scope fit and linked maintainer decision: a bug fix within the existing static, read-only boundary; not applicable.

  • CLI and MCP/tool-catalog contract: schemas unchanged.

  • Provider, bridge, target-format, or platform compatibility: Interface Builder XML plist archives only.

  • Evidence, artifact, provenance, or reconstruction contract: valid archives are decoded with complete coverage. Over-limit archives keep the documented budget omission and partial coverage.

  • 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: tests/boundary/filesystem/interfaceBuilderBundle.test.ts adds "bounds XML archives by plist value depth, not element depth". One XML archive has its deepest value at exactly value depth 128 and must be decoded. A second, one level deeper, must be omitted with aggregate_decode_budget_exhausted and partial coverage (examined 2, omitted 1). It fails on main, which omits both, and passes with the fix.
  • Real applications, decode-interface-builder, median of 3 runs, main vs this PR:
app main this PR
/System/Applications/TextEdit.app (8 documents, 1,428 nodes, complete) 581 ms, 1,460,792 bytes, result 18d1acdefd399d53 536 ms, identical bytes and result
/Applications/XLD.app (64 documents, 6,528 nodes, partial 64/109) 2,796 ms / 2,116 ms (two runs) 1,940 ms / 2,192 ms (two runs), identical 6,731,008 bytes and result 6676c9d4384bb05c

Output is byte-identical. Timing differences are within run-to-run variance; the removed per-element depth bookkeeping is not a measurable speedup.

  • Remaining proof gaps: no real shipped nib nests deeply enough to cross either rule, so the boundary case is covered by the issue's fixtures and the new test.

Validation performed

  • npx vitest run tests/boundary/filesystem/interfaceBuilderBundle.test.ts — 45 passed, 1 skipped. Against main, the new case fails.
  • npx vitest run tests/boundary/filesystem/interfaceBuilderBundle.test.ts src/artifacts/apple src/domain/propertyListKeys.test.ts tests/boundary/cli/interfaceBuilder tests/acceptance/applications — 63 files, 424 passed, 1 skipped.
  • npm run check:fast — passed. My first test placement exceeded the 150-line describe limit; I moved the test into its own describe block.
  • Issue reproduction and real-app runs, as tabulated.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS system and third-party app bundles.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: recursion stays bounded. The shared parser's iterative depth preflight runs before the recursive plist decode, as it already did for keyed archives.

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.

🤖 Generated with Claude Code

The Interface Builder preflight rejected XML archives whose raw element
depth exceeded 128, but the shared plist parser bounds zero-based value
depth at 128; the plist envelope and dictionary keys add elements, not
value depth. Archives whose deepest value sat at depth 127 or 128 were
therefore omitted as over budget although keyed-archive inspection
decodes them. The preflight's duplicate depth rule is removed; the
shared parser's depth limit is mapped to the existing budget omission,
so deeper archives stay explicitly omitted.

Fixes #3949

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added the track:perf Performance track PRs (issues & perf loop) label Oct 15, 2026
@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 ✅ Completed 2026-10-15T13:33:00.623769Z d246c40 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.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

Interface Builder now uses the shared XML plist value-depth limit instead of counting XML elements.

  • Interface Builder XML archives use the shared plist value-depth limit.

No actionable issues were found in the changes since the previous review. No previous review threads were supplied. Checking whether another PR supersedes this one was blocked because GitHub access required authentication. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "fix(apple): return the decode reservatio..." · Reviewed by Greptile

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

ℹ️ 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 on lines +712 to +716
if (cause instanceof RangeError)
throw new InterfaceBuilderDecodeBudgetExceeded(
"aggregate_decode_budget_exhausted",
cause.message,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the aggregate budget after a depth rejection

When an XML plist exceeds the shared value-depth limit, this catch runs only after analyzeInterfaceBuilderBundle has reserved its decodedReservation from the shared budget (lines 126–134). Previously the raw-depth preflight threw before that reservation; now a sufficiently large, over-depth archive can consume most or all of the 256 MiB budget despite being discarded, causing later valid NIBs to be omitted as aggregate_decode_budget_exhausted. Check the shared depth limit before reserving, or release this reservation when the archive is omitted.

AGENTS.md reference: AGENTS.md:L75-L75

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in d246c40. Root cause: removing the element-depth preflight moved the depth rejection from before decodeBudget.reserve(...) to the shared parser, which runs after it. An over-depth archive therefore kept its reservation even though nothing was retained. The per-document loop now tracks the plist reservation, and the budget-omission path calls a new InterfaceBuilderDecodeBudget.release(). Release is capped at the initial budget, so later documents get that share back. Archives rejected before reserving release 0, and NIBArchive budgeting is unchanged. Tests: the depth test now asserts that exactly one positive reservation is released for the over-depth archive. It fails without the analysis wiring. A unit case checks that release restores bytes and never exceeds the initial budget. Constructing a real starvation case would need a large element-heavy archive under the 32 MiB input cap, so the test verifies the release itself. Validation: npx vitest run src/artifacts/apple src/domain/apple tests/boundary/filesystem/interfaceBuilderBundle.test.ts tests/boundary/cli/interfaceBuilder tests/acceptance/applications passed 68 files (517 passed, 1 skipped), and npm run check:fast passed.

Review follow-up. The removed element-depth preflight rejected an archive
before its plist representation was reserved; the shared depth limit now
rejects it during decoding, after the reservation. A large over-depth
archive therefore kept its share of the aggregate budget and could
starve later valid archives. A document omitted by the budget after
reserving now releases that reservation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

ℹ️ 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 on lines +128 to 130
// Value nesting is bounded by the shared plist parser, which counts plist
// value depth; raw element depth would also count the envelope and keys.
for (const token of xmlPreflightTokens(xml)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce value depth before constructing the DOM

For XML NIBs with a deeply nested <dict>, <array>, or nested <plist> chain, removing the early xmlDepth rejection makes the preflight scan the entire archive and then lets parseXmlPropertyList construct the full xmldom document before its value-depth check runs. The prior code stopped after 129 raw levels; now a crafted archive within the 32 MiB input cap can create and traverse hundreds of thousands of DOM nodes before it is omitted, defeating the intended CPU/memory bound. Add a syntax-aware early value-depth guard before DOMParser rather than relying on the post-DOM parser check.

AGENTS.md reference: AGENTS.md:L49-L50

Useful? React with 👍 / 👎.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 3776f21 into main Oct 15, 2026
32 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/3949-ib-xml-plist-depth branch October 15, 2026 14:38
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior 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 track:perf Performance track PRs (issues & perf loop)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Interface Builder decoding omits XML archives within the plist nesting limit

2 participants