Skip to content

fix(apple): observe keyed-archive dates when the offset table reaches the trailer - #7166

Merged
morluto merged 10 commits into
morluto:mainfrom
devreddy1015:fix/keyed-archive-date-table-bounds
Nov 26, 2026
Merged

morluto merged 10 commits into
morluto:mainfrom
devreddy1015:fix/keyed-archive-date-table-bounds

Conversation

@devreddy1015

@devreddy1015 devreddy1015 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

inspect_keyed_archive reported a sub-millisecond NSDate as an exact timestamp when the binary plist's offset table runs into the trailer, a layout the keyed-archive preflight admits and plist@5 decodes. Expected output is the documented unknown date: iso8601: null plus the unknown-date limitation.

Change

  • scanBinaryPlistScalars bounds offset-table reads by end of file instead of the trailer, matching decoder bounds. Strict callers are unchanged.
  • Reconciled with fix(apple): preserve post-table plist objects #7820: its append-only rewrite already fixes the truncated-trailer crash Greptile found, so my earlier size helper is dropped.
  • Codex follow-up: the rewrite now copies the whole source buffer, including the old trailer, before appending clones, the new table and a new trailer. Before, an object stored in the trailer's spare bytes after an overlapping table was overwritten, and plist@5 threw Unsupported int size: 256. The offset width and both budget estimates now count the extra trailer.
  • Second Codex follow-up: a date is now observed only when it ends before both the offset table and the trailer. Before, a date that started just before the trailer could carry the trailer's width bytes in its payload, so rewriting it in place made decoding fail with Unsupported int size: 0. That layout now keeps the generic incomplete-metadata disclosure.

Evidence

  • Three regressions in KeyedArchiveReader.test.ts cover the table running into the trailer: a sub-millisecond date, an overlapping date (Greptile's case), and an object in the trailer's spare bytes (Codex's case). All three fail on current main and pass here.
  • src/artifacts/apple/ and src/native/parsers/: 367 tests pass. keyedArchivePostTable.test.ts from fix(apple): preserve post-table plist objects #7820 passes. Typecheck, lint and format pass.
  • Not run: the full CI suite. Tested on Linux x64 with Node 26.12.1. The build's metadata check needs the pinned Node 24, so I compiled with npm run compile.

Scope: a static parsing fix within existing boundaries, with no CLI/MCP contract, package or metadata change.

Author readiness

Human owner: @devreddy1015

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

… the trailer

inspect_keyed_archive preflights binary plists with decoder bounds, which
admit an offset table that ends anywhere before end of file, including
inside the 32-byte trailer. plist@5 reads such a table. Dates must still
end before the offset table, so the preflight records each reachable date.

The scalar scanner, however, required the table to end before the
trailer. For a table that runs into the trailer it abandoned the whole
file and collected no dates. The precision clamp in
decodeBinaryPlistScalars then saw no unrepresentable date, so a 0.1005 s
instant was reported as the exact timestamp 2001-01-01T00:00:00.100Z with
no unknown-date limitation.

Bound the scanner's offset-table reads by the end of the file, which is
the widest table any preflight admits. Strict preflight already rejects
tables past the trailer before scanning, so strict callers are unchanged.
Object and date bounds still end at the offset table.
@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

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

Summary

The PR preserves date uncertainty when a binary plist’s offset table reaches the trailer.

  • Sub-millisecond archive dates stay unknown when offset tables reach trailers.
  • Scalar rewrites preserve objects in the old trailer.

No new actionable issues were found. The merged #7820 fix is already in the base; this PR adds distinct fixes beyond it. GitHub discussion checks were blocked by missing authentication. Tests were not run during this review.

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread src/domain/apple/plistScalars.ts Resolved
@devreddy1015
devreddy1015 marked this pull request as ready for review October 25, 2026 19:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T15:29:40.296476Z
We couldn’t complete this review. Comment @codex review to try again.
c49a733 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.

Review follow-up. With the scanner observing dates when the offset table
runs into the trailer, a sub-millisecond date that overlaps another object
now reaches cloneBinaryPlistObjects. That rewrite sized its output as
bytes.length plus the growth of a table assumed to end before the trailer.
When the old table overlaps the trailer, those bytes exist only once, so
the buffer came out short and the copied trailer was truncated. plist@5
then failed with "Unsupported int size: 0".

binaryPlistCloneGrowth now computes the bytes a clone rewrite adds,
subtracting only the old table bytes that precede the trailer. The
allocator and both preflight budget estimates use it, so admission and
allocation agree. For tables that end before the trailer the value is
unchanged.

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/apple/plistScalars.ts Resolved
…e-table-bounds

# Conflicts:
#	src/artifacts/apple/PlistScalars.ts
#	src/artifacts/apple/PropertyListDecodeBudget.ts
Review follow-up (Codex). Decoder bounds admit an offset table that runs
into the trailer and an object stored in the trailer's spare bytes after
it. With dates now observed for that layout, an overlapping
sub-millisecond date reaches cloneBinaryPlistObjects. Since morluto#7820 the
rewrite appends clones and a fresh table, but only after the bytes before
the trailer, so it overwrote such an object and plist@5 failed with
"Unsupported int size: 256".

Copy the whole source buffer and append the clones, the new table and a
new trailer after it. The old table and trailer stay as inert bytes, so
every source offset still names its original record. The offset width and
both preflight estimates now account for the clones starting at the end
of the buffer and for the extra trailer.
@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.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @devreddy1015, thanks for this! The fix looks good. What's left: there is 1 unresolved review thread from Codex, about "Preserve post-table objects when date scanning triggers cloning". Happy to get this in once that's sorted out.

@CassieFox23

CassieFox23 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: On head fa44319, all 38 tests in KeyedArchiveReader.test.ts passed on three Node versions. With two source files swapped back to 131fbe0, 3 tests failed on each version. I did not test a real keyed archive whose offset table runs into the trailer.

Edit (11 Nov): I ran the new head, 992ece7, in a VM, and the results are here.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head fa44319 pass: 1 file, 38 tests pass: 1 file, 38 tests pass: 1 file, 38 tests
Red run (fix files from 131fbe0) fail: 3 failed, 35 passed fail: 3 failed, 35 passed fail: 3 failed, 35 passed

For the red run, I put src/artifacts/apple/PlistScalars.ts and src/artifacts/apple/PropertyListDecodeBudget.ts back to 131fbe0, the merge base (where the branch left main). The test file stayed at the head version.

In the Node 24.22.1 red log, these 3 tests fail:

  • keeps an object stored in the trailer's spare bytes when isolating an overlapping date
  • keeps a sub-millisecond instant unknown when the offset table runs into the trailer
  • rebuilds a complete trailer when isolating an overlapping date whose table runs into the trailer

So these 3 tests fail without the fix and pass with it.

CI on fa44319:

  • CI and PR title: waiting for a maintainer to approve them (action_required).
  • PR readiness: one successful run and one cancelled run. Its commit status is success.
  • Validate author declaration: one successful and one cancelled check run.
  • Greptile Review: passed.

The head is 502 commits behind main b81da90. GitHub says the PR is mergeable, and its merge state is blocked.

Not run

  • A real keyed archive whose offset table runs into the trailer.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: fa44319 / 131fbe0 (merge base with main)
  • Red run: fa44319 with PlistScalars.ts and PropertyListDecodeBudget.ts from 131fbe0
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/artifacts/apple/KeyedArchiveReader.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/apple/plistScalars.ts Resolved
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's changed test file on head 992ece7 under three Node versions. All 40 tests passed each time. The CI workflow is completed/action_required, with no test jobs in its check runs.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
src/artifacts/apple/KeyedArchiveReader.test.ts pass: 1 of 1 files, 40 of 40 tests pass: 1 of 1 files, 40 of 40 tests pass: 1 of 1 files, 40 of 40 tests

The PR changes 3 files against the merge base cb4e5cf. Those are the test file, src/artifacts/apple/PlistScalars.ts and src/artifacts/apple/PropertyListDecodeBudget.ts. My run covered only the test file.

CI on 992ece7, read live with gh. GitHub shows mergeable true and state blocked. The PR is not a draft.

  • CI: completed/action_required. The CI check runs list none of Source tests, Portable tests or Test shard.
  • CodeQL production: completed/action_required.
  • PR title: two runs, both completed/action_required.
  • PR readiness: one run completed/cancelled and one completed/success. The commit status PR readiness is success.
  • Validate author declaration: one check run cancelled and one success.

The head is 405 commits behind main dcdae13.

Not run

  • A real keyed archive with offset table running into the trailer
  • A merge with current main, dcdae13.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 992ece7 / cb4e5cf (merge base with main)
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/artifacts/apple/KeyedArchiveReader.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

…e-table-bounds

# Conflicts:
#	src/artifacts/apple/KeyedArchiveReader.test.ts
@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.

@morluto morluto added the bug Something isn't working label Nov 23, 2026
…e-table-bounds

plist 5.1.1 rejects an offset table that runs into the trailer, so the tests no longer call parseBinary on those fixtures; rea decodes a rebuilt copy with a fresh trailer. Match main's "not a keyed archive" error.
@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.

@devreddy1015

Copy link
Copy Markdown
Contributor Author

@morluto I merged the latest main (no conflicts) and Greptile's re-review is 5/5. Could you approve the workflows when you have a moment? Thanks!

@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto enabled auto-merge (squash) November 26, 2026 15:31
@morluto
morluto merged commit 853d8ef into morluto:main Nov 26, 2026
40 checks passed
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.

3 participants