Repository navigation
refactor(macho): name load-command codes through the shared LC table - #10714
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. |
[High impact] This PR appears safe to merge; no new actionable issues were found. SummaryThe PR replaces repeated Mach-O command numbers with the shared
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
LC["Shared LC table"] --> Readers["Mach-O readers"]
Platform["Shared platform map"] --> Readers
Readers --> Facts["Parsed command facts"]
Facts --> Projection["Binary projection"]
Parsers["Format readers"] --> Failure["ParseFailureError"]
Failure --> Owner["Owning caller"]
Owner --> Result["Input refusal, fallback, or named limit"]
Reviews (11) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
603d916 to
8805d7f
Compare
8805d7f to
b111ec9
Compare
…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
8e7d93e to
2245574
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.
…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
…ommand-literals # Conflicts: # scripts/verify/architecture-guard-baselines.json
…ommand-literals # Conflicts: # src/ghidra/GhidraClient.ts
|
Merged current main (2ab693a). Two fixes:
Validation on the merged tree: |
# 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.
# Conflicts: # scripts/verify/architecture-guard-baselines.json # src/kuna/KunaDocumentError.ts # src/kuna/KunaProvider.ts
Summary
Mach-O load-command readers now name every command code through the shared
LCtable insrc/domain/apple/machoLoadCommandCodes.tsinstead of hex literals. The table gainsLC_REQ_DYLD. A new counted architecture guard,macho-load-command-literal, fails when a load-command reader compares a command against a literal again. It starts at zero.Part of plan W7 (parser kernel: one format vocabulary table).
This PR also carries collapsed stacked PRs:
ParseFailure.ParseFailureError, and the per-format failure-class guard pattern is broadened.Problem and expected behavior
machoLoadCommandCodes.tssays it is the one table of load-command codes, but six readers still restated codes as literals:src/native/MachoCommandNames.ts: 18 comparisons, plus the dylib andlc_strcommand sets.src/native/metadata/MachoImage.ts: 3.src/native/AppleMachoSelection.ts: 2.src/domain/apple/machoLoadCommands.ts: the fixed-word layout table keys.src/domain/apple/machoDylibCommand.ts: the dependency command map.src/artifacts/apple/MachoLoadCommandReader.ts: theVERSION_MIN_*platform map.src/native/MachoBinaryProjection.ts: two literal code lists, anindexOfplatform lookup, and the string-field map keys.A reader of
frame.command === 0x80000028has to know that this isLC_MAIN, and a typo in one copy goes unnoticed.Expected: every load-command reader uses
LC.<loader.h name>, and the guard keeps new literals out.Change and scope
LCmember. The values are identical, so behavior is unchanged.MachoCommandNames.tsalso accepts the dylib codes withoutLC_REQ_DYLD(0x18,0x1f,0x23). These are now writtenwithoutRequiredByDyld(LC.LOAD_WEAK_DYLIB)and so on, using the newLC_REQ_DYLDexport. The accepted set is unchanged.LC_VERSION_MIN_*-> platform map moves to its domain ownersrc/domain/apple/machoPlatform.ts(MACHO_VERSION_MIN_PLATFORMS).MachoCommandNamesrecords the platform inlegacyBuild.platform, andMachoBinaryProjectionreads that fact instead of re-deriving it from the command code.scripts/verify/architecture-guards.mjsaddsmacho-load-command-literal. It applies to files that useMachoLoadCommandCursor,readMachoLoadCommand*or importmachoLoadCommandCodes, and countscommand,frame.command,command.kindorcmdcompared against a numeric literal or looked up in a literal code list ([..].includes(..)/.indexOf(..)). The baseline is empty, so any new site fails. Run against themainversions, the rule finds 18 matches inMachoCommandNames.tsand 4 inMachoImage.ts.Not included (separate W7 items):
HopperFileOffsetrequiring the admitted range.--integrity-policy record-and-continueon lipo/FAT slice mismatch.AppleMachoFixups.ts. These are opcodes, not load commands.Contract and boundary impact
Semantic owner and earliest changed stage:
src/domain/apple/machoLoadCommandCodes.tsstays the one owner of load-command codes. The six readers consume it.Contribution scope fit and linked maintainer decision: not applicable. This is an internal refactor.
CLI and MCP/tool-catalog contract: none.
Provider, bridge, target-format, or platform compatibility: none. Every value is unchanged.
Evidence, artifact, provenance, or reconstruction contract: none.
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
MachoCommandNames.test.tsandMachoBinaryProjection.test.tsnow expectlegacyBuild.platform. The values are otherwise unchanged, and the existing Mach-O tests and goldens cover every touched reader. The new guard is the regression check for the duplication itself.mainversions ofMachoCommandNames.tsandMachoImage.ts, finds 18 and 4 literal comparisons. It finds 0 on this branch. Restoring this branch's pre-reviewMachoCommandNames.tsandMachoBinaryProjection.tsmakes the guard fail (2 and 1 matches of the list spelling).command,frame.command,command.kind,cmd) in load-command readers. A literal compared through another name, or used as a Map key, would not be caught.Validation performed
npm run test:focused -- src/artifacts/apple/MachoEncryptionReader.test.ts src/artifacts/apple/machoContainer.test.ts src/native/MachoProjectionBudget.test.ts src/native/MachoCommandNames.test.ts src/native/NativeMachoInspection.test.ts src/artifacts/apple/MachoLoadCommandReader.test.ts src/native/AppleMachoSelection.test.ts src/native/MachoBinaryProjection.test.ts src/domain/apple/machoLoadCommands.test.ts tests/boundary/go/goBinaryImage.test.ts tests/boundary/providers/native/nativeLoadText.golden.test.ts tests/boundary/providers/native/nativeLoadKinds.golden.test.ts tests/boundary/providers/native/nativeMachoHeader.golden.test.ts src/native/NativeMachoSourceProvider.test.ts: 14 files, 465 tests passed.node scripts/verify/architecture-guards.mjs: passed.After the review fix:
npm run test:local -- src/native/MachoBinaryProjection.test.ts src/native/MachoCommandNames.test.ts src/native/NativeMachoInspection.test.ts src/artifacts/apple/MachoLoadCommandReader.test.ts: 133 passed;npm run check:fastand the guards passed.npm run check:fast: typecheck and lint passed.npx oxfmt --checkon the changed folders: passed.Follow-up (62c1f68):
src/domain/apple/plistValue.test.tsstill expectedRangeErrorfrom the nesting limit, which refactor(plist): report property-list and keyed-archive failures through ParseFailure #10822 made aPlistNestingLimitError(ParseFailureErrorlimit). It now expectsPlistNestingLimitError.npm run test:localover the 27 sibling tests of the changed sources had failed only this test, and it passes after the fix.Review fix (541793e, Greptile): the selected Mach-O's parse failures now go through
parseFailureAnalysisError. A malformed or truncated selected Mach-O is reported as invalid input onpath(invalid_request,invalid_format) instead ofunreadable_output, and an unsupported one asunsupported_target.npm run test:localover 8 Mach-O source test files passed (176).npm run test:focusedover the native provider boundary tests passed (nativeProvider,nativeMachoUuidlessInspection,nativeSelectedArchitecture,objcClassMetadataFallback,nativeMachoMissingUuidCli,foreignUniversalMachoCli,nativeMachoSummaryMcp,lipoFieldOwnership,nativeInventory.golden,nativeMachoEncryptionBinding,nativeReexport.golden,binaryTarget,nativeExports). After merging current main:npx oxfmt --check .,npm run check:fastandnode scripts/verify/architecture-guards.mjspassed.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.