Repository navigation
refactor(macho): select slices through one owner with typed refusals - #10874
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
…gh 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
…es (#10794) * refactor(parsers): report apktool strings and XML plist source failures through ParseFailure * refactor(apktool): drop the unused ParseFailureError import
… 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.
d1a105e to
b173b5e
Compare
[Medium impact] The PR appears safe to merge; no blocking issue was found. SummaryThis PR gives Mach-O byte selection one owner and returns typed refusals separately from malformed-file failures.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
Request["Mach-O bytes and request mode"] --> Owner["selectMachoSlice"]
Owner --> Shared["Shared FAT reader"]
Shared --> Selected["Selected bytes, file offset, and identity"]
Shared --> Malformed["Malformed container"]
Owner --> Refusal["Typed selection refusal"]
Selected --> Layout["parseMachoLayout"]
Layout --> Consumers["Dispatch metadata, initializers, and IL2CPP"]
Refusal --> Boundary["Consumer chooses its error meaning"]
Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
b21fbba to
7c5b78b
Compare
…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.
…and subjectKeyIdentifiers, and type the unknown Mach-O header as unsupported
f802354 to
7116818
Compare
…seFailure 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
|
Both issues in the Greptile summary (reviewed at f802354) are fixed in 7116818:
Details are in the resolved review threads. Greptile has not re-reviewed the new head yet. |
|
@greptileai review 7116818 addresses both findings from the last summary (reviewed at f802354); see the reply above. |
…ommand-literals # Conflicts: # scripts/verify/architecture-guard-baselines.json
…ommand-literals # Conflicts: # src/ghidra/GhidraClient.ts
# Conflicts: # scripts/verify/architecture-guard-baselines.json
… 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.
…ho-slice-selection-owner
# Conflicts: # scripts/verify/architecture-guard-baselines.json # src/kuna/KunaDocumentError.ts # src/kuna/KunaProvider.ts
# Conflicts: # src/native/AppleDispatchMetadata.ts # src/native/AppleMachoSelection.test.ts # src/native/AppleMachoSelection.ts # tests/boundary/providers/native/objcClassMetadataFallback.test.ts
Summary
Mach-O slice selection now has one owner,
selectMachoSliceinsrc/native/metadata/MachoSliceSelection.ts, with an explicit request mode and aResultwhose error is a tagged refusal (architecture_not_present,ambiguous_architecture,admitted_slice_mismatch) ormalformed. A caller/admission mismatch is no longer thrown as a plainTypeErrorthat looks like a format failure. Refs plan W7; stacked on #10780 (which now carries #10847 and #10850). Also carries #10875 (collapsed): FIT property and APK certificateextensions [3]lookups throughuniqueKeyed; thekeyed-first-matchbaseline is now empty. See #10875 for its design (DT spec / dtc duplicate-property rule; RFC 5280 §4.1/§4.2) and evidence (new APK test fails on the base: 1 failed | 23 passed).Design
{ mode: "admitted", architecture, slice }reads the image target admission bound to the session: a universal image only at the admitted range, which must be declared for the architecture's CPU family; a thin image only when its header is of that family.{ mode: "architecture", architecture, input? }resolves a caller's selector by CPU family and subtype (the formerselectNativeImage).readUniversalMachoImage/readUniversalMachoSlice, which already reject overlapping ranges and FAT-shaped JVM classes and check the slice header against its declaration. The admitted path previously had a second FAT reader (readFatHeaderPrefix+readFatSliceDeclarations) with different rules.malformedcarries the container's message; the three refusal kinds say the request and the file disagree about which slice is meant. Each consumer decides what a refusal means at its boundary.NativeMachoInspectionpicks amongliporecords, not FAT bytes. That choice moves intoselectLipoArchitecture(MachoArchitectureSelection.ts). It takes the same two modes and returns the same refusal type. The admitted range keeps the admitted mode, and a target architecture keeps the policy ranking, or a unique lipo name when REA has no policy for it. A selector that tools would resolve to more than one record is refused.Problem and expected behavior
AppleMachoSelection.selectMachoSlicethrewTypeErrorfor "architecture absent", "needs the admitted slice", "admitted slice not declared" and "does not match the requested architecture".parseMachoLayoutthrewTypeErrorfor a thin image of another CPU family and for a FAT declaration that disagrees with its header. Il2cpp caught everyTypeErrorfrom the layout asmalformed-container, so a refused selection was reported as a damaged file.selectNativeImagealready returned aResult, but with a singlearchitecturekind that did not say whether the slice was missing or ambiguous.NativeMachoInspection.selectArchitecturefound a policy-less architecture byavailable.find(({ name }) => name === …)(akeyed-first-matchbaseline entry).MachoArchitectureSelectionmatched the guard twice for name lookups in its static policy table.Expected: one owner states which slice a request addresses, or why it addresses none, as a typed value.
Change and scope
src/native/metadata/MachoSliceSelection.ts:selectMachoSlice(bytes, request),MachoSliceRequest,MachoSliceSelectionRefusal,MachoSliceSelectionFailure,AdmittedMachoSlice(moved here).selectNativeImageis removed;requireSelectedNativeImagecalls the owner inarchitecturemode and maps every refusal to thearchitectureinput, as before.src/native/AppleMachoSelection.ts: the oldselectMachoSlice,MachoSlice,AdmittedMachoSliceand the twoTypeErrorCPU checks are removed.parseMachoLayout(bytes, selected)parses the image the owner selected. The 32-bit refusal no longer names the requested architecture, which the layout no longer receives.AppleDispatchMetadatathrowsProviderAdapterErrorwithdiagnostics.refusalset to the kind. Admission bound this architecture and range to these exact bytes, so a refusal is an inconsistency inside REA. The projection is unchanged: the oldTypeErroralready becameProviderAdapterError.MachoInitializersnotes the refusal, as it notes any undecoded fixup.unsupported-containerandmalformedtomalformed-container. Itscatch (TypeError)is removed.MachoArchitectureSelection.ts:selectLipoArchitectureandarchitectureBaseName(moved fromNativeMachoInspection). Policy subtypes are looked up through aMapbuilt from the static table, so the guard no longer matches it; it is configuration, not parsed data.selectMachoArchitectureandmachoToolArchitectureNameare now module-private.keyed-first-matchdropsMachoArchitectureSelection.ts(2) andNativeMachoInspection.ts(1);parser-plain-throwAppleMachoSelection.ts3 → 1.Only little-endian 64-bit Mach-O metadata is supported) is nowunsupportedInput("macho"), a plainParseFailureErrorand not aBinaryFormatFailureorUnsupportedMachoMetadataFormatError. Dispatch therefore still projects it toProviderAdapterError, as the boundary testdoes not treat an unknown header as a supported-format capability limitpins. Il2cpp now reports it asunsupported-containerinstead of rethrowing a rawTypeError. Theparser-plain-throwentry forAppleMachoSelection.tsis removed, and the unit pin inAppleMachoSelection.test.tsnow expects anunsupportedParseFailureError.WeakMapof keyed views) instead of re-keying per read.Contribution scope: not applicable (refactor inside existing boundaries).
Contract and boundary impact
selectMachoSlice(bytes) andselectLipoArchitecture(lipo records). Consumers:AppleDispatchMetadata,MachoInitializers,Il2cppBinaryImage,NativeMachoInspection, and the Go/Rust/initializer providers throughrequireSelectedNativeImage.requireSelectedNativeImageissue paths and messages are unchanged;universalSliceMcpboundary tests pass unchanged.inspect_macholipo refusal messages are unchanged. Admitted dispatch metadata now applies the generic FAT admission rules:admitted_slice_mismatch.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
MachoArchitectureSelection.test.ts(new): a policy-less name listed twice isambiguous_architecture; an absent caller architecture (architecture_not_present) is distinct from an undeclared admitted range (admitted_slice_mismatch); an admitted range listed twice is refused.AppleMachoSelection.test.ts,AppleDispatchMetadata.test.ts: assert refusal kinds and theProviderAdapterErrordiagnostics instead ofTypeErrortext.MachoSliceSelection.test.ts: asserts the split kinds.layoutForfixture selects, then parses, as the readers do.TypeError(see the removedthrow new TypeErrorsites and Il2cpp'scatch (TypeError)). The new tests use the new API, so they do not run on the base.inspect_machoand slice-selecting providers (boundary tests above).inspect_native_dispatch_metadata; synthetic fixtures only.For evidence-bearing changes:
Validation performed
npm run check:fast— passed (typecheck + lint), last run after rebasing onto the rebased refactor(native): select ELF sections through the keyed owner #10780.npm run test:focused -- tests/boundary/filesystem/keyedFirstMatchGuard.test.ts src/native/AppleMachoSelection.test.ts src/native/MachoArchitectureSelection.test.ts src/native/NativeMachoInspection.test.ts src/native/AppleDispatchMetadata.test.ts src/native/metadata/MachoSliceSelection.test.ts src/domain/apkSignature/apkV1SignatureBlock.test.ts src/artifacts/fit/FitStructure.test.ts tests/boundary/mcp/universalSliceMcp.test.ts— 323 passed (after rebase).node scripts/verify/architecture-guards.mjs --shrink-baselines— passed; baselines lowered as listed.npm run test:local -- src/native/AppleMachoSelection.test.ts src/native/metadata/MachoSliceSelection.test.ts src/native/NativeMachoInspection.test.ts src/native/AppleDispatchMetadata.test.ts src/native/NativeMachoSelectedSlice.test.ts src/native/NativeMachoCommandDiagnostics.test.ts src/native/NativeMachoVtoolRefusal.test.ts src/native/NativeMachoOperand.test.ts— 260 passed.npm run test:local -- src/native/MachoArchitectureSelection.test.ts— 3 passed.npm run test:focused -- tests/boundary/providers/native/objcClassMetadataFallback.test.ts tests/boundary/mcp/universalSliceMcp.test.ts tests/boundary/mcp/nativeInitializersMcp.test.ts tests/boundary/il2cpp/il2cppMappingOwnership.test.ts tests/boundary/il2cpp/il2cppBinaryFile.test.ts src/native/metadata/Il2cppContainer.test.ts(plus the foursrc/nativefiles above) — 471 passed.npm run test:focused -- tests/boundary/providers/native/lipoFieldOwnership.test.ts tests/boundary/providers/native/nativeSelectedArchitecture.test.ts tests/boundary/providers/native/nativeProvider.test.ts tests/boundary/providers/native/objcClassMetadataFallback.test.ts tests/boundary/mcp/universalSliceMcp.test.ts— 92 passed.Review follow-up (7116818):
npm run test:local -- src/native/AppleDispatchMetadata.test.ts src/native/AppleMachoSelection.test.ts src/artifacts/fit/FitStructure.test.ts src/domain/apkSignature/apkV1SignatureBlock.test.ts src/firmware/devicetree/DevicetreeParser.test.ts: all passed.npm run test:focused -- tests/boundary/providers/native/objcClassMetadataFallback.test.ts tests/boundary/providers/native/nativeMachoUuidlessInspection.test.ts: 25 passed. The unknown header still projects toProviderAdapterError.subjectKeyIdentifiertest fails with the guard removed fromapkV1SignatureBlock.ts(1 failed | 24 passed).formatrefusal; it is reached beforepropertyOf.npm run check:fast: typecheck passed. Lint errors in the two test files (max-lines-per-function) were fixed by moving the new tests to the top level;npx oxlinton them now reports 0 errors.After refactor(macho): name load-command codes through the shared LC table #10714 merged (fa06533, merging main; conflicts in
AppleDispatchMetadata.ts,AppleMachoSelection.ts,AppleMachoSelection.test.ts,objcClassMetadataFallback.test.tsand the guard baseline resolved, then--shrink-baselines):npm run test:localover 22 Mach-O source test files, 603 passed.npm run test:focused -- tests/boundary/providers/native/objcClassMetadataFallback.test.ts tests/boundary/il2cpp/il2cppBinaryFile.test.ts tests/boundary/providers/native/nativeSelectedArchitecture.test.ts tests/boundary/providers/native/nativeProvider.test.ts tests/boundary/providers/native/lipoFieldOwnership.test.ts, 271 passed.npx oxfmt --check .,npm run check:fast,node scripts/verify/architecture-guards.mjsandbriefs/local-gate.shpassed.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.