Add a mutation harness for the PE mapper #179

Closed
opened 2026-11-21 18:04:49 +00:00 by raulmoracode · 0 comments
raulmoracode commented 2026-11-21 18:04:49 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:04:49Z.


Question

Can the PE mapper be exercised against malformed images without ending the test suite, and does every malformed image produce a named result instead of a crash or a hang?

Evidence so far

  • tests/cpu/native_map_check.py patches a handful of specific fields: the entry point, the import directory Size, the delay-import directory and one export address slot. Header corruption, section-table corruption, relocation-table corruption and truncated files are not covered.
  • The mapper reads DOS, NT and section fields before it has validated all of them, so a single corrupted field is a plausible crash site. #163 is one example in a related function.
  • A crash inside a Python process ends the whole CTest run, so an in-process mutation loop cannot report which input crashed.

Proposal

A cpu_native_mutation test that applies a fixed list of single-field edits and three truncations to the source-built fixtures. Each case runs in its own process and prints either MAP_OK or one of the named MapStatus values with a detail string. The parent fails the case on a crash, a timeout, an unknown status, or a status that disagrees with the returned base.

The mutation list is fixed offsets computed with pefile, not random input, so every run is reproducible and no corpus is needed.

Completion condition

ctest --preset dev --no-tests=error -R '^cpu_native_mutation$' -V passes on main, and the same test fails when the mapper is replaced by one that crashes. That control was demonstrated with a three-line mapper DLL that dereferences null.

Required environment

x64 Windows, MSVC, CMake/Ninja, Python 3.11 or newer with pefile. No game files.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532507515 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/180). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:04:49Z. --- ## Question Can the PE mapper be exercised against malformed images without ending the test suite, and does every malformed image produce a named result instead of a crash or a hang? ## Evidence so far - `tests/cpu/native_map_check.py` patches a handful of specific fields: the entry point, the import directory `Size`, the delay-import directory and one export address slot. Header corruption, section-table corruption, relocation-table corruption and truncated files are not covered. - The mapper reads DOS, NT and section fields before it has validated all of them, so a single corrupted field is a plausible crash site. #163 is one example in a related function. - A crash inside a Python process ends the whole CTest run, so an in-process mutation loop cannot report which input crashed. ## Proposal A `cpu_native_mutation` test that applies a fixed list of single-field edits and three truncations to the source-built fixtures. Each case runs in its own process and prints either `MAP_OK` or one of the named `MapStatus` values with a detail string. The parent fails the case on a crash, a timeout, an unknown status, or a status that disagrees with the returned base. The mutation list is fixed offsets computed with `pefile`, not random input, so every run is reproducible and no corpus is needed. ## Completion condition `ctest --preset dev --no-tests=error -R '^cpu_native_mutation$' -V` passes on `main`, and the same test fails when the mapper is replaced by one that crashes. That control was demonstrated with a three-line mapper DLL that dereferences null. ## Required environment x64 Windows, MSVC, CMake/Ninja, Python 3.11 or newer with `pefile`. No game files. _AI-assisted._
Sign in to join this conversation.
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows#179
No description provided.