tests: cover x2w_runtime_patch PE import and delay-load walkers #3751

Manually merged
github merged 2 commits from github-bot/gh-3749 into main 2026-12-01 17:05:19 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-01 14:55 UTC · original
Ammmae0x:tests/runtime-gpa-patch-unit → main · +1502 −0 · 5 files · 2 commits · merged 2026-12-01 17:04 UTC

Refs #1149

Portable C++17 unit, malformed-PE boundary, and 1:1 header-mutation tests for x2w_runtime_patch (src/startup_stubs/runtime_gpa_patch.h), with zero edits to existing files (5 new files only). The existing tests/startup_runtime_gpa_patch_check.cpp coverage is untouched, and the new check uses the disjoint runtime_gpa_patch_unit prefix so test names do not collide.

  • tests/runtime_gpa_patch_unit_check.cpp: 33 cases, pure C++17, no <windows.h>. dll_is_xgameruntime (exact lower, mixed and upper case, null, empty, a short prefix, an extra suffix); the case-sensitive import names and classify (GetProcAddress from any DLL, QueryApiImpl only from xgameruntime.dll, rejections leaving kind unchanged); readable_range (null base, zero bytes, an RVA past the image, the overflow guard, the exact end) and c_string_in_image (a NUL at the last byte, an unterminated string); the packed struct layout (DosStub 64 bytes with e_lfanew at 60, ImportDesc 20, DelayDesc 32); and visit_imports / visit_imports_with over synthetic PE32+ byte buffers (regular imports with exact kind / first-thunk RVA / DLL / import name, delay imports flagged delay_import, an ordinal thunk skipped while later named thunks are still visited, bad DOS magic, a negative e_lfanew, a bad PE signature, PE32 rejected, truncated headers, a sparse null-name descriptor skipped, an unterminated hint string skipped, a custom classifier returning Kind::registry, null and empty images, an all-zero descriptor terminating the walk, and zero-size import/delay directories). Buffers are written byte by byte, with no reinterpret_cast of image data.
  • tests/cmake/runtime_gpa_patch_unit.cmake: per-case CTests plus runtime_gpa_patch_unit_all and 6 WILL_FAIL TRUE header-copy controls (dll_suffix, query_gate, pe32_magic, ordinal_skip, delay_flag, readable_range) with mutated copies under startup_stubs/runtime_gpa_patch.h and BEFORE PRIVATE include.
  • tests/runtime_gpa_patch_unit_meta_check.py, tests/checks/python-linux/runtime_gpa_patch_unit.txt, docs/experiments/runtime-gpa-patch-unit.md.

Linux checks (this host, g++ -std=c++17):

/tmp/pe-env/bin/python -B tests/runtime_gpa_patch_unit_meta_check.py
PASS: runtime_gpa_patch_unit: 33 cases, 6/6 mutations killed (g++)

Scratch CMake + CTest: 40/40 (33 cases, runtime_gpa_patch_unit_all, 6 mutation controls). Form, docs (208 files / 802 links), and bidi (2827 files) checks pass; parallel Python runner 299/299; diff --check clean; merge-tree vs origin/main exits 0.

No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter.

AI-assisted.

Windows Verification (ee993a26)

  • git merge-tree --write-tree upstream/main HEAD -> 86e6561d (exit 0), git diff --check upstream/main...HEAD clean
  • Repo checks: py_compile, form_coverage_check.py, docs_links_check.py (209 files, 806 links), bidi_controls_check.py (2830 files) passed
  • Commands:
cmake --build --preset dev --target runtime_gpa_patch_unit_check runtime_gpa_patch_unit_dll_suffix_mut runtime_gpa_patch_unit_query_gate_mut runtime_gpa_patch_unit_pe32_magic_mut runtime_gpa_patch_unit_ordinal_skip_mut runtime_gpa_patch_unit_delay_flag_mut runtime_gpa_patch_unit_readable_range_mut
ctest --preset dev --no-tests=error -j16 -R "^runtime_gpa_patch_unit" --output-on-failure
cmake --build --preset release --target runtime_gpa_patch_unit_check runtime_gpa_patch_unit_dll_suffix_mut runtime_gpa_patch_unit_query_gate_mut runtime_gpa_patch_unit_pe32_magic_mut runtime_gpa_patch_unit_ordinal_skip_mut runtime_gpa_patch_unit_delay_flag_mut runtime_gpa_patch_unit_readable_range_mut
ctest --preset release --no-tests=error -j16 -R "^runtime_gpa_patch_unit" --output-on-failure
  • Results: dev 40/40 passed (0.95s); release 40/40 passed (0.90s); direct runtime_gpa_patch_unit_check.exe (dev & release): PASS: runtime_gpa_patch_unit: 33/33 cases passed. AI-assisted.
