[PR #4155] [CLOSED] fix(pe): retain empty resources at the section's virtual end #6095

Closed
opened 2026-10-31 01:11:48 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4155
Author: @berelels
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/pe-empty-resource-section-end


📝 Commits (1)

  • 6e1a712 fix(pe): retain empty resources at the section's virtual end

📊 Changes

2 files changed (+69 additions, -1 deletions)

View changed files

📝 src/native/pe/PeResourceLayout.ts (+12 -1)
📝 src/native/pe/PeResourceParser.test.ts (+57 -0)

📄 Description

Summary

Fixes #3970. inspect_pe_resources rejected the whole inventory when a resource leaf had a zero-byte payload whose RVA is exactly the end of its section's virtual extent (the GNU windres/ld layout in the issue). The Windows resource loader resolves that resource and reports size 0. It is now retained with an empty payload range.

Problem and expected behavior

PeResourceLayout.map selects sections with rva - section.rva < virtualExtent(section). For size === 0 at the end boundary no section matched, so parsing failed with Resource RVA has missing or overlapping section mappings.. An empty interval reads no bytes, so the end boundary is a valid location for it.

Change and scope

  • When size === 0 and no section contains the RVA, accept the section whose virtual extent ends exactly there. Sections with a zero extent are excluded.
  • A section that starts at that RVA still owns it: the containing-section rule runs first, so adjacent sections do not become ambiguous.
  • Nonempty payloads past the virtual extent and empty payloads past the end stay rejected. No reads from raw alignment padding are restored (#1678 is unchanged).

Contribution scope: an ordinary fix within existing boundaries, so no maintainer scope decision is needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/native/pe/PeResourceLayout.ts RVA mapping (built-in PE resource parser).

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix).

  • CLI and MCP/tool-catalog contract: unchanged schemas. A previously rejected input now returns complete with a payload.location.bytes: 0 row.

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

  • Evidence, artifact, provenance, or reconstruction contract: none beyond retaining the resource identity.

  • 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/native/pe/PeResourceParser.test.ts, with three cases. (1) An empty payload at VirtualAddress + VirtualSize is retained with identity, offset, length 0 and the empty SHA-256. (2) An empty payload one byte past the end is still rejected. (3) An empty payload at a boundary where a later section starts maps into the later section.
  • Base reproduction: case (1) fails on main (cd64e24ff) with the issue's message; cases (2) and (3) pass on both.
  • User-visible CLI output: a hand-built PE32+ DLL with the issue's layout (.rsrc RVA 0x4000, VirtualSize 0x58, data entry RVA 0x4058, Size 0, type 42 / name 1 / language 1033):
    • rea-agents@6.5.0: invalid_request / Resource RVA has missing or overlapping section mappings.
    • This branch: {"coverage":{"status":"complete","examined_entries":3,"resources":1},"payloads":[{"rva":16472,"location":{"offset":1112,"bytes":0},"sha256":"e3b0c442…b855"}]}
    • The one-byte control (VirtualSize 0x59) returns complete on this branch.
  • Remaining proof gaps: no DLL produced by real windres/ld (no MinGW toolchain on the test host) and no Windows run. Windows API behavior is taken from the issue report.

For evidence-bearing changes:

  • 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/native/pe/PeResourceParser.test.ts: 24 passed before, 1 failed with the new tests on base, 27 passed with the fix.
  • npm run test:focused -- src/native/pe/PeResourceParser.test.ts src/application/binaryDiagnostics/PeResourcesService.test.ts tests/boundary/filesystem/peResources.test.ts tests/acceptance/applications/peResources.test.ts …: 9 files, 205 tests passed (combined run with the #3981 branch's files).
  • npm run check:fast (pre-push): typecheck and lint, 2/2 tasks successful.
  • node scripts/rea.mjs inspect-pe-resources <empty.dll|one.dll> --format json: output above (Linux x64, Node 24.18.0).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (built-in parser). Linux only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: zero-length mapping performs no read. requirePeRange(bytes, offset, 0) still bounds the offset.

Author readiness

Human owner: @berelels

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

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4155 **Author:** [@berelels](https://github.com/berelels) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/pe-empty-resource-section-end` --- ### 📝 Commits (1) - [`6e1a712`](https://github.com/morluto/rea/commit/6e1a712d29c384340ec6ed9c0d28bd05622e116e) fix(pe): retain empty resources at the section's virtual end ### 📊 Changes **2 files changed** (+69 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/native/pe/PeResourceLayout.ts` (+12 -1) 📝 `src/native/pe/PeResourceParser.test.ts` (+57 -0) </details> ### 📄 Description ## Summary Fixes #3970. `inspect_pe_resources` rejected the whole inventory when a resource leaf had a zero-byte payload whose RVA is exactly the end of its section's virtual extent (the GNU windres/ld layout in the issue). The Windows resource loader resolves that resource and reports size 0. It is now retained with an empty payload range. ## Problem and expected behavior `PeResourceLayout.map` selects sections with `rva - section.rva < virtualExtent(section)`. For `size === 0` at the end boundary no section matched, so parsing failed with `Resource RVA has missing or overlapping section mappings.`. An empty interval reads no bytes, so the end boundary is a valid location for it. ## Change and scope - When `size === 0` and no section contains the RVA, accept the section whose virtual extent ends exactly there. Sections with a zero extent are excluded. - A section that *starts* at that RVA still owns it: the containing-section rule runs first, so adjacent sections do not become ambiguous. - Nonempty payloads past the virtual extent and empty payloads past the end stay rejected. No reads from raw alignment padding are restored (#1678 is unchanged). Contribution scope: an ordinary fix within existing boundaries, so no maintainer scope decision is needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/native/pe/PeResourceLayout.ts` RVA mapping (built-in PE resource parser). - Contribution scope fit and linked maintainer decision: not applicable (bug fix). - CLI and MCP/tool-catalog contract: unchanged schemas. A previously rejected input now returns `complete` with a `payload.location.bytes: 0` row. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none beyond retaining the resource identity. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] 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/native/pe/PeResourceParser.test.ts`, with three cases. (1) An empty payload at `VirtualAddress + VirtualSize` is retained with identity, offset, length 0 and the empty SHA-256. (2) An empty payload one byte past the end is still rejected. (3) An empty payload at a boundary where a later section starts maps into the later section. - Base reproduction: case (1) fails on `main` (cd64e24ff) with the issue's message; cases (2) and (3) pass on both. - User-visible CLI output: a hand-built PE32+ DLL with the issue's layout (`.rsrc` RVA 0x4000, VirtualSize 0x58, data entry RVA 0x4058, Size 0, type 42 / name 1 / language 1033): - `rea-agents@6.5.0`: `invalid_request` / `Resource RVA has missing or overlapping section mappings.` - This branch: `{"coverage":{"status":"complete","examined_entries":3,"resources":1},"payloads":[{"rva":16472,"location":{"offset":1112,"bytes":0},"sha256":"e3b0c442…b855"}]}` - The one-byte control (VirtualSize 0x59) returns `complete` on this branch. - Remaining proof gaps: no DLL produced by real windres/ld (no MinGW toolchain on the test host) and no Windows run. Windows API behavior is taken from the issue report. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/native/pe/PeResourceParser.test.ts`: 24 passed before, 1 failed with the new tests on base, 27 passed with the fix. - `npm run test:focused -- src/native/pe/PeResourceParser.test.ts src/application/binaryDiagnostics/PeResourcesService.test.ts tests/boundary/filesystem/peResources.test.ts tests/acceptance/applications/peResources.test.ts …`: 9 files, 205 tests passed (combined run with the #3981 branch's files). - `npm run check:fast` (pre-push): typecheck and lint, 2/2 tasks successful. - `node scripts/rea.mjs inspect-pe-resources <empty.dll|one.dll> --format json`: output above (Linux x64, Node 24.18.0). ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable (built-in parser). Linux only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: zero-length mapping performs no read. `requirePeRange(bytes, offset, 0)` still bounds the offset. ## Author readiness Human owner: @berelels - [ ] 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:11:48 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6095
No description provided.