pe: harden module name and row schema guards in import_routing with standalone unit suite #2879

Manually merged
github merged 1 commit from github-bot/gh-2879 into gh-pr/2879/base 2026-11-27 03:17:50 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-11-26 16:07 UTC · original
Ammmae0x:pe/import-routing-check → main · +266 −0 · 3 files · 1 commits · merged 2026-11-27 03:15 UTC

Change

Harden input validation in tools/import_routing.py and add a standalone unit, boundary-validation, and temp-copy mutation suite (tests/import_routing_check.py, registered via tests/cmake/pe_import_routing.cmake).

  • classify(module) validates via _validate_module() and raises ValueError on non-str, empty, whitespace-containing, or control-character module names (never AttributeError or misclassifying "" as unsupported).
  • annotate(row, module_key="module") validates that row is a MutableMapping (TypeError) containing module_key (KeyError) and validates module before mutating row.
  • Preserves all existing POLICY routes, constants (POLICY_VERSION, ROUTE_KIND, RESOLUTION, ROUTES), case-insensitive matching, original-case HLE candidate_provider, and return schemas.

Verification

Commit: bac0ae5a (Windows 11 x64, out\pe-env\Scripts\python.exe -B):

  • out\pe-env\Scripts\python.exe -B tests\import_routing_check.py -v -> 2/2 tests OK (all 4 policy routes, mixed case, api-ms-win-/ext-ms- prefix vs substring controls, non-str/empty/whitespace/control refusals, non-mapping/missing-key/atomic-no-mutation refusals, UserDict & custom module_key, and 6 temp-copy mutations).
  • out\pe-env\Scripts\python.exe -B tests\intake\routing_check.py -> passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\dependency_paths_check.py -> passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\compat_report_check.py -> passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\compat_report_cli_check.py -> 10/10 tests OK (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> passed (29 Markdown files, 545 links, exit 0).
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> passed (2048 files, exit 0).
  • Independent spot-mutation audit: disabling isinstance(module, str), disabling isinstance(row, MutableMapping), and relaxing name.startswith(prefix) to prefix in name one-by-one each caused tests\import_routing_check.py to fail (exit 1).

Evidence and follow-up

All test inputs are synthetic module names and in-memory mappings; zero external files or game inputs are used. Existing callers (intake/routing_check.py, dependency_paths_check.py, compat_report_check.py, compat_report_cli_check.py) pass unchanged.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-26 16:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2879) `Ammmae0x:pe/import-routing-check` → `main` · +266 −0 · 3 files · 1 commits · merged 2026-11-27 03:15 UTC ## Change Harden input validation in `tools/import_routing.py` and add a standalone unit, boundary-validation, and temp-copy mutation suite (`tests/import_routing_check.py`, registered via `tests/cmake/pe_import_routing.cmake`). - `classify(module)` validates via `_validate_module()` and raises `ValueError` on non-`str`, empty, whitespace-containing, or control-character module names (never `AttributeError` or misclassifying `""` as `unsupported`). - `annotate(row, module_key="module")` validates that `row` is a `MutableMapping` (`TypeError`) containing `module_key` (`KeyError`) and validates `module` before mutating `row`. - Preserves all existing `POLICY` routes, constants (`POLICY_VERSION`, `ROUTE_KIND`, `RESOLUTION`, `ROUTES`), case-insensitive matching, original-case HLE `candidate_provider`, and return schemas. ## Verification Commit: `bac0ae5a` (Windows 11 x64, `out\pe-env\Scripts\python.exe -B`): - `out\pe-env\Scripts\python.exe -B tests\import_routing_check.py -v` -> 2/2 tests OK (all 4 policy routes, mixed case, `api-ms-win-`/`ext-ms-` prefix vs substring controls, non-str/empty/whitespace/control refusals, non-mapping/missing-key/atomic-no-mutation refusals, `UserDict` & custom `module_key`, and 6 temp-copy mutations). - `out\pe-env\Scripts\python.exe -B tests\intake\routing_check.py` -> passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\dependency_paths_check.py` -> passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\compat_report_check.py` -> passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\compat_report_cli_check.py` -> 10/10 tests OK (exit 0). - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> passed (29 Markdown files, 545 links, exit 0). - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> passed (2048 files, exit 0). - Independent spot-mutation audit: disabling `isinstance(module, str)`, disabling `isinstance(row, MutableMapping)`, and relaxing `name.startswith(prefix)` to `prefix in name` one-by-one each caused `tests\import_routing_check.py` to fail (exit 1). ## Evidence and follow-up All test inputs are synthetic module names and in-memory mappings; zero external files or game inputs are used. Existing callers (`intake/routing_check.py`, `dependency_paths_check.py`, `compat_report_check.py`, `compat_report_cli_check.py`) pass unchanged. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:27:44 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 02:07 UTC · original · reviewed

Small, targeted safety improvement. _validate_module() rejects non-str, empty, whitespace, and control-character names before lower() normalization. annotate() now requires MutableMapping and checks module_key presence upfront, preventing silent KeyError or attribute failures.

The mutation harness is well-designed: seven mutations (type guard, whitespace guard, MutableMapping check, lower normalization, startswith→in, candidate_provider casing, substring API-set prefix) all run the full contract and mutation-verify that each removed guard escapes detection.

One tiny note: the MutableMapping import is from collections.abc (standard library). This is correct and preferred over collections.MutableMapping which was deprecated in 3.3 and removed in 3.10, so no issue there.

No concerns.

**@⁠KelboLive** on GitHub · 2026-11-27 02:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2879#pullrequestreview-6082569244) · **reviewed** Small, targeted safety improvement. _validate_module() rejects non-str, empty, whitespace, and control-character names before lower() normalization. annotate() now requires MutableMapping and checks module_key presence upfront, preventing silent KeyError or attribute failures. The mutation harness is well-designed: seven mutations (type guard, whitespace guard, MutableMapping check, lower normalization, startswith→in, candidate_provider casing, substring API-set prefix) all run the full contract and mutation-verify that each removed guard escapes detection. One tiny note: the MutableMapping import is from collections.abc (standard library). This is correct and preferred over collections.MutableMapping which was deprecated in 3.3 and removed in 3.10, so no issue there. No concerns.
github-bot changed target branch from main to gh-pr/2879/base 2026-11-27 03:17:49 +00:00
github manually merged commit bac0ae5abb into gh-pr/2879/base 2026-11-27 03:17:50 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 03:14 UTC · original · approved these changes

Reviewed the exact head bac0ae5abb7b921175de44539073eed49f69f6da. Valid module routing stays case-insensitive and keeps the caller's data; invalid names are rejected before routing metadata is written. I ran python -B tests/import_routing_check.py against the exact-head module in isolation, including the boundary and mutation cases. Both tests passed. Verified that main includes the test fragment and the required Windows check passed.

**@⁠R0Y00** on GitHub · 2026-11-27 03:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2879#pullrequestreview-6082992501) · **approved these changes** Reviewed the exact head `bac0ae5abb7b921175de44539073eed49f69f6da`. Valid module routing stays case-insensitive and keeps the caller's data; invalid names are rejected before routing metadata is written. I ran `python -B tests/import_routing_check.py` against the exact-head module in isolation, including the boundary and mutation cases. Both tests passed. Verified that main includes the test fragment and the required Windows check passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.