Skip to content

fix(plist): decode hexadecimal XML integers as Apple's parser does - #3475

Closed
apitoagents wants to merge 2 commits into
morluto:mainfrom
apitoagents:fix/xml-plist-hexadecimal-integers
Closed

apitoagents wants to merge 2 commits into
morluto:mainfrom
apitoagents:fix/xml-plist-hexadecimal-integers

Conversation

@apitoagents

@apitoagents apitoagents commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3373.

inspect-keyed-archive / inspect_keyed_archive reported the valid XML plist integer <integer>0x2A</integer> as 0. Apple's property-list parser (and plutil -p) reads the same bytes as 42, and both the decimal spelling and a binary conversion of the same archive already returned 42. Every XML plist consumer that goes through parseXmlPropertyList (keyed archives, Info.plist resolution, Interface Builder documents, native plist inspection) now decodes hexadecimal integers to the value Apple's parser reports.

Problem and expected behavior

The pinned plist decoder reads <integer> text with parseInt(text, 10), so a 0x-prefixed literal decodes to 0. The supplemental XML number collector also only recognised decimal digits, so a hexadecimal literal was recorded as "incomplete metadata" instead of being classified. Expected: the same value as the decimal spelling (42), with the exact-integer association still available for literals beyond 2^53.

Change and scope

  • src/domain/apple/plistNumbers.ts: one owner for <integer> literal text, parsePlistIntegerLiteral, which reads an optional sign followed by decimal digits or a 0x/0X hexadecimal literal into an exact bigint and reports the radix.
  • src/domain/propertyListKeys.ts: the existing __proto__ key substitution is generalised into substituteDecoderDivergences. It locates first children the pinned decoder reads (rejected keys and hexadecimal integers) with the decoder's own XML parser, orders them by source position, and prefixes each with a CDATA section holding the text the decoder must read. The original source text is untouched, so character references and line endings keep their meaning exactly as before.
  • src/artifacts/apple/PlistNumberLiterals.ts: the number collector uses the shared literal parser, so hexadecimal literals participate in exact-integer association instead of marking metadata incomplete.
  • docs/native-investigation.md: one sentence in "Keyed archive integer precision".

Intentionally not included: whitespace handling is unchanged (the decoder already tolerates surrounding whitespace for decimal text; Apple rejects it). Mixed content such as <integer>0x2A<string>1</string></integer> keeps the decoder's first-child semantics (reads 0x2A), matching how <key> first children are already treated; the collector still marks it incomplete.

Scope decision: not applicable (ordinary fix within existing read-only boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: parseXmlPropertyList (domain), XML plist decode.
  • Contribution scope fit and linked maintainer decision: routine fix; not applicable.
  • CLI and MCP/tool-catalog contract: unchanged. Only the decoded value of hexadecimal <integer> elements changes (from 0 to the Apple-parsed value).
  • Provider, bridge, target-format, or platform compatibility: XML plist only; binary plists and OpenStep unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: archive digests and object identities unchanged; large hexadecimal literals now reach the existing { "$plist_type": "integer", "decimal": "<exact digits>" } representation.
  • 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:

    • src/domain/propertyListKeys.test.ts: hexadecimal spellings (0x2A, 0X2a, +0x2A, -0x2A, entity-encoded, CDATA, trailing comment, surrounding whitespace, 2^53+1, 0xFFFFFFFFFFFFFFFF) interleaved with __proto__ keys before and after, to cover substitution ordering; hexadecimal text outside integers and non-literal integers (0x, 0x1G) stay as decoded; first-child semantics for mixed content.
    • tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts: new hexadecimal-integer (0x2A → 42, no precision/incomplete-metadata limitation) and unsafe-hexadecimal-integer (0x20000000000001 → exact 9007199254740993) cases, through both inspectBundleKeyedArchive and the built CLI.
  • Base reproduction (executed): the issue's sample.plist against the compiled runtime from main (cbc0e97c2) returned normalized_result.objects[1].value: 0. After this change the same command returns value: 42, /usr/bin/plutil -p reports 42, and the decimal control (sed 's/0x2A/42/') returns 42. Both runs exit 0.

  • User-visible CLI/MCP output: {"id":1,"kind":"scalar","class_id":null,"class_name":null,"status":"observed","value":42}.

  • Remaining proof gaps: plutil comparison ran on macOS only. Occurrence of hexadecimal integers in real application archives was not measured (the issue reports the same).

  • 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/domain/propertyListKeys.test.ts — 49 passed
  • npm run test:focused -- tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts tests/boundary/filesystem/keyedArchiveIntegerAmbiguity.test.ts tests/boundary/providers/native/keyedArchiveEncoding.test.ts tests/boundary/cli/nativePlistCli.test.ts tests/boundary/cli/nativePlistPrototypeKeyCli.test.ts — 5 files, 33 passed
  • npm run test:local -- src/artifacts/apple/KeyedArchiveReader.test.ts src/native/parsers/plist.test.ts src/domain/propertyListXmlText.test.ts — 32 passed
  • npm run check:fast — typecheck and lint successful
  • npm run verify:module-boundaries — 1878 source files checked, no violations
  • node scripts/check-doc-facts.mjs — no output (pass)
  • node scripts/rea.mjs inspect-keyed-archive sample.plist --json — value: 42 after the change (0 on the base revision)

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Hexadecimal integers previously decoded to 0; they now decode to their value.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; plutil cross-check on macOS 13 (Darwin 22.3.0).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only parsing; no new inputs, processes, or network access.

Author readiness

Human owner: @apitoagents

  • 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.

@apitoagents
apitoagents marked this pull request as ready for review October 14, 2026 12:45
@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 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

XML plist hexadecimal integers now decode to their numeric value, and large values can use the existing exact-decimal representation.

  • XML plist readers decode hexadecimal integers to their intended values.
  • Keyed archives keep exact values for large hexadecimal integers.

Reviews (4) · Last reviewed commit: "refactor(plist): convert only hexadecima..." · Reviewed by Greptile

Comment thread src/domain/propertyListKeys.ts Resolved
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: Fifteen new tests fail on main and all pass with this PR. A hexadecimal XML integer such as 0x2A now reads as 42, not 0. The PR needs a rebase, because a strict git apply fails on current main.

Thanks, apitoagents, for the fix. I ran two test files on main 62bf098 (#4169). They are src/domain/propertyListKeys.test.ts and tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts.

Step Node 24.18.0
PR's test changes only, on main 15 failed, 44 passed
Plus the PR's source changes 59 passed

The 15 failures are all new hexadecimal cases. They include 0x2A, 0X2a, +0x2A, -0x2A, a CDATA form, and two large values that need exact integers. Both the filesystem and the built CLI cases fail on main.

Needs a rebase

On main 62bf098, git apply --check rejects src/domain/propertyListKeys.ts. Main changed that file after this PR branched, in an earlier merge (#4105). The older tool patch accepts the same diff with fuzz 2. A three-way merge of that one file has no conflicts. I tested the merged result, not the PR head as pushed. The merged result compiled and passed. The proto key tests from #4105 still pass in it.

Not run

  • Real GitHub CI did not run on this PR. Only the Greptile review is listed, so this is the first real test run I know of.
  • Apple's own parser. The PR says it matches it. I did not check that.
  • The PR head as pushed. I ran the merged tree.
  • Only Node 24.18.0. Not Node 22 or 26.
  • The full test suite.
Commands
# main 62bf09809 extracted to a work tree, then npm ci, npm run build, npm run test:prepare
git apply --check 3475.diff                      # exit 1 on propertyListKeys.ts
# merged tree: 3-way merge of propertyListKeys.ts, other five files taken from the PR
patch -p1 -d <tree> < merged.tests.diff
npm run test:focused -- src/domain/propertyListKeys.test.ts tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts   # exit 1
patch -p1 -d <tree> < merged.src.diff
npm run test:focused -- src/domain/propertyListKeys.test.ts tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts   # exit 0
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0
  • Head / base: 62120d2 (merged by hand) / 62bf098
  • Other: the box was shared with three other test agents.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@apitoagents

Copy link
Copy Markdown
Contributor Author

Thanks for running it. Rebased onto current main (08a897b2c, after #4105). The three-way merge was clean; git apply --check rejected the file only because #4105 moved the OpenStep scan above the XML substitution, which this PR does not touch.

Validation on the rebased head as pushed, Node 24.15.0 (macOS):

  • npm run test:local -- src/domain/propertyListKeys.test.ts src/artifacts/apple/KeyedArchiveReader.test.ts src/native/parsers/plist.test.ts src/domain/propertyListXmlText.test.ts — 83 passed, including the OpenStep __proto__ cases from fix(apple): report __proto__ entries omitted from OpenStep property lists #4105
  • npm run test:focused -- tests/boundary/filesystem/keyedArchiveScalarIdentity.test.ts tests/boundary/filesystem/keyedArchiveIntegerAmbiguity.test.ts tests/boundary/providers/native/keyedArchiveEncoding.test.ts tests/boundary/cli/nativePlistCli.test.ts tests/boundary/cli/nativePlistPrototypeKeyCli.test.ts — 36 passed
  • npm run check:fast, npm run verify:module-boundaries (1946 files), node scripts/check-doc-facts.mjs — clean
  • inspect-keyed-archive on the issue's sample with the rebuilt runtime — value: 42

Apple's parser: /usr/bin/plutil -p on the same file reports 42; plutil also accepts 0X2a, +0x2A, -0x2A and 0xFFFFFFFFFFFFFFFF, which the new tests cover. Real CI still needs a maintainer to approve the workflow run.

@apitoagents
apitoagents force-pushed the fix/xml-plist-hexadecimal-integers branch from 62120d2 to 561bcff Compare October 15, 2026 19:07
morluto added a commit that referenced this pull request Oct 17, 2026
Interpret the validated, depth-bounded DOM directly. Collect source number
facts during the same traversal and share them with keyed archives, Interface
Builder and native plist projections. Remove the second XML parse, key aliases,
source-location rewriting and both duplicate XML numeric scanners. Preserve
character references, container/null behavior, safe own-property construction
and prototype omission accounting.

Decode signed hexadecimal integers and combine real text/CDATA. Retain exact
integer identity when a finite integer exceeds even Number's finite range,
using the shared scalar projector. Keep unsupported mixed integer syntax
conservative and report incomplete metadata.

Adapt @apitoagents's hexadecimal regression and literal-parsing proposal from
PR #3475. Native plutil controls establish the supported hex/real cases and
confirm that the synthetic 401-digit overflow case exceeds native bounds;
retaining accepted input does not claim native-format support.

Validation: 274 focused checks in 30 files pass, one skipped; build,
check:fast and docs:check pass. Built CLI/actual stdio MCP, native plist and
Interface Builder controls cover kinds, references, exact digits and digests.
Eight baseline checks fail; native binary conversion independently verifies
updated CDATA real expectations. 48 tiny completed CLI cost comparisons
preserve ordinary XML/binary and all three native replies byte for byte.
Two read-only reviews clear. No statistical speed claim, heavy profiler,
investigated-target execution or real deep-provider verification.

Fixes #3373
Fixes #4042
Fixes #4789
@apitoagents

Copy link
Copy Markdown
Contributor Author

Superseded by 7aa4b98 (fix(plist): own XML values and numeric facts in one decoder), which decodes signed hexadecimal <integer> text and adapted the regression cases from this PR. Verified on main 742b6f5: the issue's sample.plist now returns value: 42 through inspect-keyed-archive. Closing this one. Thanks @morluto for integrating it and @CassieFox23 for the test runs.

@apitoagents
apitoagents deleted the fix/xml-plist-hexadecimal-integers branch October 17, 2026 16:44
@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Keyed archive inspection returns hexadecimal XML integers as zero

3 participants