Repository navigation
refactor(parsers): select once-only sections and JSON fields through one keyed owner - #10740
Merged
Merged
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. |
Contributor
[Medium impact] The reviewed changes appear safe to merge. SummaryThis PR gives Go and Rust one shared way to select sections that may appear only once.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Parsed native sections] --> B[keyedBy retains named declarations]
B --> C[uniqueKeyed selects requested key]
C --> D[Absent: existing fallback or no metadata]
C --> E[One: check section and read metadata]
C --> F[Repeated: malformed failure]
E --> G[Rust dependency JSON]
G --> H[Check depth and parse JSON]
H --> I[findDuplicateJsonMember]
I --> J[Repeated: malformed failure]
I --> K[Distinct: check schema and graph limits]
Reviews (2) · Last reviewed commit: "refactor(parsers): select once-only sect..." · Reviewed by Greptile |
22 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Duplicate handling in REA's parsers is decided by whichever lookup a parser author happened to use:
findkeeps the first declaration,Map.setandJSON.parsekeep the last, and hand-writtenfilter(...).length > 1checks reject. This PR adds one owner for keyed lookups,src/domain/keyedCollection.ts, and moves the first slice onto it: the JSON reader and the section lookups that must not lose a declaration. It also records the target design so later slices follow the same shape.Refs the W7 duplicate-key workstream (structural audit report 06, finding 5).
Keyed<T> design (target model)
Keyed<T> = { entries: { key, ordinal, value }[], duplicates: key[] }, built once bykeyedBy(values, keyOf). Members without a key (unnamed sections) are not keyed.find/Map.setdefaults:uniqueKeyed(keyed, key): the format allows the key once. ReturnsResult<T | undefined, { kind: "duplicate", key, ordinals }>. Absent isundefined; repeated is a typed failure carrying every ordinal.all(later slice): every declaration, for tables where repeats are legal (__objc_classlistin several segments, ELFnamed()helpers).first/last(later slice): only where the format's own consumer defines precedence (JSON client configs: last), and they take a declared reason.findDuplicateJsonMember(src/domain/jsonDuplicateMember.ts), plists through fix(plist): record dictionary keys declared more than once #10737.apiContractreportsduplicate_json_members), or failsmalformedwhere the format allows one.findsites are migrated): a lint rule banningsections.find(on parsed native tables, with a counted baseline.Selectors are added when a migrated consumer needs them; this slice only needs
uniqueKeyed.Problem and expected behavior
Trigger: a Go Mach-O whose
__go_buildinfosection is declared twice, the second in an unmapped segment.Before: the build-info search read the first declaration, then the second, and failed with "Mach-O build-info section is in an unmapped segment"; whether ambiguity or a per-section defect was reported depended on declaration order (ELF checked ambiguity inside the loop, Mach-O after it).
After: both formats select the build-info section once, through
uniqueKeyed, and a repeat fails with "... ambiguous build-info sections" before either declaration is read. The Rustcargo auditabledependency section uses the same owner, and its dependency JSON drops a privatejsonc-parservisitor that reimplemented duplicate-member detection in favour offindDuplicateJsonMember.Change and scope
src/domain/keyedCollection.ts(new):Keyed<T>,keyedBy,uniqueKeyed,DuplicateKey.src/go/GoBuildInfoSearch.ts: ELF.go.buildinfoand Mach-O__go_buildinfoselection throughuniqueKeyed; the two ad hoc ambiguity checks are removed. Per-section validation is unchanged.src/rust/RustBinaryImage.ts: dependency section (__DATA,.dep-v0/.dep-v0) throughuniqueKeyed, replacingfilter(...).length > 1.src/rust/RustAuditableReader.ts: the dependency JSON is parsed withJSON.parseand checked withfindDuplicateJsonMember; thejsonc-parservisitor copy is deleted. Same failure kinds and details.Not included (later slices): the other JSON detectors (
losslessJson.ts,CaptureJson.ts,SafetensorsHeader.ts,GgufHeader.tsparse their own trees and already reject inline); first-match native sectionfindsites (ELF/PE:NativeExportParser,ElfHardening,ElfUnwindTables,nativeAotPe,ManagedPeReader);allhelpers (ElfUnwindTables.named,KernelModuleParser.sectionsNamed); the lint guard.Contribution scope: ordinary refactor within existing boundaries; not applicable.
Contract and boundary impact
Semantic owner and earliest changed stage:
keyedCollection.tsowns once-only selection;jsonDuplicateMember.tsowns JSON repeated-member detection. Consumers: Go build-info search, Rust dependency section and JSON. Superseded: Go's two inline ambiguity checks, Rust'sfiltercount check and itsjsonc-parserduplicate visitor.Contribution scope fit and linked maintainer decision: W7 part 6 ("short Keyed<T> design in the PR body, first slice").
CLI and MCP/tool-catalog contract: none.
Provider, bridge, target-format, or platform compatibility: a Go binary with a repeated build-info section whose later copy is defective now reports ambiguity instead of the defect; both are
malformed.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.
Launch or attach to a process.
Inject instrumentation or run scripts/code.
Change process memory, registers, files, or configuration.
Contact network services.
Recover protected code or work around protections.
Documentation or usability only; no target interaction.
Not sure yet; investigation or maintainer guidance needed.
Evidence and regression coverage
Tests added or updated:
src/domain/keyedCollection.test.ts: source order and ordinals, unkeyed members skipped, single/absent selection, typed refusal with every ordinal.tests/boundary/go/goBinaryImage.test.ts: the unmapped-segment fixture now builds both cases; "rejects a repeated Mach-O build-info section before reading either" fails on the base revision (it reported "unmapped"), and the unmapped case keeps its coverage with a single declaration.src/rust/RustAuditableReader.test.tsduplicate-field cases (packages,name,dependencies) andtests/boundary/rust/rustBinaryImage.test.tspass unchanged.Base reproduction: shown above for Go.
Remaining proof gaps: no real Go/Rust binary with repeated sections was available; fixtures only.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:local -- src/domain/keyedCollection.test.ts src/rust/RustAuditableReader.test.ts— passed.npm run test:focused -- tests/boundary/go/goBinaryImage.test.ts— 113 passed; withGoBuildInfoSearch.tsreverted, the new repeated-section test fails.npm run test:focused -- tests/boundary/rust/rustBinaryImage.test.ts— passed.npm run typecheck— passed.npx oxlinton changed files — no errors.npx oxfmt --check src tests— clean.node scripts/verify/architecture-guards.mjsandnpm run verify:module-boundaries— passed.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.