textures: guard truncated struct and zlib errors in texture_descriptors #2326

Merged
Ammmae0x merged 1 commit from upstream-pr/2334 into main 2026-11-25 13:01:29 +00:00
Ammmae0x commented 2026-11-25 12:41:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T12:41:56Z.


Change

Hardens main(argv) in tools/texture_descriptors.py and adds a standalone pure-Python unit and CLI check suite (tests/texture_descriptors_check.py, registered as texture_descriptors_check in CMakeLists.txt):

  • Validates non-negative --descriptor, --raw-page-map, and --zlib-segment indices in main(argv) before opening the input archive.
  • Catches struct.error and zlib.error alongside OSError and ValueError in main(argv), exiting cleanly via parser.exit(1, ...) with zero raw Python tracebacks.
  • Covers synthetic in-memory RDS5/ETPF archives across boundary(), read_tables(), describe_descriptor(), inventory(), raw_page_map() (with verified zero-filled padding), zlib_segment(), descriptor_indices(), and all JSON CLI modes (inventory, --descriptor, --raw-page-map, --zlib-segment, --lookup-key across multiple archives), plus negative controls for bad magic, nonzero/mismatched raw padding, non-increasing boundaries, non-raw metadata, truncated/empty headers, corrupt zlib, injected struct.error/zlib.error, invalid --lookup-key, duplicate archives, negative indices, and missing/directory inputs.

Verification

Commit: e64fae8f (based on upstream/main b1a644ae). Pure-Python change; no C++ or GPU binaries modified.

  • out/pe-env/Scripts/python.exe -B tests/texture_descriptors_check.py -> exit 0 (texture_descriptors: synthetic RDS5/ETPF helpers, JSON CLI modes, and error exits passed)
  • out/pe-env/Scripts/python.exe -B tests/resource_ranges_check.py -> exit 0 (Ran 21 tests ... OK)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 (Self-test passed.)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed.)
  • Spot-mutation verification (pre-push): temporarily disabling four guards in tools/texture_descriptors.py (size < 32 truncated header check, negative CLI index check, struct.error/zlib.error CLI catch, and nonzero raw-padding check) caused tests/texture_descriptors_check.py to fail with exit 1 in 4/4 cases.

Evidence and follow-up

  • Uses synthetic in-memory RDS5/ETPF archives and temporary files constructed by tests/texture_descriptors_check.py under the repository MIT license; no external binaries or game files are added.
  • Contributors can run the check directly with python -B tests/texture_descriptors_check.py or via CTest (texture_descriptors_check).
  • AI-assisted.

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. (No build requirement or user-facing capability doc change needed.)
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6604719739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2334). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T12:41:56Z. --- ## Change Hardens `main(argv)` in `tools/texture_descriptors.py` and adds a standalone pure-Python unit and CLI check suite (`tests/texture_descriptors_check.py`, registered as `texture_descriptors_check` in `CMakeLists.txt`): - Validates non-negative `--descriptor`, `--raw-page-map`, and `--zlib-segment` indices in `main(argv)` before opening the input archive. - Catches `struct.error` and `zlib.error` alongside `OSError` and `ValueError` in `main(argv)`, exiting cleanly via `parser.exit(1, ...)` with zero raw Python tracebacks. - Covers synthetic in-memory RDS5/ETPF archives across `boundary()`, `read_tables()`, `describe_descriptor()`, `inventory()`, `raw_page_map()` (with verified zero-filled padding), `zlib_segment()`, `descriptor_indices()`, and all JSON CLI modes (inventory, `--descriptor`, `--raw-page-map`, `--zlib-segment`, `--lookup-key` across multiple archives), plus negative controls for bad magic, nonzero/mismatched raw padding, non-increasing boundaries, non-raw metadata, truncated/empty headers, corrupt zlib, injected `struct.error`/`zlib.error`, invalid `--lookup-key`, duplicate archives, negative indices, and missing/directory inputs. ## Verification Commit: `e64fae8f` (based on `upstream/main` `b1a644ae`). Pure-Python change; no C++ or GPU binaries modified. - `out/pe-env/Scripts/python.exe -B tests/texture_descriptors_check.py` -> exit `0` (`texture_descriptors: synthetic RDS5/ETPF helpers, JSON CLI modes, and error exits passed`) - `out/pe-env/Scripts/python.exe -B tests/resource_ranges_check.py` -> exit `0` (`Ran 21 tests ... OK`) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (`form coverage checks passed`) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` (`Self-test passed.`) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Self-test passed.`) - Spot-mutation verification (pre-push): temporarily disabling four guards in `tools/texture_descriptors.py` (`size < 32` truncated header check, negative CLI index check, `struct.error`/`zlib.error` CLI catch, and nonzero raw-padding check) caused `tests/texture_descriptors_check.py` to fail with exit `1` in 4/4 cases. ## Evidence and follow-up - Uses synthetic in-memory RDS5/ETPF archives and temporary files constructed by `tests/texture_descriptors_check.py` under the repository MIT license; no external binaries or game files are added. - Contributors can run the check directly with `python -B tests/texture_descriptors_check.py` or via CTest (`texture_descriptors_check`). - AI-assisted. ## 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. (No build requirement or user-facing capability doc change needed.) - [x] I did not include game files, dumps, distribution links or secrets.
tedin7 commented 2026-11-25 13:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:45:43Z.

