Shaders/validator+gfx10: guard null IDxcBlob slice UB, check GetStatus HR, and fix ds_wrap/global_addtid fields #630

Open
github-bot wants to merge 1 commit from github-bot/gh-630 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 03:26 UTC · original
AscilCH:fix/shader-validator-null-blob-and-gfx10-fields → main · +97 −4 · 2 files · 1 commits · open

Problem

Two sets of bugs in victory-shader:

  1. Null-pointer slice UB and ignored GetStatus failure in emit/validator.rs:
    • std::slice::from_raw_parts(ptr(errors), len(errors)) passed a raw IDxcBlob::GetBufferPointer() directly to slice::from_raw_parts, which is UB (and panics under Rust debug ub_checks) when an empty IDxcBlob returns (null, 0).
    • The HRESULT returned by IDxcOperationResult::GetStatus was discarded; if GetStatus itself failed, status remained 0 and validate() falsely returned Ok(()).
  2. Incorrect GFX10 operand decoding in gfx10/fields.rs:
    • ds_wrap_rtn_b32 vdst, vaddr, vdata0, vdata1 takes two data VGPRs, but "wrap" was omitted from the 2-data-operand check (fields.rs:303), silently dropping vdata1 from Fields::Ds::data, disassembly, and ir::build register reads.
    • global_load_dword_addtid and global_store_dword_addtid compute addresses from saddr + offset + lane_id * 4 and take no vaddr VGPR, yet Encoding::Global (fields.rs:392) unconditionally decoded addr: Some(v0), fabricating a spurious v0 read in ir::build.

Fix

  • Check get_status(result, &mut status) in crates/victory-shader/src/emit/validator.rs, releasing result and returning Err on failure, and borrow error blob bytes through blob_bytes() guarding p.is_null() || n == 0.
  • Include name.contains("wrap") in the 2-data-operand Encoding::Ds check and guard Encoding::Global addr with !name.contains("addtid") in crates/victory-shader/src/gfx10/fields.rs.
  • Add synthetic unit tests blob_bytes_handles_null_or_empty_without_ub and ds_wrap_rtn_decodes_both_data_operands_and_global_addtid_has_no_vaddr.

Verification

  • cargo test -p victory-shader --locked emit::validator::tests: 1 passed, 0 failed
  • cargo test -p victory-shader --locked gfx10::: 13 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 03:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/630) `AscilCH:fix/shader-validator-null-blob-and-gfx10-fields` → `main` · +97 −4 · 2 files · 1 commits · open ## Problem Two sets of bugs in `victory-shader`: 1. **Null-pointer slice UB and ignored `GetStatus` failure in `emit/validator.rs`**: - `std::slice::from_raw_parts(ptr(errors), len(errors))` passed a raw `IDxcBlob::GetBufferPointer()` directly to `slice::from_raw_parts`, which is UB (and panics under Rust debug `ub_checks`) when an empty `IDxcBlob` returns `(null, 0)`. - The `HRESULT` returned by `IDxcOperationResult::GetStatus` was discarded; if `GetStatus` itself failed, `status` remained `0` and `validate()` falsely returned `Ok(())`. 2. **Incorrect GFX10 operand decoding in `gfx10/fields.rs`**: - `ds_wrap_rtn_b32 vdst, vaddr, vdata0, vdata1` takes two data VGPRs, but `"wrap"` was omitted from the 2-data-operand check (`fields.rs:303`), silently dropping `vdata1` from `Fields::Ds::data`, disassembly, and `ir::build` register reads. - `global_load_dword_addtid` and `global_store_dword_addtid` compute addresses from `saddr + offset + lane_id * 4` and take no `vaddr` VGPR, yet `Encoding::Global` (`fields.rs:392`) unconditionally decoded `addr: Some(v0)`, fabricating a spurious `v0` read in `ir::build`. ## Fix - Check `get_status(result, &mut status)` in `crates/victory-shader/src/emit/validator.rs`, releasing `result` and returning `Err` on failure, and borrow error blob bytes through `blob_bytes()` guarding `p.is_null() || n == 0`. - Include `name.contains("wrap")` in the 2-data-operand `Encoding::Ds` check and guard `Encoding::Global` `addr` with `!name.contains("addtid")` in `crates/victory-shader/src/gfx10/fields.rs`. - Add synthetic unit tests `blob_bytes_handles_null_or_empty_without_ub` and `ds_wrap_rtn_decodes_both_data_operands_and_global_addtid_has_no_vaddr`. ## Verification - `cargo test -p victory-shader --locked emit::validator::tests`: 1 passed, 0 failed - `cargo test -p victory-shader --locked gfx10::`: 13 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
- `emit/validator.rs`: check the `HRESULT` returned by `IDxcOperationResult::GetStatus`
  instead of discarding it (which could silently report invalid DXIL as `Ok(())`),
  and guard `slice::from_raw_parts` via `blob_bytes()` so a null/empty `IDxcBlob`
  buffer never triggers undefined behavior.
- `gfx10/fields.rs`: include `"wrap"` in the 2-data-operand DS check so
  `ds_wrap_rtn_b32` decodes both `vdata0` and `vdata1` (fixing SSA dataflow in
  `ir::build`), and omit `vaddr` on `global_load_dword_addtid` /
  `global_store_dword_addtid` so no bogus `v0` read is fabricated.
- Add synthetic unit tests in `validator.rs` and `gfx10/fields.rs`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:46 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/630/head:github-bot/gh-630'
git switch 'github-bot/gh-630'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-630'
git switch 'github-bot/gh-630'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-630'
git switch 'github-bot/gh-630'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-630'
git switch 'main'
git merge --squash 'github-bot/gh-630'
git switch 'main'
git merge --ff-only 'github-bot/gh-630'
git switch 'main'
git merge 'github-bot/gh-630'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.