Skip to content

perf(apple): read app plists without the plist package - #4989

Merged
thymikee merged 1 commit into
0.22from
perf/0.22-drop-plist-package
Nov 22, 2026
Merged

thymikee merged 1 commit into
0.22from
perf/0.22-drop-plist-package

Conversation

@thymikee

@thymikee thymikee commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #4979.

parseApplePlist lazily imported plist, which bundled @xmldom/xmldom and xmlbuilder into core for one function. core/plist-value.ts now reads a property list with the repo's own @agent-device/xml walker and adds a bplist00 reader: dictionary, array, string, integer, real, boolean, null, date, data, and unique id. Text is read untrimmed, so a padded or CDATA-split string answers exactly what Apple's parsers answer. Every offset, length and object reference is checked against the document, nesting is bounded, one object decodes once, and a dictionary key becomes an own property, so __proto__ cannot repoint a prototype. The reader is published as its own @agent-device/platform-apple/plist subpath, and is synchronous through the plugin-host contract. It refuses what a permissive reader guesses at: XML numeric text that is not exactly a number or exceeds MAX_SAFE_INTEGER, an unparseable <date>, a <plist> with several children, OpenStep text, non-string binary keys, and integer widths over eight bytes.

Before / after

$ npm pack --dry-run --json --ignore-scripts
before  unpackedSize 4219492  size 1312683
after   unpackedSize 4072868  size 1271330

plist, @xmldom/xmldom and xmlbuilder no longer appear in dist/src or THIRD_PARTY_NOTICES.txt.

Validation

Head 114e79e3dd on 0.22. Ran pnpm install --frozen-lockfile, pnpm build, typecheck, lint, format, check:layering, check:fallow, check:production-exports, check:command-docs, focused Apple, Limrun and XML tests, and pnpm check:affected --run --base origin/0.22 --head HEAD. Diffed the reader against plutil and plistlib over generated and real documents plus mutated and truncated bytes: identical values, typed refusals only. Padded-key, padded-string and CDATA-split fixtures pin the text. Not device-facing: no dispatch, capture or lifecycle change, so no device lane.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.10 MB 4.96 MB -146.6 kB
Package (unpacked) 5.10 MB 4.96 MB -146.6 kB
Package (download) 1.55 MB 1.51 MB -41.7 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.0 ms 20.0 ms +0.0 ms
CLI --help 41.8 ms 39.5 ms -2.3 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 3 new findings on 8419377. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 21c9c81. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed 21c9c81: the XML path changes plist string values, so this needs one fix before merge.

plist-value.ts:140 reads <string> and <key> through XmlNode.text, and the XML walker trims every text and CDATA segment and drops whitespace-only ones (parser.ts:170-178). plist 5.0.0 concatenates the raw text and CDATA nodes. So <string>My App </string> now reads My App, <string> </string> reads an empty string, and <string>a <![CDATA[ b ]]> c</string> reads abc instead of a b c. This breaks the goal that parseApplePlist returns identical results for app plists. Any XML Info.plist with padded or segmented strings reaches it, through the plugin-host parsePlist (plugin-device-host.ts:117) and Limrun readInfoPlist. The tests and the 124-file corpus have no whitespace case, so they would not catch it. The rule: plist <string> and <key> text is the exact entity-decoded character data, with no trimming. The XML package owns text handling, so add an XmlParseOptions flag such as trimText: false in packages/xml and pass it from readXmlDocument. Dict and array children are nodes, so their whitespace text can be ignored. Please add a fixture with a padded string and a CDATA-split string.

Not blocking, and each can be taken or left: plist-value.ts:291 counts object visits in valueBudget but decodes shared references again on every visit, so an array of 100,000 refs to one 1 MB string allocates about 100 GB before the budget trips (decode each index once and reuse it, or add a byte budget); plist-value.ts:442 never checks index < objectCount, so a reference past the count decodes trailer bytes (add require(index < this.objectCount, 'object reference') in readObjectByIndex); and plist-value.ts:111 now refuses documents plist 5.0.0 accepted (XML integers beyond 2^53 or with a suffix, <real>nan, invalid dates, a <plist> with several children, OpenStep text, non-string binary dict keys) and keeps <null/> array entries it dropped, so readLimrunAppInfo can turn such a file into a command error (list these refusals in the PR body and the parseApplePlist doc, or move them to a follow-up).

For a follow-up issue, not for this PR: plist-value.ts:37 publishes APPLE_PLIST_PARSE_REASONS as a ReasonTable, so the docs list both reasons under error.details.reason, but ApplePlistParseError is a plain Error that normalizeError wraps as UNKNOWN with no details on the Limrun and log-reader routes, so those reasons never reach the wire. Either drop the table, the .reason field and the two docs rows, or throw AppError(code, message, { reason }) at the parseApplePlist boundary in plist.ts.

Review threads: the nesting-depth thread and the XML integer thread are fixed at this head. The unsigned binary ints thread does not apply, because 1, 2 and 4-byte binary ints are unsigned in Apple's format and in plist 5.0.0, and plist-value.test.ts:129 pins it, so it can be resolved.

The checks are still pending. Body rules fails because the PR body has 264 words outside code blocks and the limit is 250; it reads only the PR body. Smoke Tests and one other check were still running when this was written. There are no conflicts. Not verified here: the reader was not run, plist 5.0.0 behavior was read from its published source, and the npm size comparison and the 124-file corpus diff were not re-run. The next step before merge is the whitespace fix above with its fixture.

@thymikee
thymikee force-pushed the perf/0.22-drop-plist-package branch from 21c9c81 to 114e79e Compare November 22, 2026 21:50
@thymikee

Copy link
Copy Markdown
Member Author

Whitespace fix landed in 114e79e3dd, with the fixtures asked for.

@agent-device/xml now owns the rule through an option: XmlParseOptions.trimText (default true, the existing per-segment trimValues behavior). With trimText: false, appendText keeps a segment exactly as written and entity-decodes it, and drops only an empty one. readXmlDocument passes trimText: false, so plist <string> and <key> text is the entity-decoded character data with no trimming, and <dict>/<array> still see only their element children.

padded-xml.plist holds the cases raised, plus a padded <key>, a whitespace-only string, tabs, an entity, a newline inside a value and an entity-bearing URL; plutil -convert binary1 produced padded-binary.plist from it. Both are read through the same assertions and match plutil -convert json and plistlib.loads value for value:

written read
<key> PaddedKey </key> " PaddedKey " as the key
<string> PaddedValue </string> " PaddedValue "
<string> </string> " ", not ""
<string>x\t</string> tabs kept
<string>foo<![CDATA[ bar ]]>baz</string> "foo bar baz"
<string>\n<![CDATA[ spaced ]]>\n</string> "\n spaced \n"

Three packages/xml tests pin the option itself, so the default stays what the other eight callers expect: webdriver-source.ts, the usbmux protocol, xctestrun products, and the four perf trace readers are unchanged.

Two refusals that follow from untrimmed text, both matching plutil: <integer> 42 </integer> and <real> 1.5 </real> are refused as apple_plist_malformed (plutil reports Unknown character ' ' in <integer> and Encountered misformatted real), while <data> still tolerates whitespace, since Apple wraps base64 across lines.

Also taken from the same review: readObjectByIndex now decodes each object index once and reuses the value, so a document that names one large object from 100,000 slots costs its own bytes rather than 100,000 copies, and an object reference naming an index at or past the trailer's object count is refused before it can read trailer bytes. Both are pinned: a crafted de-duplicated bplist00 (one string, three references) answers { A: ["hi", "hi", "hi"] }, the value plutil -convert json answers, and an out-of-range reference refuses as malformed. The stricter-refusal list is now in the parseApplePlist doc comment and the PR body.

Re-ran the differential check over the fixtures and 25 generated documents in both stored forms against plutil and plistlib: identical values. Truncated and byte-mutated copies of a real document still refuse only with ApplePlistParseError.

The reason-table point is left to its own follow-up, as the review suggested.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 114e79e

Since the review of 21c9c81: 0 new · 0 still open · 0 no longer raised

No open findings.

Not in the reviewers' prompt (5 files)
  • packages/platform-apple/src/core/__tests__/fixtures/info-binary.plist: no text diff (a binary, empty or mode-only change)
  • packages/platform-apple/src/core/__tests__/fixtures/ints-binary.plist: no text diff (a binary, empty or mode-only change)
  • packages/platform-apple/src/core/__tests__/fixtures/kinds-binary.plist: no text diff (a binary, empty or mode-only change)
  • packages/platform-apple/src/core/__tests__/fixtures/padded-binary.plist: no text diff (a binary, empty or mode-only change)
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (a4f2dcad0eae).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 114e79e is ready. The earlier findings from 21c9c81 are fixed at this commit, and nothing blocking remains. Not blocking, and fine to take or leave: the appendText comment at https://github.com/callstack/agent-device/blob/114e79e/packages/xml/src/internal/parser.ts#L173 says spacing between tags is dropped, but with trimText false every non-empty segment is kept, including spacing between child elements on the parent, so the comment and the XmlParseOptions.trimText doc could say that.

The thread on the single sync parseApplePlist is fixed at this head (#4989 (comment)), and the thread on unsigned 1/2/4-byte binary ints does not apply, because that is Apple's format and ints-binary.plist pins it (#4989 (comment)), so both can be resolved.

No conflicts are known. Smoke Tests (macos) and one other check are still running, and Body rules was cancelled; it reads only the PR body, so the diff cannot affect it. The macOS smoke route reaches parseApplePlist through the simulator accessibility-preferences read (binary plist), which this change touches, so a failure there would need a look. Not verified here: the tests were not run locally, the padded fixtures' match against plutil and plistlib and the differential corpus re-run are the author's report, and the plutil -convert binary1 origin of padded-binary.plist is the author's claim. Before merge, the two running checks need to finish green and the PR body needs a fix so Body rules passes.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 22, 2026
@thymikee
thymikee merged commit e2a8047 into 0.22 Nov 22, 2026
22 of 23 checks passed
@thymikee
thymikee deleted the perf/0.22-drop-plist-package branch November 22, 2026 22:02
hannojg pushed a commit to hannojg/agent-device that referenced this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant