ffx: validate FSPX and PSV0 bounds and add dispatch profile checks #1890
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1897"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.pyand add a synthetic PE64 test suite intests/ffx_dispatch_profile_check.py, registered inCMakeLists.txtasffx_dispatch_profile_check:len < 128), truncated RCAS permutation selectors (len != 32), truncated shader containers, and truncatedi8initializers withValueErrorinstead of failing later withstruct.error,UnicodeDecodeError, or short payloads.PSV0presence and minimum length (>= 52bytes) andACCC/FSPXpresence, 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 singles_endpgmterminator (0xbf810000).tests/ffx_dispatch_profile_check.pycovering 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/duplicates_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.pyare synthetic in-memory PE64 images with synthetic DXBC/PSV0/FSPX payloads. Running the new test suite against unpatchedupstream/main:tools/ffx_dispatch_profile.pyfailed with 3 failures and 4 errors on the newly added bounds-validation cases.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:00:22Z.
Review: COMMENTED
Review of exact head
bedd522954466ffd3a4cf4e368c18053398cea6b(merge-base with main8a03d2ad; main is now94dbdbf0,git merge-tree --write-tree origin/main HEADmerges cleanly). Comment only, no approval.What I checked
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)andtable_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 0python -B tests/ffx_dispatch_profile_check.py -v: 10/10 OKpython -B tests/docs_links_check.py: 18 Markdown files, 376 links OKpython -B tests/bidi_controls_check.py: 1332 files OKpython -B tests/form_coverage_check.py: passedorigin/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/O21/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):
len(entry) < 128check (tools/ffx_dispatch_profile.py:46-48)len(selector) != 32check (:74-76)len(container) != container_sizecheck (:88-90)len(init_data) != 0x20000check (:123-125)offset < table_endfrom the bounds condition (:109)len(matches) != 1->< 1(duplicate tag-6 sections accepted,:106)table_end > len->>=(:102), M8len(psv0) < 52->< 51(:93), M9len(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 truncatedi8initializers 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 olderUnexpected i8 initializercheck, not the newTruncated i8 initializercheck.offset == table_end(32), so the newoffset < table_endcondition is never the one that fires (M5); no fixture has two tag-6 sections (M6)..rdata) and add one case each; add one tag-6 duplicate and oneoffset < table_endsection. Each should fail when its guard is removed.Nit -
len(psv0) < 52/len(native) < 16boundaries 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.