ffx: validate FSPX and PSV0 bounds and add dispatch profile checks #1890

Merged
Ammmae0x merged 1 commit from upstream-pr/1897 into main 2026-11-24 21:17:35 +00:00
Ammmae0x commented 2026-11-24 20:30:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T20:30:01Z.


Change

Harden bounds and structural validation in tools/ffx_dispatch_profile.py and add a synthetic PE64 test suite in tests/ffx_dispatch_profile_check.py, registered in CMakeLists.txt as ffx_dispatch_profile_check:

  • Reject truncated resource descriptor entries (len < 128), truncated RCAS permutation selectors (len != 32), truncated shader containers, and truncated i8 initializers with ValueError instead of failing later with struct.error, UnicodeDecodeError, or short payloads.
  • Validate PSV0 presence and minimum length (>= 52 bytes) and ACCC/FSPX presence, header magic (FSPX), section table bounds (16 + count * 16 <= len(native)), single tag-6 code section existence and bounds (offset >= table_end, size > 0x24, offset + size <= len(native)), and single s_endpgm terminator (0xbf810000).
  • Add 10 unittest cases in tests/ffx_dispatch_profile_check.py covering positive extraction/SHA-256 verification and negative controls for scratch/initializer bindings, earlier ID 16 readers, PSV0 thread counts and truncation, FSPX magic/header/section table/bounds/tag-6 presence, missing/duplicate s_endpgm, RCAS selector, ID 16 writers, RCAS bindings, and initializer size.

Verification

Verified on rebased commit bedd5229:

  • ctest --preset dev -E "cpu_native_archive_" -R "^(ffx_dispatch_profile_check|ffx_immediate_float_to_int_warp|ffx_float_to_int_warp|ffx_float_math_warp|ffx_pass26_lds_warp)$" --output-on-failure: 5/5 passed (Total Tests: 1156).
  • ctest --preset release -E "cpu_native_archive_" -R "^(ffx_dispatch_profile_check|ffx_immediate_float_to_int_warp|ffx_float_to_int_warp|ffx_float_math_warp|ffx_pass26_lds_warp)$" --output-on-failure: 5/5 passed (Total Tests: 1156).
  • python -B tests/ffx_dispatch_profile_check.py -v: 10/10 passed.
  • python -B tests/form_coverage_check.py: passed.
  • python -B tests/docs_links_check.py: passed (18 Markdown files, 376 links).
  • python -B tests/bidi_controls_check.py: passed (1332 tracked files).

Evidence and follow-up

All fixtures in tests/ffx_dispatch_profile_check.py are synthetic in-memory PE64 images with synthetic DXBC/PSV0/FSPX payloads. Running the new test suite against unpatched upstream/main:tools/ffx_dispatch_profile.py failed with 3 failures and 4 errors on the newly added bounds-validation cases.

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:6590801919 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1897). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T20:30:01Z. --- ## Change Harden bounds and structural validation in `tools/ffx_dispatch_profile.py` and add a synthetic PE64 test suite in `tests/ffx_dispatch_profile_check.py`, registered in `CMakeLists.txt` as `ffx_dispatch_profile_check`: - Reject truncated resource descriptor entries (`len < 128`), truncated RCAS permutation selectors (`len != 32`), truncated shader containers, and truncated `i8` initializers with `ValueError` instead of failing later with `struct.error`, `UnicodeDecodeError`, or short payloads. - Validate `PSV0` presence and minimum length (`>= 52` bytes) and `ACCC`/`FSPX` presence, header magic (`FSPX`), section table bounds (`16 + count * 16 <= len(native)`), single tag-6 code section existence and bounds (`offset >= table_end`, `size > 0x24`, `offset + size <= len(native)`), and single `s_endpgm` terminator (`0xbf810000`). - Add 10 unittest cases in `tests/ffx_dispatch_profile_check.py` covering positive extraction/SHA-256 verification and negative controls for scratch/initializer bindings, earlier ID 16 readers, PSV0 thread counts and truncation, FSPX magic/header/section table/bounds/tag-6 presence, missing/duplicate `s_endpgm`, RCAS selector, ID 16 writers, RCAS bindings, and initializer size. ## Verification Verified on rebased commit `bedd5229`: - `ctest --preset dev -E "cpu_native_archive_" -R "^(ffx_dispatch_profile_check|ffx_immediate_float_to_int_warp|ffx_float_to_int_warp|ffx_float_math_warp|ffx_pass26_lds_warp)$" --output-on-failure`: 5/5 passed (Total Tests: 1156). - `ctest --preset release -E "cpu_native_archive_" -R "^(ffx_dispatch_profile_check|ffx_immediate_float_to_int_warp|ffx_float_to_int_warp|ffx_float_math_warp|ffx_pass26_lds_warp)$" --output-on-failure`: 5/5 passed (Total Tests: 1156). - `python -B tests/ffx_dispatch_profile_check.py -v`: 10/10 passed. - `python -B tests/form_coverage_check.py`: passed. - `python -B tests/docs_links_check.py`: passed (18 Markdown files, 376 links). - `python -B tests/bidi_controls_check.py`: passed (1332 tracked files). ## Evidence and follow-up All fixtures in `tests/ffx_dispatch_profile_check.py` are synthetic in-memory PE64 images with synthetic DXBC/PSV0/FSPX payloads. Running the new test suite against unpatched `upstream/main:tools/ffx_dispatch_profile.py` failed with 3 failures and 4 errors on the newly added bounds-validation cases. ## 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. - [ ] 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.
tedin7 commented 2026-11-24 21:01:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:00:22Z.

Review: COMMENTED


Review of exact head bedd522954466ffd3a4cf4e368c18053398cea6b (merge-base with main 8a03d2ad; main is now 94dbdbf0, git merge-tree --write-tree origin/main HEAD merges cleanly). Comment only, no approval.

What I checked

  • Title/scope: neutral, one reviewable behavior (hardening of an offline Python tool + its synthetic test). Fixtures are in-memory synthetic PE64/DXBC/PSV0/FSPX built from the tool's own constants; no game bytes, dumps or links. Nothing clean-room related found.
  • Logic read line by line (tools/ffx_dispatch_profile.py): the new bounds checks are correct, no off-by-one or signedness problem found (Python ints, offset + size > len(native) and table_end > len(native) are the right inclusive limits; the valid-equal case is accepted).

Commands run locally (all at bedd5229)

  • git diff --check origin/main...HEAD: exit 0
  • python -B tests/ffx_dispatch_profile_check.py -v: 10/10 OK
  • python -B tests/docs_links_check.py: 18 Markdown files, 376 links OK
  • python -B tests/bidi_controls_check.py: 1332 files OK
  • python -B tests/form_coverage_check.py: passed
  • Same new test file against origin/main:tools/ffx_dispatch_profile.py: FAILED (failures=3, errors=4), so the PR's claim about the unpatched tool is reproduced.
  • x2w_pipe.py win2025 1897 --regex '^ffx_dispatch_profile_check$': Windows Server 2025 Debug (dev) 1/1 passed and Release /O2 1/1 passed.

Mutations (each applied to the tool, test file re-run, then reverted)

Killed by the tests:

  • offset + size > len(native) -> >=: FAILED (failures=3, errors=1)

Survived (tests still 10/10 OK):

  • M1 delete the len(entry) < 128 check (tools/ffx_dispatch_profile.py:46-48)
  • M2 delete the len(selector) != 32 check (:74-76)
  • M3 delete the len(container) != container_size check (:88-90)
  • M4 delete the len(init_data) != 0x20000 check (:123-125)
  • M5 delete offset < table_end from the bounds condition (:109)
  • M6 len(matches) != 1 -> < 1 (duplicate tag-6 sections accepted, :106)
  • M7 table_end > len -> >= (:102), M8 len(psv0) < 52 -> < 51 (:93), M9 len(native) < 16 -> < 12 (:98)

Findings

P2 - several new guards have no test that can fail (tests/ffx_dispatch_profile_check.py). The description says the change rejects truncated resource descriptors, truncated RCAS selector, truncated shader containers and truncated i8 initializers and that every new fixture has a negative control, but no test reaches those four branches (M1-M4 survive).

  • test_unexpected_rcas_permutation_selector_refused (line 287) flips a value to 1; it never shortens the selector, so it only exercises the old value check.
  • test_unexpected_writer_rcas_bindings_and_initializer_refused (line 304-307) changes the size immediate to 0x10000, which hits the older Unexpected i8 initializer check, not the new Truncated i8 initializer check.
  • The tag-6 bounds test uses offset == table_end (32), so the new offset < table_end condition is never the one that fires (M5); no fixture has two tag-6 sections (M6).
  • Suggestion: build the synthetic PE so the last section ends early (or place the descriptor / selector / initializer RVA at the end of .rdata) and add one case each; add one tag-6 duplicate and one offset < table_end section. Each should fail when its guard is removed.

