textures: harden bool/integer and byte-type bounds in texture_blocks with standalone unit suite #2884

Manually merged
github merged 1 commit from github-bot/gh-2884 into gh-pr/2884/base 2026-11-27 08:38:18 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-11-26 16:23 UTC · original
Ammmae0x:textures/texture-blocks-check → main · +317 −13 · 3 files · 1 commits · merged 2026-11-27 08:34 UTC

Change

Harden integer, boolean, and byte-type validation in tools/texture_blocks.py and add a standalone unit, bounds-guard, and mutation test suite (tests/texture_blocks_check.py, registered via tests/cmake/textures_texture_blocks.cmake).

  • Reject bool and non-int values for width, height, depth, and pitch_blocks with ValueError across _grid, surface_bytes, linearize_blocks, tile_blocks, tile_volume_4k_s, and linearize_volume_4k_s, and reject non-str format names cleanly in format_info.
  • Validate padding in tile_blocks is bytes, bytearray, or a 1-D byte (format == "B") memoryview of exact block_bytes length.
  • Preserve all FORMATS entries and 2D/3D block round-trip behavior.

Verification

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

  • out\pe-env\Scripts\python.exe -B tests\texture_blocks_check.py -v -> 6/6 tests OK (BC1..BC7 2D & BC7_UNORM_VOLUME 3D round-trips, non-multiple-of-4 dimensions, padded pitch_blocks, bytes/bytearray/memoryview padding, bool/non-int/zero/negative/narrow-pitch/format-mismatch refusals, and 5 fast mutations).
  • out\pe-env\Scripts\python.exe -B tests\bc7_tiles_check.py -> 6/6 tests OK.
  • out\pe-env\Scripts\python.exe -B tests\gfx10_texture_roundtrip_check.py -> 6/6 tests OK (PASS).
  • out\pe-env\Scripts\python.exe -B tests\texture_bc_volume_check.py -> 11/11 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 _require_int, relaxing the memoryview format == "B" check in tile_blocks, and disabling the pitch < columns check in surface_bytes one-by-one each caused tests\texture_blocks_check.py to fail (exit 1).

Evidence and follow-up

All fixtures are deterministic synthetic BC block payloads generated in memory by tests/texture_blocks_check.py; 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/2884) `Ammmae0x:textures/texture-blocks-check` → `main` · +317 −13 · 3 files · 1 commits · merged 2026-11-27 08:34 UTC ## Change Harden integer, boolean, and byte-type validation in `tools/texture_blocks.py` and add a standalone unit, bounds-guard, and mutation test suite (`tests/texture_blocks_check.py`, registered via `tests/cmake/textures_texture_blocks.cmake`). - Reject `bool` and non-`int` values for `width`, `height`, `depth`, and `pitch_blocks` with `ValueError` across `_grid`, `surface_bytes`, `linearize_blocks`, `tile_blocks`, `tile_volume_4k_s`, and `linearize_volume_4k_s`, and reject non-`str` format names cleanly in `format_info`. - Validate `padding` in `tile_blocks` is `bytes`, `bytearray`, or a 1-D byte (`format == "B"`) `memoryview` of exact `block_bytes` length. - Preserve all `FORMATS` entries and 2D/3D block round-trip behavior. ## Verification Commit: `e710e909` (Windows 11 x64, `out\pe-env\Scripts\python.exe -B`): - `out\pe-env\Scripts\python.exe -B tests\texture_blocks_check.py -v` -> 6/6 tests OK (BC1..BC7 2D & BC7_UNORM_VOLUME 3D round-trips, non-multiple-of-4 dimensions, padded `pitch_blocks`, `bytes`/`bytearray`/`memoryview` padding, bool/non-int/zero/negative/narrow-pitch/format-mismatch refusals, and 5 fast mutations). - `out\pe-env\Scripts\python.exe -B tests\bc7_tiles_check.py` -> 6/6 tests OK. - `out\pe-env\Scripts\python.exe -B tests\gfx10_texture_roundtrip_check.py` -> 6/6 tests OK (`PASS`). - `out\pe-env\Scripts\python.exe -B tests\texture_bc_volume_check.py` -> 11/11 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 `_require_int`, relaxing the `memoryview` `format == "B"` check in `tile_blocks`, and disabling the `pitch < columns` check in `surface_bytes` one-by-one each caused `tests\texture_blocks_check.py` to fail (exit 1). ## Evidence and follow-up All fixtures are deterministic synthetic BC block payloads generated in memory by `tests/texture_blocks_check.py`; 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:51 +00:00
github-bot changed target branch from main to gh-pr/2884/base 2026-11-27 08:38:12 +00:00
github manually merged commit e710e9098f into gh-pr/2884/base 2026-11-27 08:38:14 +00:00
Author
Owner

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

Reviewed e710e909 on main 3b6c38a8. The new integer guards cover dimensions and pitch before the block arithmetic. The padding path normalizes supported byte buffers and checks an exact one-block length. Existing tight and pitched output paths still round-trip.

Independent Windows Python 3.12 runs of tests/texture_blocks_check.py, tests/bc7_tiles_check.py, tests/gfx10_texture_roundtrip_check.py, tests/texture_bc_volume_check.py and tests/bcpack_check.py passed all 39 tests. The new suite includes direct input-refusal and mutation controls. git diff --check was clean. Hosted Windows, Linux Python and gfx1013 checks passed.

**@⁠R0Y00** on GitHub · 2026-11-27 08:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2884#pullrequestreview-6085441836) · **approved these changes** Reviewed `e710e909` on `main` `3b6c38a8`. The new integer guards cover dimensions and pitch before the block arithmetic. The padding path normalizes supported byte buffers and checks an exact one-block length. Existing tight and pitched output paths still round-trip. Independent Windows Python 3.12 runs of `tests/texture_blocks_check.py`, `tests/bc7_tiles_check.py`, `tests/gfx10_texture_roundtrip_check.py`, `tests/texture_bc_volume_check.py` and `tests/bcpack_check.py` passed all 39 tests. The new suite includes direct input-refusal and mutation controls. `git diff --check` was clean. Hosted Windows, Linux Python and gfx1013 checks passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.