pe: skip raw writes for virtual-only sections#541
Open
mq1n wants to merge 1 commit into
Open
Conversation
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
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
SizeOfRawData == 0as virtual-only on diskRoot cause
Some PE files, including the local Free Pascal sample used to reproduce this, contain a
.bsssection 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 atPointerToRawData == 0, which could corrupt the DOS/PE headers.Validation
cargo fmt --checkcargo testfreepascal_cli.exerewrite remained byte-identical by SHA256Notes
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.