Skip to content

Preserve BaseOfData when rewriting PE32 images - #4

Open
zanieb wants to merge 1 commit into
Systemcluster:mainfrom
zanieb:zb/fix-pe32-base-of-data
Open

Preserve BaseOfData when rewriting PE32 images#4
zanieb wants to merge 1 commit into
Systemcluster:mainfrom
zanieb:zb/fix-pe32-base-of-data

Conversation

@zanieb

@zanieb zanieb commented Aug 5, 2026

Copy link
Copy Markdown

The PE specification defines BaseOfData as a four-byte field present in PE32 but absent from PE32+. Rebuilding a PE32 executable currently drops this field, shifting subsequent headers and corrupting the image. Instead, we should preserve the existing BaseOfData bytes when serializing PE32 headers.

Copilot AI lite review requested due to automatic review settings August 5, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes PE32 image rewriting by ensuring the 4-byte BaseOfData field (present in PE32, absent in PE32+) is preserved during serialization so subsequent optional-header fields are not shifted and corrupted.

Changes:

  • Preserve the original BaseOfData bytes when rewriting PE32 optional headers.
  • Add a regression test that rebuilds a PE32 image and asserts byte-size stability and parse/equality round-trips.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
tests/tests.rs Adds a PE32-specific rebuild test using a 32-bit fixture to prevent header-shift regressions.
src/image.rs Copies the on-disk BaseOfData bytes into the rebuilt header for PE32 images before serializing the rest of the optional header.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants