[PR #3997] [CLOSED] fix(native): admit zero-length PE resource payloads at the section end #5981

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

📋 Pull Request Information

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

Base: main ← Head: fix/pe-zero-length-resource-boundary


📝 Commits (2)

  • e80aa39 fix(native): admit zero-length PE resource payloads at the section end
  • 0f44c9a test(pe): assert enclosing section priority at shared boundary for empty payload

📊 Changes

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

View changed files

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

📄 Description

Summary

Fixes #3970.

Admit PE resource entries whose payload length is zero and whose RVA lies exactly at the section's virtual extent boundary, matching Windows loader and resource API (LoadLibraryExW / FindResourceExW / SizeofResource) behavior for zero-length resources generated at the end of .rsrc.

Problem and expected behavior

Resource-only PE images (such as DLLs generated by GNU windres/ld with an empty binary resource) can place an empty payload (Size = 0) at the exact end of .rsrc (OffsetToData = section.VirtualAddress + section.VirtualSize).

Previously, PeResourceLayout.map selected candidate sections using strictly rva >= section.rva && rva - section.rva < virtualExtent(section). Because the zero-length payload lies at rva - section.rva == virtualExtent, zero candidate sections were matched and the parser aborted with invalid_format (Resource RVA has missing or overlapping section mappings.), rejecting the entire inventory.

Expected behavior: zero-length payloads at the exact section virtual boundary are mapped to the containing section when no section strictly encloses the RVA. Nonempty payloads reaching or exceeding the section virtual extent remain rejected.

Change and scope

  • In src/native/pe/PeResourceLayout.ts: When selecting candidate sections for RVA mapping, if size === 0 and no section strictly encloses rva, allow sections where rva - section.rva === virtualExtent(section).
  • Non-zero payloads continue to use the strict < virtualExtent boundary check.
  • Added comprehensive unit tests in src/native/pe/PeResourceParser.test.ts asserting that zero-length payloads at the exact section virtual boundary succeed with empty payload hash and offset, while payloads past the boundary by even 1 byte continue to fail with Resource RVA has missing or overlapping section mappings..

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/native/pe/PeResourceLayout.ts, RVA section mapping during resource layout parsing.
  • Contribution scope fit and linked maintainer decision: routine static analysis bug fix; maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: inspect-pe-resources CLI and inspect_pe_resources MCP tool. No schema, argument, or catalog changes.
  • Provider, bridge, target-format, or platform compatibility: built-in PE parser; no external provider dependency.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • 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 added admits a zero-length resource payload at the section virtual boundary.
  • Base reproduction or other evidence: On baseline without the fix, the reproduction test failed with ArtifactReaderFailure: Resource RVA has missing or overlapping section mappings. at PeResourceLayout.ts:115. With the fix, all 25 tests in PeResourceParser.test.ts pass.
  • User-visible CLI/MCP output: inspect-pe-resources on PE images with empty resource at section end reports the resource inventory instead of aborting with exit code 1.
  • Remaining proof gaps: Synthetic byte fixture; no live GCC/windres compiler invocation during unit test execution.

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

  • npx vitest run src/native/pe/PeResourceParser.test.ts — 25 passed in 51ms.
  • npm run check:fast — turbo typecheck and lint completed with 0 errors.
  • npm run format:check — oxfmt checked 3581 files with 0 format errors.
  • npm run docs:check — all 6 Turbo tasks successful, 5 readme consistency tests passed.
  • git diff --check — clean, no whitespace or formatting issues.

Compatibility, safety, and release

  • Breaking changes or migration steps: None. Previously rejected valid Windows PE images now parse successfully.
  • Real Hopper/Ghidra, browser, or OS coverage: Built-in TypeScript PE parser; verified on Windows x64 Node 24.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Static read-only byte parsing; no subprocess execution or network access.

Author readiness

Human owner: @ErenYeager1836

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

🔄 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/3997 **Author:** [@ErenYeager1836](https://github.com/ErenYeager1836) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/pe-zero-length-resource-boundary` --- ### 📝 Commits (2) - [`e80aa39`](https://github.com/morluto/rea/commit/e80aa39b716633fd8e7f26d059783dea97b1beb3) fix(native): admit zero-length PE resource payloads at the section end - [`0f44c9a`](https://github.com/morluto/rea/commit/0f44c9afbdf2a0092fc59ac0b3b139f570cb388b) test(pe): assert enclosing section priority at shared boundary for empty payload ### 📊 Changes **2 files changed** (+57 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/native/pe/PeResourceLayout.ts` (+9 -1) 📝 `src/native/pe/PeResourceParser.test.ts` (+48 -0) </details> ### 📄 Description ## Summary Fixes #3970. Admit PE resource entries whose payload length is zero and whose RVA lies exactly at the section's virtual extent boundary, matching Windows loader and resource API (`LoadLibraryExW` / `FindResourceExW` / `SizeofResource`) behavior for zero-length resources generated at the end of `.rsrc`. ## Problem and expected behavior Resource-only PE images (such as DLLs generated by GNU windres/ld with an empty binary resource) can place an empty payload (`Size = 0`) at the exact end of `.rsrc` (`OffsetToData = section.VirtualAddress + section.VirtualSize`). Previously, `PeResourceLayout.map` selected candidate sections using strictly `rva >= section.rva && rva - section.rva < virtualExtent(section)`. Because the zero-length payload lies at `rva - section.rva == virtualExtent`, zero candidate sections were matched and the parser aborted with `invalid_format` (`Resource RVA has missing or overlapping section mappings.`), rejecting the entire inventory. Expected behavior: zero-length payloads at the exact section virtual boundary are mapped to the containing section when no section strictly encloses the RVA. Nonempty payloads reaching or exceeding the section virtual extent remain rejected. ## Change and scope - In `src/native/pe/PeResourceLayout.ts`: When selecting candidate sections for RVA mapping, if `size === 0` and no section strictly encloses `rva`, allow sections where `rva - section.rva === virtualExtent(section)`. - Non-zero payloads continue to use the strict `< virtualExtent` boundary check. - Added comprehensive unit tests in `src/native/pe/PeResourceParser.test.ts` asserting that zero-length payloads at the exact section virtual boundary succeed with empty payload hash and offset, while payloads past the boundary by even 1 byte continue to fail with `Resource RVA has missing or overlapping section mappings.`. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/native/pe/PeResourceLayout.ts`, RVA section mapping during resource layout parsing. - Contribution scope fit and linked maintainer decision: routine static analysis bug fix; maintainer scope decision not applicable. - CLI and MCP/tool-catalog contract: `inspect-pe-resources` CLI and `inspect_pe_resources` MCP tool. No schema, argument, or catalog changes. - Provider, bridge, target-format, or platform compatibility: built-in PE parser; no external provider dependency. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. Expected effects: - [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` added `admits a zero-length resource payload at the section virtual boundary`. - Base reproduction or other evidence: On baseline without the fix, the reproduction test failed with `ArtifactReaderFailure: Resource RVA has missing or overlapping section mappings.` at `PeResourceLayout.ts:115`. With the fix, all 25 tests in `PeResourceParser.test.ts` pass. - User-visible CLI/MCP output: `inspect-pe-resources` on PE images with empty resource at section end reports the resource inventory instead of aborting with exit code 1. - Remaining proof gaps: Synthetic byte fixture; no live GCC/windres compiler invocation during unit test execution. 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 - `npx vitest run src/native/pe/PeResourceParser.test.ts` — 25 passed in 51ms. - `npm run check:fast` — turbo typecheck and lint completed with 0 errors. - `npm run format:check` — oxfmt checked 3581 files with 0 format errors. - `npm run docs:check` — all 6 Turbo tasks successful, 5 readme consistency tests passed. - `git diff --check` — clean, no whitespace or formatting issues. ## Compatibility, safety, and release - Breaking changes or migration steps: None. Previously rejected valid Windows PE images now parse successfully. - Real Hopper/Ghidra, browser, or OS coverage: Built-in TypeScript PE parser; verified on Windows x64 Node 24. - Package or release metadata impact: None. - Security, privacy, process, or containment review: Static read-only byte parsing; no subprocess execution or network access. ## Author readiness Human owner: @ErenYeager1836 - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:56 +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#5981
No description provided.