Skip to content

pe: skip raw writes for virtual-only sections#541

Open
mq1n wants to merge 1 commit into
m4b:masterfrom
mq1n:codex/pe-virtual-only-sections
Open

pe: skip raw writes for virtual-only sections#541
mq1n wants to merge 1 commit into
m4b:masterfrom
mq1n:codex/pe-virtual-only-sections

Conversation

@mq1n

@mq1n mq1n commented Jun 17, 2026

Copy link
Copy Markdown

Summary

  • treat PE sections with SizeOfRawData == 0 as virtual-only on disk
  • preserve virtual-only section table entries while skipping nonexistent raw bytes during PE rewrite
  • add synthetic regression coverage for the writer path without requiring an executable fixture

Root cause

Some PE files, including the local Free Pascal sample used to reproduce this, contain a .bss section with a nonzero virtual size but no raw on-disk data. The writer previously expanded that virtual-only section into zero bytes and wrote them at PointerToRawData == 0, which could corrupt the DOS/PE headers.

Validation

  • cargo fmt --check
  • cargo test
  • focused virtual-only section regression tests
  • touched-file strict Clippy filter
  • local freepascal_cli.exe rewrite remained byte-identical by SHA256

Notes

This is a narrow PE writer fix and does not special-case Free Pascal binaries. The regression test uses synthetic section data instead of adding a binary executable fixture.

PE sections such as .bss can reserve virtual memory without carrying raw on-disk data. The writer previously expanded those virtual bytes and could write zeroes at file offset 0, corrupting the DOS/PE headers during rewrite.

Treat zero-raw-size sections as virtual-only, preserve their section table entries, and skip writing nonexistent section bytes. The regression coverage uses synthetic section data so the test does not require a bundled executable fixture.

Constraint: Virtual-only PE sections may legally have SizeOfRawData == 0 and PointerToRawData == 0
@mq1n mq1n marked this pull request as ready for review June 17, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant