Repository navigation
fix(apple): bound Interface Builder XML plists by shared value depth - #4114
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The reviewed changes appear safe to merge. SummaryInterface Builder now uses the shared XML plist value-depth limit instead of counting XML elements.
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 |
There was a problem hiding this comment.
💡 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".
| if (cause instanceof RangeError) | ||
| throw new InterfaceBuilderDecodeBudgetExceeded( | ||
| "aggregate_decode_budget_exhausted", | ||
| cause.message, | ||
| ); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
💡 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".
| // 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)) { |
There was a problem hiding this comment.
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 👍 / 👎.
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 threwaggregate_decode_budget_exhaustedwhen 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):archive_decodecompletepartial,aggregate_decode_budget_exhausted, omitted 1partial, budget exhaustedpartial, budget exhaustedAt 126,
inspect-keyed-archivealso refuses the archive (Plist exceeds 128 nesting levels), so both commands now share one limit.Change and scope
closing/selfClosingtoken fields. The preflight still applies the representation-size estimate and the DOCTYPE internal-subset refusal.parseXmlPropertyList, which already bounds nesting before its recursive decode. IB's XML decode path converts thatRangeErrorinto the existingInterfaceBuilderDecodeBudgetExceeded("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 decodeRangeErroras a resource limit (KeyedArchiveReader).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/boundary/filesystem/interfaceBuilderBundle.test.tsadds "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 withaggregate_decode_budget_exhaustedand partial coverage (examined 2, omitted 1). It fails on main, which omits both, and passes with the fix.decode-interface-builder, median of 3 runs, main vs this PR:/System/Applications/TextEdit.app(8 documents, 1,428 nodes, complete)18d1acdefd399d53/Applications/XLD.app(64 documents, 6,528 nodes, partial 64/109)6676c9d4384bb05cOutput is byte-identical. Timing differences are within run-to-run variance; the removed per-element depth bookkeeping is not a measurable speedup.
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-linedescribelimit; I moved the test into its owndescribeblock.Compatibility, safety, and release
plistdecode, as it already did for keyed archives.Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code