pe: harden module name and row schema guards in import_routing with standalone unit suite #2879
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2879
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2879"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCChange
Harden input validation in
tools/import_routing.pyand add a standalone unit, boundary-validation, and temp-copy mutation suite (tests/import_routing_check.py, registered viatests/cmake/pe_import_routing.cmake).classify(module)validates via_validate_module()and raisesValueErroron non-str, empty, whitespace-containing, or control-character module names (neverAttributeErroror misclassifying""asunsupported).annotate(row, module_key="module")validates thatrowis aMutableMapping(TypeError) containingmodule_key(KeyError) and validatesmodulebefore mutatingrow.POLICYroutes, constants (POLICY_VERSION,ROUTE_KIND,RESOLUTION,ROUTES), case-insensitive matching, original-case HLEcandidate_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& custommodule_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).isinstance(module, str), disablingisinstance(row, MutableMapping), and relaxingname.startswith(prefix)toprefix in nameone-by-one each causedtests\import_routing_check.pyto 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
AI-assisted.
@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.
@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 ranpython -B tests/import_routing_check.pyagainst 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.