**@⁠Ammmae0x** on GitHub · 2026-12-01 14:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3749) `Ammmae0x:tests/runtime-gpa-patch-unit` → `main` · +1502 −0 · 5 files · 2 commits · merged 2026-12-01 17:04 UTC Refs #1149 Portable C++17 unit, malformed-PE boundary, and 1:1 header-mutation tests for `x2w_runtime_patch` (`src/startup_stubs/runtime_gpa_patch.h`), with zero edits to existing files (5 new files only). The existing `tests/startup_runtime_gpa_patch_check.cpp` coverage is untouched, and the new check uses the disjoint `runtime_gpa_patch_unit` prefix so test names do not collide. - `tests/runtime_gpa_patch_unit_check.cpp`: 33 cases, pure C++17, no `<windows.h>`. `dll_is_xgameruntime` (exact lower, mixed and upper case, null, empty, a short prefix, an extra suffix); the case-sensitive import names and `classify` (`GetProcAddress` from any DLL, `QueryApiImpl` only from `xgameruntime.dll`, rejections leaving `kind` unchanged); `readable_range` (null base, zero bytes, an RVA past the image, the overflow guard, the exact end) and `c_string_in_image` (a NUL at the last byte, an unterminated string); the packed struct layout (`DosStub` 64 bytes with `e_lfanew` at 60, `ImportDesc` 20, `DelayDesc` 32); and `visit_imports` / `visit_imports_with` over synthetic PE32+ byte buffers (regular imports with exact kind / first-thunk RVA / DLL / import name, delay imports flagged `delay_import`, an ordinal thunk skipped while later named thunks are still visited, bad DOS magic, a negative `e_lfanew`, a bad PE signature, PE32 rejected, truncated headers, a sparse null-name descriptor skipped, an unterminated hint string skipped, a custom classifier returning `Kind::registry`, null and empty images, an all-zero descriptor terminating the walk, and zero-size import/delay directories). Buffers are written byte by byte, with no `reinterpret_cast` of image data. - `tests/cmake/runtime_gpa_patch_unit.cmake`: per-case CTests plus `runtime_gpa_patch_unit_all` and 6 `WILL_FAIL TRUE` header-copy controls (`dll_suffix`, `query_gate`, `pe32_magic`, `ordinal_skip`, `delay_flag`, `readable_range`) with mutated copies under `startup_stubs/runtime_gpa_patch.h` and `BEFORE PRIVATE` include. - `tests/runtime_gpa_patch_unit_meta_check.py`, `tests/checks/python-linux/runtime_gpa_patch_unit.txt`, `docs/experiments/runtime-gpa-patch-unit.md`. Linux checks (this host, `g++ -std=c++17`): ```text /tmp/pe-env/bin/python -B tests/runtime_gpa_patch_unit_meta_check.py PASS: runtime_gpa_patch_unit: 33 cases, 6/6 mutations killed (g++) ``` Scratch CMake + CTest: 40/40 (33 cases, `runtime_gpa_patch_unit_all`, 6 mutation controls). Form, docs (208 files / 802 links), and bidi (2827 files) checks pass; parallel Python runner 299/299; `diff --check` clean; merge-tree vs `origin/main` exits 0. No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter. AI-assisted. <!-- WIN-VERIFY: passed | sha=ee993a2627cf268c4b0e36ad14fd82b90f615627 | targets=runtime_gpa_patch_unit_check runtime_gpa_patch_unit_dll_suffix_mut runtime_gpa_patch_unit_query_gate_mut runtime_gpa_patch_unit_pe32_magic_mut runtime_gpa_patch_unit_ordinal_skip_mut runtime_gpa_patch_unit_delay_flag_mut runtime_gpa_patch_unit_readable_range_mut | ctest=^runtime_gpa_patch_unit | release=true --> ### Windows Verification (`ee993a26`) - `git merge-tree --write-tree upstream/main HEAD` -> `86e6561d` (exit 0), `git diff --check upstream/main...HEAD` clean - Repo checks: `py_compile`, `form_coverage_check.py`, `docs_links_check.py` (209 files, 806 links), `bidi_controls_check.py` (2830 files) passed - Commands: ```text cmake --build --preset dev --target runtime_gpa_patch_unit_check runtime_gpa_patch_unit_dll_suffix_mut runtime_gpa_patch_unit_query_gate_mut runtime_gpa_patch_unit_pe32_magic_mut runtime_gpa_patch_unit_ordinal_skip_mut runtime_gpa_patch_unit_delay_flag_mut runtime_gpa_patch_unit_readable_range_mut ctest --preset dev --no-tests=error -j16 -R "^runtime_gpa_patch_unit" --output-on-failure cmake --build --preset release --target runtime_gpa_patch_unit_check runtime_gpa_patch_unit_dll_suffix_mut runtime_gpa_patch_unit_query_gate_mut runtime_gpa_patch_unit_pe32_magic_mut runtime_gpa_patch_unit_ordinal_skip_mut runtime_gpa_patch_unit_delay_flag_mut runtime_gpa_patch_unit_readable_range_mut ctest --preset release --no-tests=error -j16 -R "^runtime_gpa_patch_unit" --output-on-failure ``` - Results: `dev` 40/40 passed (0.95s); `release` 40/40 passed (0.90s); direct `runtime_gpa_patch_unit_check.exe` (`dev` & `release`): `PASS: runtime_gpa_patch_unit: 33/33 cases passed`. AI-assisted.
Refs #1149. Portable C++17 unit, malformed-PE boundary, and 1:1 header-mutation tests for src/startup_stubs/runtime_gpa_patch.h, with zero edits to existing files (5 new files only).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 15:00:12 +00:00
Fix the use-after-free caught by MSVC Debug CTest: collect(build_pe(...))
handed patch::Hit pointers into a temporary image that was destroyed at
the end of the full expression, so visit_regular_imports,
visit_delay_imports and runtime_gpa_patch_unit_all failed (37/40).
Store build_pe(...) in a named const image before collect(image) at
all four call sites, and add a deleted collect(const vector<unsigned
char>&&) overload so a temporary image is rejected at compile time
under both GCC and MSVC. Audited the rest of the file: every other
collect(image) either keeps a named image alive while its hits are
used or only reads .size() within the same expression, and the
visit_imports_with sites keep their image alive for the whole case.
github manually merged commit 5372c9bf42 into main 2026-12-01 17:05:19 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.