Skip to content

refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation - #10895

Merged
morluto merged 2 commits into
refactor/macho-load-command-literalsfrom
refactor/plist-invariant-violation
Nov 15, 2026
Merged

morluto merged 2 commits into
refactor/macho-load-command-literalsfrom
refactor/plist-invariant-violation

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

The binary plist preflight, materializer, scalar decoder and NIBArchive decoder threw plain TypeError/RangeError for every failure, so a catch site could not tell a truncated trailer from a broken internal assumption (such as a decode plan its own preflight should have produced). Input faults now throw ParseFailureError (malformed, truncated, unsupported), and broken internal assumptions throw a new shared invariantViolation(message) (InternalInvariantError) from src/domain/internalInvariant.ts. This brings the property-list family to zero in the parser-plain-throw baseline.

Stacked on #10714 (which now carries #10818). Refs the W7 structural-audit plan.

Problem and expected behavior

  • PropertyListDecodeBudget.ts (25), NibArchive.ts (19), BinaryPlistMaterializer.ts (4), PlistScalars.ts (3), plus plistValue.ts (3), interfaceBuilderKeyedArchive.ts (1) and native/parsers/plist.ts (1), threw plain host errors. The parser-plain-throw guard counted them in its baseline.
  • Expected: a failure that the bytes caused carries a ParseFailure kind. A state that earlier validation rules out is reported as a defect, never as a malformed, truncated, unsupported or limited input.

Change and scope

  • New src/domain/internalInvariant.ts: InternalInvariantError (tagged) and invariantViolation(message, options?). The parser-plain-throw guard's message and comment name it as the accepted form for broken internal assumptions. The guard still counts only throw new Error|TypeError|RangeError(, so throw invariantViolation(...) passes.
  • Input faults:
    • PropertyListDecodeBudget: truncated trailer, scalar, UID, date, numeric and reference-table records → truncatedInput("plist"). Invalid trailer sizes, object table, offsets, markers, key types, extended sizes and references → malformedInput. Reference tables or offsets that need a wider representation than the clone supports → unsupportedInput.
    • PlistScalars: clone offset width and clone size beyond the supported representation → unsupportedInput.
    • NibArchive: invalid magic, tables, references, varints and UTF-8 → malformedInput("nib-archive"). A table or field past its end → truncatedInput. A newer format version or unknown value type → unsupportedInput with undecodedContent: true.
    • interfaceBuilderKeyedArchive.requireInterfaceBuilderArchive → malformedInput("interface-builder-archive"). The native binary plist header check → malformedInput("plist").
  • Defects (invariantViolation):
    • A missing source plan or scalar source in decodeBinaryPlistValue.
    • A re-read of the trailer after the preflight has already validated the same bytes (in the materializer, the text decoder and decodeBinaryPlistScalars). readBinaryPlistLayout fails only below 32 bytes, and the preflight first refuses anything below 40.
    • projectPlistValue given proxies, accessors, holes or symbol keys. Its inputs come from REA's own decoders, so this is a caller contract violation, not bad bytes.
  • Messages are unchanged, except for the three post-preflight trailer re-reads, which now say what broke.
  • Not included: consumers still catch broadly. KeyedArchiveReader reports any non-limit failure as format, InterfaceBuilderAnalysis lists it as an invalid archive, and ReleaseExposureReader falls back to raw text. Because of that, an InternalInvariantError is still reported through those generic paths. Each would need a one-line rethrow; that is left as follow-up because none of the invariant sites is reachable from input today.
  • Contribution scope: not applicable (internal error classification within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: the plist preflight (estimateBinaryPlistExpansion/preflightPropertyListDecode) owns the validation of binary plist layout and records. The materializer and scalar decoder rely on it and now treat a re-check failure as a defect. decodeNibArchive owns NIBArchive structure.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: unchanged. Consumers build their messages from cause.message, which keeps the same text.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: unchanged. Failure categories that consumers already derive (limit vs format, omitted vs invalid archive) are the same, because none of the new kinds is limit.

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

    • NibArchive.test.ts: a newer version is unsupported with undecodedContent, an out-of-table reference is a malformed ParseFailureError, and a cut-short archive is truncated.
    • PlistScalars.test.ts: a truncated UID is truncated/plist, and an invalid date marker is malformed.
    • BinaryPlistMaterializer.test.ts: a plan without its binary source throws InternalInvariantError.
    • plistValue.test.ts: proxies, accessors, holes and symbol keys throw InternalInvariantError.
    • KeyedArchiveReader.test.ts: an invalid date marker is a malformed ParseFailureError, no longer a TypeError.
  • Base reproduction: with this PR's tests and the five parent source files restored to HEAD~1, npm run test:local fails 5 tests (the four new and updated classification tests, plus plistValue's invariant test).

  • Remaining proof gaps: the invariant sites are unreachable from input, so only the missing-plan path is exercised directly.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast: typecheck and lint passed.

  • npm run test:local -- src/artifacts/apple/{BinaryPlistMaterializer,PlistScalars,NibArchive,NibViewHierarchy,PropertyListDecodeBudget,InterfaceBuilderDecodeBudget,KeyedArchiveReader}.test.ts src/domain/apple/{plistValue,interfaceBuilderKeyedArchive}.test.ts src/native/parsers/plist.test.ts: 10 files, 265 tests passed.

  • npm run test:focused -- tests/boundary/filesystem/{appleXmlDeclarations,interfaceBuilderBundle,keyedArchiveSelection}.test.ts: 105 passed, 2 skipped.

  • node scripts/verify/architecture-guards.mjs --shrink-baselines: removed the seven property-list entries from parser-plain-throw, and the guards passed.

  • The same tests against the parent sources: 5 failed, as expected.

  • Review follow-up (f5accf4): a cut-short NIBArchive header with intact magic is now truncated, and so is a binary plist extended-length record that crosses the object area; a complete but unsafe length stays malformed. npm run test:local over the eight apple/plist test files passed 207/207. Both new assertions fail on the previous commit.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The thrown classes change from TypeError/RangeError to ParseFailureError/InternalInvariantError, and no public caller matches on them.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

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.

…seFailure and defects through invariantViolation
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T08:10:25.874994Z f5accf4 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 Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; both previous findings are fixed.

Summary

The PR separates plist and NIBArchive input faults from broken internal assumptions.

  • Plist checks label damaged and unsupported input by format.
  • Impossible decoder states now raise a distinct defect error.
  • NIBArchive decoding tells bad, cut-off, and newer formats apart.

Reviews (2) · Last reviewed commit: "fix(plist): report a cut-short NIB heade..." · Reviewed by Greptile

Comment thread src/artifacts/apple/NibArchive.ts Resolved
@morluto
morluto merged commit 64d8962 into refactor/macho-load-command-literals Nov 15, 2026
1 check passed
@morluto
morluto deleted the refactor/plist-invariant-violation branch November 15, 2026 08:16
morluto added a commit that referenced this pull request Nov 15, 2026
…10714)

* refactor(macho): name load-command codes through the shared LC table

* refactor(macho): name version-min and string commands through the shared tables

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure (#10760)

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure

* refactor(xml): type XML parse failures as malformed or unsupported only

* refactor(parsers): catch per-format document and source failure classes (#10794)

* refactor(parsers): report apktool strings and XML plist source failures through ParseFailure

* refactor(apktool): drop the unused ParseFailureError import

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes (#10818)

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes

* refactor(plist): report property-list and keyed-archive failures through ParseFailure (#10822)

* refactor(plist): report property-list and keyed-archive failures through ParseFailure

* refactor(kuna): report Kuna document failures through ParseFailure (#10824)

* refactor(kuna): report Kuna document failures through ParseFailure

* test(kuna): pin the limit and malformed facts of Kuna document failures

* refactor(plist): report plist decode budgets through ParseFailure (#10842)

* refactor(plist): report plist decode budgets through ParseFailure

The plist preflight owner throws a ParseFailure limit (plist-decode-bytes) for its byte budget, the shared PlistNestingLimitError for nesting depth, and a malformed failure for a reference cycle, instead of a per-format PropertyListDecodeBudgetFailure whose meaning each caller re-mapped through a fail callback. The fail option, PropertyListDecodeBudgetFailure and interfaceBuilderDecodeBudgetFailure are removed; the parser-format-failure-class baseline reaches zero.

* refactor(plist): report keyed-archive allowances as typed limit failures (#10844)

keyedArchive.ts and decodeKeyedArchiveBytes throw decodeLimit parse failures (keyed-archive-bytes, -object-table-entries, -values-per-object, -reference-edges) and malformed parse failures instead of plain RangeError/TypeError. KeyedArchiveReader no longer classifies every RangeError as a limit: only a limit parse failure or a host stack/capacity limit is one. The unreachable 128-level scan nesting check is removed; projectPlistValue already refuses the archive first.

* test(plist): expect the nesting limit as its ParseFailure carrier

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation (#10895)

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation

* fix(plist): report a cut-short NIB header or plist length record as truncated

* fix(native): project the selected Mach-O's parse failures through the shared owner

nativeMachoSourcePrimary mapped every non-limit ParseFailureError to
AnalysisOutputError, so a malformed or truncated selected Mach-O was
reported as unreadable tool output and an unsupported one lost its
category. It now uses parseFailureAnalysisError like the ELF, Go and
other byte-format providers: malformed and truncated bytes are an
invalid path, unsupported bytes an unsupported target, and a limit
still falls through to its producer's budget.
morluto added a commit that referenced this pull request Nov 15, 2026
…10874)

* refactor(macho): name load-command codes through the shared LC table

* refactor(macho): name version-min and string commands through the shared tables

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure (#10760)

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure

* refactor(xml): type XML parse failures as malformed or unsupported only

* refactor(parsers): catch per-format document and source failure classes (#10794)

* refactor(parsers): report apktool strings and XML plist source failures through ParseFailure

* refactor(apktool): drop the unused ParseFailureError import

* refactor(native): select ELF sections through the keyed owner

* test(native): pin returned exports and versions for repeated version sections

* refactor(nativeaot): read neither of repeated frozen object regions (#10790)

* refactor(nativeaot): read neither of repeated frozen object regions through the keyed owner

* refactor(parsers): retire every first-match section lookup (#10793)

* fix(nativeaot): report an ambiguous frozen object region as partial (#10812)

* refactor(native): select program headers and load commands through the keyed owner (#10827)

* refactor(native): select the GOT base and dependency segments through the keyed owner (#10847)

* refactor(native): select the GOT base and dependency segments through the keyed owner

resolveGotBase selects the SHT_DYNAMIC section and the allocated .got.plt/.got sections with uniqueKeyed, so a repeat leaves the GOT base unknown instead of taking the first match; elfDependencies reads PT_LOAD segments through the same keyed program table as PT_DYNAMIC. A new keyed-first-match guard recognizes a find/findLast or filter-then-[0] whose predicate compares a key field, whatever the table is called; existing matches are baselined. The unwind fixture can declare PT_DYNAMIC headers and repeated .dynamic/.got.plt sections.

* test(native): pin the PT_DYNAMIC path and destructured keyed lookups

The keyed-first-match guard moves to scripts/verify/keyed-first-match.mjs with focused tests, and now recognizes a destructured key in any position and a destructured filter predicate. The single PT_DYNAMIC unwind test declares .dynamic as SHT_PROGBITS so only the program header supplies DT_PLTGOT, and asserts the resolved ranges.

* fix(macho): refuse repeated chained-fixup and dyld-info tables (#10850)

parseMachoLayout kept the last LC_DYLD_CHAINED_FIXUPS range and merged the rebase/bind streams of every LC_DYLD_INFO(_ONLY) command. A repeat now refuses the slice as malformed. NativeMachoInspection's chained import-name reader already declined repeated LC_DYLD_CHAINED_FIXUPS; that rule is now covered by a test.

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes (#10818)

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes

* refactor(plist): report property-list and keyed-archive failures through ParseFailure (#10822)

* refactor(plist): report property-list and keyed-archive failures through ParseFailure

* refactor(kuna): report Kuna document failures through ParseFailure (#10824)

* refactor(kuna): report Kuna document failures through ParseFailure

* test(kuna): pin the limit and malformed facts of Kuna document failures

* refactor(plist): report plist decode budgets through ParseFailure (#10842)

* refactor(plist): report plist decode budgets through ParseFailure

The plist preflight owner throws a ParseFailure limit (plist-decode-bytes) for its byte budget, the shared PlistNestingLimitError for nesting depth, and a malformed failure for a reference cycle, instead of a per-format PropertyListDecodeBudgetFailure whose meaning each caller re-mapped through a fail callback. The fail option, PropertyListDecodeBudgetFailure and interfaceBuilderDecodeBudgetFailure are removed; the parser-format-failure-class baseline reaches zero.

* refactor(plist): report keyed-archive allowances as typed limit failures (#10844)

keyedArchive.ts and decodeKeyedArchiveBytes throw decodeLimit parse failures (keyed-archive-bytes, -object-table-entries, -values-per-object, -reference-edges) and malformed parse failures instead of plain RangeError/TypeError. KeyedArchiveReader no longer classifies every RangeError as a limit: only a limit parse failure or a host stack/capacity limit is one. The unreachable 128-level scan nesting check is removed; projectPlistValue already refuses the archive first.

* test(plist): expect the nesting limit as its ParseFailure carrier

* fix(verify): count a filter index only on the filter's own result

* refactor(macho): select slices through one owner with typed refusals

* refactor(keyed): select FIT properties and certificate extensions through uniqueKeyed

* refactor(keyed): key each FIT node once, pin repeated FIT properties and subjectKeyIdentifiers, and type the unknown Mach-O header as unsupported

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation (#10895)

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation

* fix(plist): report a cut-short NIB header or plist length record as truncated

* fix(native): project the selected Mach-O's parse failures through the shared owner

nativeMachoSourcePrimary mapped every non-limit ParseFailureError to
AnalysisOutputError, so a malformed or truncated selected Mach-O was
reported as unreadable tool output and an unsupported one lost its
category. It now uses parseFailureAnalysisError like the ELF, Go and
other byte-format providers: malformed and truncated bytes are an
invalid path, unsupported bytes an unsupported target, and a limit
still falls through to its producer's budget.
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant