textures: harden paged_resource validation and add unit suite #2668

Merged
Ammmae0x merged 3 commits from upstream-pr/2676 into main 2026-11-26 03:13:23 +00:00
Ammmae0x commented 2026-11-26 01:45:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:45:48Z.


Change

Harden input validation in tools/paged_resource.py and add a pure-Python unit, edge-case, and mutation suite (tests/paged_resource_check.py), registered in CMakeLists.txt as textures_paged_resource_check.

  • Reject bool and non-int values (isinstance(v, bool) or not isinstance(v, int)) with explicit ValueError for Segment (offset, stored, size) and PagedResource.read() (offset, length, limit).
  • Validate upfront in PagedResource.__init__() that every segment codec is a supported string ("raw" or "zlib"), and reject negative limit < 0 in PagedResource.read().
  • Preserve existing ValueError messages and positive behavior across all callers (tools/texture_descriptors.py, tools/script_state_probe.py, tools/shader_census.py).

Verification

Verified on commit f69f1e7b (based on upstream/main 82c70807) on Windows using out/pe-env/Scripts/python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\paged_resource_check.py -> exit 0 (6/6 tests OK, 0 skips: multi-segment raw+zlib boundary spans, short-read _read_at reassembly, bool/non-int/overlapping/descending/empty/oversized/bad-codec/bad-raw-size rejections, corrupt/truncated/trailing-data/over-limit zlib, negative/bool/overflow read() bounds, and 5 fast in-memory mutations).
  • Caller checks: tests\texture_descriptors_check.py, tests\awc_metadata_check.py (14 OK), tests\resource_root_check.py (5 OK), tests\sgd5_effects_check.py (4 OK) -> all exit 0.
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py, tests\docs_links_check.py, tests\bidi_controls_check.py -> all exit 0.
  • On-disk spot-mutation negative controls (3/3 killed by tests/paged_resource_check.py): allowing bool in _require_int(), skipping upfront codec validation in __init__(), and allowing negative limit in read().

Evidence and follow-up

  • Pure-Python synthetic archives and in-memory BytesIO / short-read streams constructed at runtime (MIT License; no external data or binaries).
  • No external tools or GPU hardware required.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617635231 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2676). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:45:48Z. --- ## Change Harden input validation in `tools/paged_resource.py` and add a pure-Python unit, edge-case, and mutation suite (`tests/paged_resource_check.py`), registered in `CMakeLists.txt` as `textures_paged_resource_check`. - Reject `bool` and non-`int` values (`isinstance(v, bool) or not isinstance(v, int)`) with explicit `ValueError` for `Segment` (`offset`, `stored`, `size`) and `PagedResource.read()` (`offset`, `length`, `limit`). - Validate upfront in `PagedResource.__init__()` that every segment `codec` is a supported string (`"raw"` or `"zlib"`), and reject negative `limit < 0` in `PagedResource.read()`. - Preserve existing `ValueError` messages and positive behavior across all callers (`tools/texture_descriptors.py`, `tools/script_state_probe.py`, `tools/shader_census.py`). ## Verification Verified on commit `f69f1e7b` (based on `upstream/main` `82c70807`) on Windows using `out/pe-env/Scripts/python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\paged_resource_check.py` -> exit 0 (6/6 tests OK, 0 skips: multi-segment raw+zlib boundary spans, short-read `_read_at` reassembly, bool/non-int/overlapping/descending/empty/oversized/bad-codec/bad-raw-size rejections, corrupt/truncated/trailing-data/over-limit zlib, negative/bool/overflow `read()` bounds, and 5 fast in-memory mutations). - Caller checks: `tests\texture_descriptors_check.py`, `tests\awc_metadata_check.py` (14 OK), `tests\resource_root_check.py` (5 OK), `tests\sgd5_effects_check.py` (4 OK) -> all exit 0. - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py`, `tests\docs_links_check.py`, `tests\bidi_controls_check.py` -> all exit 0. - On-disk spot-mutation negative controls (3/3 killed by `tests/paged_resource_check.py`): allowing `bool` in `_require_int()`, skipping upfront codec validation in `__init__()`, and allowing negative `limit` in `read()`. ## Evidence and follow-up - Pure-Python synthetic archives and in-memory `BytesIO` / short-read streams constructed at runtime (MIT License; no external data or binaries). - No external tools or GPU hardware required. ## 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.
Ammmae0x commented 2026-11-26 02:05:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:56:42Z.


Fixed the Linux CI failure in tests/resource_ranges_check.py (commit f9ac2505): PagedResource.__init__() now rejects only non-str/empty codecs upfront and defers unknown string codecs (such as "other") to PagedResource.read() so segments following an unknown codec remain independently addressable as tested by test_invalid_segments and documented in docs/experiments.md. Updated tests/paged_resource_check.py to cover both upfront non-str/empty rejections and deferred unknown-codec read() failures.

Verified locally with tests/resource_ranges_check.py (21 OK), tests/paged_resource_check.py (6 OK), caller suites (texture_descriptors_check, awc_metadata_check, resource_root_check, sgd5_effects_check, script_state_check, shader_census_check), tests/form_coverage_check.py, tests/docs_links_check.py, and tests/bidi_controls_check.py (all exit 0). AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180305314 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2676#issuecomment-7180305314). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:56:42Z. --- Fixed the Linux CI failure in `tests/resource_ranges_check.py` (commit `f9ac2505`): `PagedResource.__init__()` now rejects only non-`str`/empty codecs upfront and defers unknown string codecs (such as `"other"`) to `PagedResource.read()` so segments following an unknown codec remain independently addressable as tested by `test_invalid_segments` and documented in `docs/experiments.md`. Updated `tests/paged_resource_check.py` to cover both upfront non-`str`/empty rejections and deferred unknown-codec `read()` failures. Verified locally with `tests/resource_ranges_check.py` (21 OK), `tests/paged_resource_check.py` (6 OK), caller suites (`texture_descriptors_check`, `awc_metadata_check`, `resource_root_check`, `sgd5_effects_check`, `script_state_check`, `shader_census_check`), `tests/form_coverage_check.py`, `tests/docs_links_check.py`, and `tests/bidi_controls_check.py` (all exit 0). AI-assisted.
tedin7 commented 2026-11-26 03:03:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:01:39Z.

Review: COMMENTED


Review of head 3ff83f28 (after merging current main).

Looks sound:

  • tools/paged_resource.py: bool/non-int rejection for Segment fields and read() args, upfront codec check, negative limit rejected. Existing error messages and positive behavior are unchanged.
  • The new tests/paged_resource_check.py covers boundary spans, short reads, corrupt/truncated zlib, bad bounds and in-memory mutations. It is registered as textures_paged_resource_check next to its sibling Python checks.
  • No other open or merged PR touches paged_resource.

Commands run locally (Linux, worktree at this head):

  • python3 -B tests/paged_resource_check.py -> 6 tests OK
  • python3 -B tests/resource_ranges_check.py, tests/texture_descriptors_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py -> exit 0
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: drop the bool rejection in _require_int -> new test fails (7 failures)
  • Mutation 2: drop the limit < 0 check in read() -> new test fails (1 failure)

Windows receipt follows separately.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067976189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2676#pullrequestreview-6067976189). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:01:39Z. **Review:** COMMENTED --- Review of head 3ff83f28 (after merging current main). Looks sound: - `tools/paged_resource.py`: bool/non-int rejection for `Segment` fields and `read()` args, upfront codec check, negative `limit` rejected. Existing error messages and positive behavior are unchanged. - The new `tests/paged_resource_check.py` covers boundary spans, short reads, corrupt/truncated zlib, bad bounds and in-memory mutations. It is registered as `textures_paged_resource_check` next to its sibling Python checks. - No other open or merged PR touches `paged_resource`. Commands run locally (Linux, worktree at this head): - `python3 -B tests/paged_resource_check.py` -> 6 tests OK - `python3 -B tests/resource_ranges_check.py`, `tests/texture_descriptors_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` -> exit 0 - `git diff --check origin/main...HEAD` -> clean - Mutation 1: drop the `bool` rejection in `_require_int` -> new test fails (7 failures) - Mutation 2: drop the `limit < 0` check in `read()` -> new test fails (1 failure) Windows receipt follows separately. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 04:04:15 +00:00
tedin7 commented 2026-11-26 04:04:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:11:38Z.


Win2025 WARP receipt for head 3ff83f28 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 3ff83f2878ba633c1cbc97db5e0b4d9ea4fb3ff2:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 121.41s (configure 3.38s)
    • Test (ctest --preset dev -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (1.26s: textures_paged_resource_check 0.30s, layout_chunk_summary 1.06s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 231.92s (configure 3.38s)
    • Test (ctest --preset release -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (1.50s: textures_paged_resource_check 0.37s, layout_chunk_summary 1.26s)
  • Windows Python checks: tests/resource_ranges_check.py ok (1.0s)
  • sccache: 143/207 hits; wall 372.4s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181479846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2676#issuecomment-7181479846). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:11:38Z. --- Win2025 WARP receipt for head 3ff83f28 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `3ff83f2878ba633c1cbc97db5e0b4d9ea4fb3ff2`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `121.41s` (configure `3.38s`) - Test (`ctest --preset dev -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`1.26s`: `textures_paged_resource_check` `0.30s`, `layout_chunk_summary` `1.06s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `231.92s` (configure `3.38s`) - Test (`ctest --preset release -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`1.50s`: `textures_paged_resource_check` `0.37s`, `layout_chunk_summary` `1.26s`) - **Windows Python checks**: `tests/resource_ranges_check.py` ok (`1.0s`) - `sccache`: 143/207 hits; wall `372.4s` AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
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!2668
No description provided.