Nit - len(psv0) < 52 / len(native) < 16 boundaries are only tested at 44 and 8 bytes (M7-M9); exact-boundary lengths 51 and 15 would pin them.

No P1 found. The production change itself looks right to me; the gap is that the test suite proves only the FSPX/PSV0/s_endpgm half of what the description claims.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047322554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1897#pullrequestreview-6047322554). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:00:22Z. **Review:** COMMENTED --- Review of exact head `bedd522954466ffd3a4cf4e368c18053398cea6b` (merge-base with main `8a03d2ad`; main is now `94dbdbf0`, `git merge-tree --write-tree origin/main HEAD` merges cleanly). Comment only, no approval. ## What I checked - Title/scope: neutral, one reviewable behavior (hardening of an offline Python tool + its synthetic test). Fixtures are in-memory synthetic PE64/DXBC/PSV0/FSPX built from the tool's own constants; no game bytes, dumps or links. Nothing clean-room related found. - Logic read line by line (`tools/ffx_dispatch_profile.py`): the new bounds checks are correct, no off-by-one or signedness problem found (Python ints, `offset + size > len(native)` and `table_end > len(native)` are the right inclusive limits; the valid-equal case is accepted). ## Commands run locally (all at bedd5229) - `git diff --check origin/main...HEAD`: exit 0 - `python -B tests/ffx_dispatch_profile_check.py -v`: 10/10 OK - `python -B tests/docs_links_check.py`: 18 Markdown files, 376 links OK - `python -B tests/bidi_controls_check.py`: 1332 files OK - `python -B tests/form_coverage_check.py`: passed - Same new test file against `origin/main:tools/ffx_dispatch_profile.py`: `FAILED (failures=3, errors=4)`, so the PR's claim about the unpatched tool is reproduced. - `x2w_pipe.py win2025 1897 --regex '^ffx_dispatch_profile_check$'`: Windows Server 2025 Debug (`dev`) 1/1 passed and Release `/O2` 1/1 passed. ## Mutations (each applied to the tool, test file re-run, then reverted) Killed by the tests: - `offset + size > len(native)` -> `>=`: FAILED (failures=3, errors=1) Survived (tests still 10/10 OK): - M1 delete the `len(entry) < 128` check (`tools/ffx_dispatch_profile.py:46-48`) - M2 delete the `len(selector) != 32` check (`:74-76`) - M3 delete the `len(container) != container_size` check (`:88-90`) - M4 delete the `len(init_data) != 0x20000` check (`:123-125`) - M5 delete `offset < table_end` from the bounds condition (`:109`) - M6 `len(matches) != 1` -> `< 1` (duplicate tag-6 sections accepted, `:106`) - M7 `table_end > len` -> `>=` (`:102`), M8 `len(psv0) < 52` -> `< 51` (`:93`), M9 `len(native) < 16` -> `< 12` (`:98`) ## Findings **P2 - several new guards have no test that can fail** (`tests/ffx_dispatch_profile_check.py`). The description says the change rejects truncated resource descriptors, truncated RCAS selector, truncated shader containers and truncated `i8` initializers and that every new fixture has a negative control, but no test reaches those four branches (M1-M4 survive). - `test_unexpected_rcas_permutation_selector_refused` (line 287) flips a value to 1; it never shortens the selector, so it only exercises the old value check. - `test_unexpected_writer_rcas_bindings_and_initializer_refused` (line 304-307) changes the size immediate to 0x10000, which hits the older `Unexpected i8 initializer` check, not the new `Truncated i8 initializer` check. - The tag-6 bounds test uses `offset == table_end` (32), so the new `offset < table_end` condition is never the one that fires (M5); no fixture has two tag-6 sections (M6). - Suggestion: build the synthetic PE so the last section ends early (or place the descriptor / selector / initializer RVA at the end of `.rdata`) and add one case each; add one tag-6 duplicate and one `offset < table_end` section. Each should fail when its guard is removed. **Nit** - `len(psv0) < 52` / `len(native) < 16` boundaries are only tested at 44 and 8 bytes (M7-M9); exact-boundary lengths 51 and 15 would pin them. No P1 found. The production change itself looks right to me; the gap is that the test suite proves only the FSPX/PSV0/s_endpgm half of what the description claims. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:27:28 +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!1890
No description provided.