runtime: harden bool/integer and page bounds in host_commit with pure-Python unit suite #2885

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

@⁠Ammmae0x on GitHub · 2026-11-26 16:23 UTC · original
Ammmae0x:runtime/host-commit-check → main · +266 −4 · 3 files · 1 commits · merged 2026-11-27 03:15 UTC

Change

Harden boolean, integer, and snapshot-schema bounds validation in tools/host_commit.py and add a pure-Python unit, mocked WinAPI, and temp-copy mutation test suite (tests/host_commit_unit_check.py, registered via tests/cmake/runtime_host_commit_unit.cmake).

  • Reject bool and non-int inputs with ValueError in snapshot_from_pages() (page_size > 0, limit_pages > 0, used_pages >= 0) and require_commit_budget() (0 <= minimum_mib <= 1 << 20).
  • Validate snapshot in require_commit_budget() is a Mapping containing non-negative non-bool integer fields (available_bytes, limit_mib, used_mib, available_mib).
  • Preserve clamping (free_bytes = max(limit_bytes - used_bytes, 0) when used_pages > limit_pages) and System32-only WinDLL("psapi.dll", winmode=0x800, use_last_error=True).

Verification

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

  • out\pe-env\Scripts\python.exe -B tests\host_commit_unit_check.py -v -> 2/2 tests OK (exact MiB math, clamping, bool/non-int/negative/zero refusals, budget boundaries, snapshot Mapping/field checks, mocked read_host_commit success/GetPerformanceInfo==0/non-win32 OSError, and 6 temp-copy mutations).
  • out\pe-env\Scripts\python.exe -B tests\host_commit_check.py -> 7/7 tests OK.
  • 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 the bool check in _is_int, disabling the Mapping check in require_commit_budget, and dropping max(..., 0) clamping in snapshot_from_pages one-by-one each caused tests\host_commit_unit_check.py to fail (exit 1).

Evidence and follow-up

All tests use synthetic page counts and mocked psapi.dll/GetPerformanceInfo calls; zero external or game files are used.

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:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2885) `Ammmae0x:runtime/host-commit-check` → `main` · +266 −4 · 3 files · 1 commits · merged 2026-11-27 03:15 UTC ## Change Harden boolean, integer, and snapshot-schema bounds validation in `tools/host_commit.py` and add a pure-Python unit, mocked WinAPI, and temp-copy mutation test suite (`tests/host_commit_unit_check.py`, registered via `tests/cmake/runtime_host_commit_unit.cmake`). - Reject `bool` and non-`int` inputs with `ValueError` in `snapshot_from_pages()` (`page_size > 0`, `limit_pages > 0`, `used_pages >= 0`) and `require_commit_budget()` (`0 <= minimum_mib <= 1 << 20`). - Validate `snapshot` in `require_commit_budget()` is a `Mapping` containing non-negative non-bool integer fields (`available_bytes`, `limit_mib`, `used_mib`, `available_mib`). - Preserve clamping (`free_bytes = max(limit_bytes - used_bytes, 0)` when `used_pages > limit_pages`) and System32-only `WinDLL("psapi.dll", winmode=0x800, use_last_error=True)`. ## Verification Commit: `b0fc3111` (Windows 11 x64, `out\pe-env\Scripts\python.exe -B`): - `out\pe-env\Scripts\python.exe -B tests\host_commit_unit_check.py -v` -> 2/2 tests OK (exact MiB math, clamping, bool/non-int/negative/zero refusals, budget boundaries, snapshot Mapping/field checks, mocked `read_host_commit` success/`GetPerformanceInfo==0`/non-win32 `OSError`, and 6 temp-copy mutations). - `out\pe-env\Scripts\python.exe -B tests\host_commit_check.py` -> 7/7 tests OK. - `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 the `bool` check in `_is_int`, disabling the `Mapping` check in `require_commit_budget`, and dropping `max(..., 0)` clamping in `snapshot_from_pages` one-by-one each caused `tests\host_commit_unit_check.py` to fail (exit 1). ## Evidence and follow-up All tests use synthetic page counts and mocked `psapi.dll`/`GetPerformanceInfo` calls; zero external or game files are used. ## 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:53 +00:00
Author
Owner

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

Hardening commit budget validation is a smart addition. The new _is_int() helper correctly excludes bool (a common Python gotcha since bool is a subclass of int), and it's used consistently across snapshot_from_pages() and require_commit_budget().

Key improvements:

  1. _is_int() properly rejects bool, float, None, str — all caught by the test suite
  2. _SNAPSHOT_KEYS validates required fields are present and non-negative integers, preventing silent KeyError from partial dicts
  3. Snapshot Mapping check prevents passing lists, tuples, or strings that happen to iterate
  4. Mutation harness covers all 6 guard categories including winmode=0x800 (which could fall back to a potentially different library on older Windows versions)

The bool exclusion (_is_int) is the most critical: without it, True (==1) or False (==0) would silently pass numeric checks, potentially allowing a budget of 0 MiB or a true budget to be treated as 1 MiB.

The test cases are thorough — every edge case (None, bool, float, str, negative, zero, >1MiB caps) is covered. No concerns.

**@⁠KelboLive** on GitHub · 2026-11-27 02:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2885#pullrequestreview-6082609278) · **reviewed** Hardening commit budget validation is a smart addition. The new _is_int() helper correctly excludes bool (a common Python gotcha since bool is a subclass of int), and it's used consistently across snapshot_from_pages() and require_commit_budget(). Key improvements: 1. _is_int() properly rejects bool, float, None, str — all caught by the test suite 2. _SNAPSHOT_KEYS validates required fields are present and non-negative integers, preventing silent KeyError from partial dicts 3. Snapshot Mapping check prevents passing lists, tuples, or strings that happen to iterate 4. Mutation harness covers all 6 guard categories including winmode=0x800 (which could fall back to a potentially different library on older Windows versions) The bool exclusion (_is_int) is the most critical: without it, True (==1) or False (==0) would silently pass numeric checks, potentially allowing a budget of 0 MiB or a true budget to be treated as 1 MiB. The test cases are thorough — every edge case (None, bool, float, str, negative, zero, >1MiB caps) is covered. No concerns.
github-bot changed target branch from main to gh-pr/2885/base 2026-11-27 03:17:52 +00:00
github manually merged commit b0fc3111da into gh-pr/2885/base 2026-11-27 03:17:54 +00:00
Author
Owner

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

Reviewed the exact head b0fc3111da330da0634dbbd18647894c41b24ffc. Checked the package-launch caller and the GetPerformanceInfo conversion. The page arithmetic still floors available bytes at zero, and the budget check rejects booleans and malformed snapshots. I ran python -B tests/host_commit_unit_check.py against the exact-head module in isolation; both tests passed, including mocked API and mutation checks. 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/2885#pullrequestreview-6082993123) · **approved these changes** Reviewed the exact head `b0fc3111da330da0634dbbd18647894c41b24ffc`. Checked the package-launch caller and the `GetPerformanceInfo` conversion. The page arithmetic still floors available bytes at zero, and the budget check rejects booleans and malformed snapshots. I ran `python -B tests/host_commit_unit_check.py` against the exact-head module in isolation; both tests passed, including mocked API and mutation checks. 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.