Review: COMMENTED


Review of head e64fae8fa24af63ab3f008ff44f5af5906f044ec (comment only, no approval).

Scope: tools/texture_descriptors.py (+4/-1), new tests/texture_descriptors_check.py (318 lines), CMake registration of texture_descriptors_check. Title and body are neutral. PR is mergeable. CI checks: Linux Python checks, Windows build and gfx1013 fixtures pass; coverage chart and /O2 skipped.

Commands run locally (in a worktree at the PR head):

  • git diff --stat origin/main...HEAD: 3 files, +324/-1
  • python3 tests/texture_descriptors_check.py: passed
  • python3 tests/docs_links_check.py: 18 files, 451 links, passed
  • python3 tests/bidi_controls_check.py: 1627 files, no bidi controls
  • git diff --check origin/main...HEAD: clean

Mutations (each reverted with git checkout -- .):

  1. Negative-index guard disabled (index < -999): suite fails (AssertionError, expected message missing). Killed.
  2. struct.error, zlib.error dropped from the except: suite fails on the injected struct.error. Killed.
  3. Only zlib.error dropped: suite fails on the injected zlib.error. Killed.

Findings

  • P1: none
  • P2: none
  • nit (tools/texture_descriptors.py, new guard in main): the message "Descriptor index outside the ETPF table (must be nonnegative)" is also used for --raw-page-map and --zlib-segment. That is accurate enough, but naming the offending flag would help users.
  • nit: the guard sits inside the try, so it runs after parse_args but before any file open. That is what the PR says, and the tests confirm it.

No Windows run needed: pure Python, no shader or C++ change.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057850184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2334#pullrequestreview-6057850184). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:45:43Z. **Review:** COMMENTED --- Review of head `e64fae8fa24af63ab3f008ff44f5af5906f044ec` (comment only, no approval). **Scope:** `tools/texture_descriptors.py` (+4/-1), new `tests/texture_descriptors_check.py` (318 lines), CMake registration of `texture_descriptors_check`. Title and body are neutral. PR is mergeable. CI checks: Linux Python checks, Windows build and gfx1013 fixtures pass; coverage chart and /O2 skipped. **Commands run locally (in a worktree at the PR head):** - `git diff --stat origin/main...HEAD`: 3 files, +324/-1 - `python3 tests/texture_descriptors_check.py`: passed - `python3 tests/docs_links_check.py`: 18 files, 451 links, passed - `python3 tests/bidi_controls_check.py`: 1627 files, no bidi controls - `git diff --check origin/main...HEAD`: clean **Mutations (each reverted with `git checkout -- .`):** 1. Negative-index guard disabled (`index < -999`): suite fails (AssertionError, expected message missing). Killed. 2. `struct.error, zlib.error` dropped from the except: suite fails on the injected `struct.error`. Killed. 3. Only `zlib.error` dropped: suite fails on the injected `zlib.error`. Killed. **Findings** - P1: none - P2: none - nit (`tools/texture_descriptors.py`, new guard in `main`): the message "Descriptor index outside the ETPF table (must be nonnegative)" is also used for `--raw-page-map` and `--zlib-segment`. That is accurate enough, but naming the offending flag would help users. - nit: the guard sits inside the `try`, so it runs after `parse_args` but before any file open. That is what the PR says, and the tests confirm it. No Windows run needed: pure Python, no shader or C++ change. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:48 +00:00
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!2326
No description provided.