Skip to content

refactor(pe): move the PE resource parser into domain with domain parse failures - #11550

Merged
morluto merged 1 commit into
mainfrom
refactor/pe-resource-parser-domain
Nov 15, 2026
Merged

morluto merged 1 commit into
mainfrom
refactor/pe-resource-parser-domain

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Moves the PE resource tree parser from the artifacts provider into src/domain/pe/, as decided on #11527:

  • src/artifacts/pe/PeResourceTreeFacts.ts -> src/domain/pe/peResourceTreeFacts.ts (unchanged);
  • src/artifacts/pe/PeResourceLayout.ts -> src/domain/pe/peResourceLayout.ts (header admission, RVA mapping, bounded named-resource walk over an injected reader);
  • src/artifacts/pe/PeResourceParser.ts (and test) -> src/domain/pe/peResourceInventory.ts (parsePeResources);
  • src/artifacts/pe/PeResources.fixture.ts -> src/domain/pe/peResources.fixture.ts.

Native (PeResourcesProvider, PeCertificateParser) and artifacts (NodeSeaLocation, DenoStandaloneLocation) now import the domain parser, so native -> artifacts (2) leaves the crossProvider baseline.

Fixes #11527. Refs #11359. Part of plan W9.

Problem and expected behavior

The PE resource parser lived in the artifacts provider, and native imported it from there (#11331 had only reversed the edge). Expected: I/O-free format parsing lives in domain (as the Mach-O and plist readers moved to src/domain/apple/), the parser reports failures in the domain's parse failure algebra, and each provider maps them to its own failure at its boundary.

Change and scope

  • Domain failures. The parser no longer throws ArtifactReaderFailure, which belongs to src/resources:
    • malformed structure throws malformedInput("pe", message) (ParseFailureError, kind malformed); the message text is unchanged;
    • budgets throw decodeLimit("pe", message, { name, maximum }) with max_entries (the caller's entry budget) or pe_resource_metadata_bytes (the fixed 8 MiB allowance). peResourceLimitBoundary(limit) names the bound each one constrains (capacity or memory);
    • cancellation uses signal.throwIfAborted(), so the caller's signal.reason propagates;
    • BinaryFormatFailure("unsupported") for DOS and non-PE MZ images is unchanged.
  • One mapping owner. artifactParseFailure(cause, signal, limitBoundary?) in src/resources/ArtifactFileOperation.ts maps a domain parse failure onto the reader's reasons: the caller's own signal.reason -> cancelled, malformed/truncated -> format, limit -> limit with the named boundary. Unsupported forms and any other cause pass through. The original failure is kept as cause.
  • Wrappers stay with their providers: PeResourcesProvider (after its stable file read), PeCertificateParser (header admission), NodeSeaLocation and DenoStandaloneLocation (their carrier reads) each map at the call site. NodeSeaLocation keeps its "not an admitted PE, so not a SEA carrier" decision by catching the domain malformed failure from readPeResourceLayout.
  • Specifier updates in tests, the raw-buffer-read guard baseline (rekeyed by the shrink), and one path in docs/specs/artifacts/deno-standalone/plan.md.

Not included: dosMz, peCoffHeader, peSectionHeader and peOptionalHeader stay at the domain root; grouping domain subsystems is W10's work.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the parser's owner moves from artifacts to domain; its failure type at the parser boundary changes from ArtifactReaderFailure to ParseFailureError. The providers' public results and errors are unchanged: they map the domain failure back to the same reader reasons before their existing projections run.
  • Contribution scope fit and linked maintainer decision: [Design] Owner for the PE resource tree parser that native imports from artifacts #11527 (decision comment: pure parts to src/domain/pe/, wrappers stay with their provider).
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): cancellation still reaches the caller as an ArtifactReaderFailure("cancelled") carrying the caller's reason, so artifactReadCancelledBy and cleanup ownership are unchanged.
  • Generated metadata (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.

  • 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: the moved parser test now asserts the domain failures (kind: "malformed" in place of reason: "format", a limit failure naming max_entries whose boundary is capacity, and cancellation rejecting with the caller's reason). Provider tests are unchanged and cover the mapping end to end: entry budget -> capacity, metadata allowance -> memory, truncated table -> malformed refusal (PeResourcesProvider.test.ts), cancellation during admitted parsing (tests/process-global/peResourcesLifetime.test.ts), and Node SEA / Deno PE carriers.

  • Base reproduction or other evidence: node scripts/verify-module-boundaries.mjs --shrink-layer-baseline reported native -> artifacts: 0, baseline 2 (the artifacts <-> native cycle record already went with refactor(providers): move the native command runner into the shared provider core #11462).

  • User-visible CLI/MCP output (if applicable): none.

  • Remaining proof gaps: I did not run the acceptance tests (tests/acceptance/applications/peResources.test.ts, which needs a build) or tests/boundary/cli/callerPathSymlinkParentCli.test.ts; both only change a fixture import specifier.

  • 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 check:fast: passed, including the architecture guards.
  • node scripts/verify-module-boundaries.mjs --shrink-layer-baseline and node scripts/verify/architecture-guards.mjs --shrink-baselines: passed.
  • npm run test:focused -- with src/domain/pe/peResourceInventory.test.ts, src/native/pe/PeResourcesProvider.test.ts, tests/conformance/formats/mzPeAdmission.test.ts: 3 files, 68 tests passed.
  • npm run test:focused -- with tests/process-global/peResourcesLifetime.test.ts, src/artifacts/NodeSeaArtifactReader.test.ts, src/artifacts/deno/DenoStandaloneArtifactReader.test.ts: 3 files, 149 tests passed.
  • npm run test:focused -- with src/native/pe/PeCertificateParser.test.ts, src/native/pe/PeCertificatesProvider.test.ts, src/native/pe/PeUnsupportedTargets.test.ts, src/application/binaryDiagnostics/PeResourcesService.test.ts, tests/boundary/filesystem/peResources.test.ts: 5 files, 109 tests passed.
  • npm run test:focused -- with tests/conformance/providerCompletion.test.ts, tests/boundary/providers/nativeArtifactFinalization.test.ts: 2 files, 42 tests passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. These are internal modules; public results are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable.

Not a pure move (failure types change), so the squash commit should not go in .git-blame-ignore-revs.

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.

@chatgpt-codex-connector

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-15T22:18:37.080567Z
We couldn’t complete this review. Comment @codex review to try again.
75c8eae PR opened
ℹ️ 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.

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

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[Medium impact] The change reaches several PE parsing and embedded-carrier workflows.

Fix the Deno PE failure mapping before merging so physical read failures stay separate from cancellation.

Fix All in CodexFindings

  1. P1 Read failures become cancellation ▶
Fix with agent prompt
### Issue 1
src/artifacts/deno/DenoStandaloneLocation.ts:866-867
If `readExact` rejects with a file-read error that is also used to abort `carrier.signal`, this new catch relabels the read failure as `cancelled`. Another caller sharing `ArtifactPreparation` may then retry it instead of receiving the actual failure. This violates the repository directive that a caller's abort reason cannot establish failure origin.

Carrier reads already wrap genuine cancellation. Leave their physical failures untouched and reserve raw-reason cancellation mapping for the full-buffer parser.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Moves the PE resource parser into src/domain/pe/ and adds shared conversion from domain parse failures to reader failures.

  • PE resource parsing now lives in the domain and serves native and artifact readers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Native["PeResourcesProvider"] --> Inventory["domain/pe/peResourceInventory"]
  SEA["NodeSeaLocation"] --> Inventory
  Certificates["PeCertificateParser"] --> Layout["domain/pe/peResourceLayout"]
  Deno["DenoStandaloneLocation"] --> Layout
  Inventory --> Layout
  Inventory --> Mapping["resources/artifactParseFailure"]
  Layout --> Mapping
  Mapping --> Reader["ArtifactReaderFailure"]
  Reader --> Projection["Existing provider projections"]
Loading

Reviews (2) · Last reviewed commit: "refactor(pe): move the PE resource parse..." · Reviewed by Greptile

…se failures

The I/O-free PE resource tree parser moves from src/artifacts/pe to src/domain/pe and reports malformed structure, decode budgets and cancellation through the domain parse failure algebra. artifactParseFailure in src/resources maps those onto artifact reader reasons at each provider's boundary, so native no longer imports artifacts.

Fixes #11527
@morluto
morluto force-pushed the refactor/pe-resource-parser-domain branch from 75c8eae to 3db4cba Compare November 15, 2026 22:32
@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@morluto
morluto merged commit 807dd17 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the refactor/pe-resource-parser-domain branch November 15, 2026 22:43
Comment on lines +866 to +867
} catch (cause) {
throw artifactParseFailure(cause, carrier.signal);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Read failures become cancellation

If readExact rejects with a file-read error that is also used to abort carrier.signal, this new catch relabels the read failure as cancelled. Another caller sharing ArtifactPreparation may then retry it instead of receiving the actual failure. This violates the repository directive that a caller's abort reason cannot establish failure origin.

Carrier reads already wrap genuine cancellation. Leave their physical failures untouched and reserve raw-reason cancellation mapping for the full-buffer parser.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/artifacts/deno/DenoStandaloneLocation.ts
Line: 866-867

Comment:
**Read failures become cancellation**

If `readExact` rejects with a file-read error that is also used to abort `carrier.signal`, this new catch relabels the read failure as `cancelled`. Another caller sharing `ArtifactPreparation` may then retry it instead of receiving the actual failure. This violates the repository directive that a caller's abort reason cannot establish failure origin.

Carrier reads already wrap genuine cancellation. Leave their physical failures untouched and reserve raw-reason cancellation mapping for the full-buffer parser.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

Plastic-time added a commit to Plastic-time/rea that referenced this pull request Nov 16, 2026
- Move PeRichHeaderPort to src/ports/binaryDiagnostics (morluto#11208). The
  provider now implements it, like the other PE providers.
- Import the artifact toolkit from src/resources, BinaryContainer from
  src/domain/binaryContainer and readPeHeaders from src/domain/pe.
- List PeRichHeaderProvider among native's entry files.
- Map failures with projectPeBinaryFailure, as PeImportsProvider and
  PeLoadConfigProvider do. The new guards forbid a hand-built
  resource-constraint refusal and an inline error message; the shared
  PE projection already owns both, so the provider adds neither. The
  structural allowance's recovery now carries its ceiling (morluto#11651).
- Tests: the Evidence subject names its target identity (morluto#11416), and
  readPeHeaders now throws a malformed ParseFailureError (morluto#11550).
- Re-record the advertised schema summary: the output hash now matches
  inspect_pe_imports after Evidence format revision 2.
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 22, 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.

[Design] Owner for the PE resource tree parser that native imports from artifacts

1 participant