hle: reject null tiling out when the count is nonzero #3170

Open
cloph-dsp wants to merge 1 commit from upstream-pr/3172 into main
cloph-dsp commented 2026-11-26 10:57:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T10:57:06Z.


Depends on: #1633 (claim XG-NULL-OUT-COUNT).

XGTextureAddressComputer::GetResourceTiling dereferenced out for every requested subresource while only the count pointer was checked. A caller asking for a nonzero count with a null out therefore faulted. The function now rejects that combination with E_INVALIDARG before writing any output.

Test: modules::xg::tests::tiling_rejects_null_out_when_count_nonzero uses a synthetic texture computer and a null out pointer.

Validation (Windows, Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR):

  • cargo test --locked -p victory-hle --lib modules::xg::tests::tiling_rejects_null_out_when_count_nonzero — 1 passed, 0 failed.
  • cargo test --locked -p victory-hle --lib modules::xg:: — 5 passed, 0 failed.
  • git diff --check — clean.

AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5508732868 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3172). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T10:57:06Z. --- Depends on: #1633 (claim `XG-NULL-OUT-COUNT`). `XGTextureAddressComputer::GetResourceTiling` dereferenced `out` for every requested subresource while only the count pointer was checked. A caller asking for a nonzero count with a null `out` therefore faulted. The function now rejects that combination with `E_INVALIDARG` before writing any output. Test: `modules::xg::tests::tiling_rejects_null_out_when_count_nonzero` uses a synthetic texture computer and a null `out` pointer. Validation (Windows, Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`): - `cargo test --locked -p victory-hle --lib modules::xg::tests::tiling_rejects_null_out_when_count_nonzero` — 1 passed, 0 failed. - `cargo test --locked -p victory-hle --lib modules::xg::` — 5 passed, 0 failed. - `git diff --check` — clean. AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.
AurumCarlos commented 2026-11-26 12:12:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T12:12:19Z.

Review: COMMENTED


The crash is real and the guard fixes it: on main, out.add(i).write(..) runs on a null out as soon as wanted > 0. Returning before any output is written also matches what the description says. Two remarks:

1. The guard is broader than the writes it protects. It rejects *count > 0, but the loop only writes when wanted = (standard * slices).saturating_sub(first).min(*n) is nonzero. Calls that never touched out on main now fail with E_INVALIDARG where they used to return S_OK and set *count = 0. That covers a first past the last standard subresource, and a texture that is all mip tail (standard == 0). If the console's XG really rejects any null out with a nonzero count, then this is the right behaviour, but the PR doesn't say where that comes from. If it isn't known, checking wanted > 0 instead (moving the check after wanted is computed, but before anything is written) would fix the crash without changing any call that works today.

2. The test only covers the rejected case. The title says "when the count is nonzero", so it would be worth pinning the cases that must still succeed with a null out:

  • *count == 0 → S_OK, *count stays 0;
  • a null count → S_OK, with tiles/packed/shape still filled in.

It might also be worth asserting that tiles/packed/shape are left untouched after the E_INVALIDARG, since "before writing any output" is part of the stated behaviour.

<!-- greyfinch-sync:Marvisak/VIctory:review:6073922113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3172#pullrequestreview-6073922113). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T12:12:19Z. **Review:** COMMENTED --- The crash is real and the guard fixes it: on `main`, `out.add(i).write(..)` runs on a null `out` as soon as `wanted > 0`. Returning before any output is written also matches what the description says. Two remarks: **1. The guard is broader than the writes it protects.** It rejects `*count > 0`, but the loop only writes when `wanted = (standard * slices).saturating_sub(first).min(*n)` is nonzero. Calls that never touched `out` on `main` now fail with `E_INVALIDARG` where they used to return `S_OK` and set `*count = 0`. That covers a `first` past the last standard subresource, and a texture that is all mip tail (`standard == 0`). If the console's XG really rejects any null `out` with a nonzero count, then this is the right behaviour, but the PR doesn't say where that comes from. If it isn't known, checking `wanted > 0` instead (moving the check after `wanted` is computed, but before anything is written) would fix the crash without changing any call that works today. **2. The test only covers the rejected case.** The title says "when the count is nonzero", so it would be worth pinning the cases that must still succeed with a null `out`: - `*count == 0` → `S_OK`, `*count` stays 0; - a null `count` → `S_OK`, with `tiles`/`packed`/`shape` still filled in. It might also be worth asserting that `tiles`/`packed`/`shape` are left untouched after the `E_INVALIDARG`, since "before writing any output" is part of the stated behaviour.
Jackster commented 2026-11-26 23:02:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:15Z.


Windows 11, 63bcca4 + this PR:

  • cargo test -p victory-hle: lib 153 passed / 0 failed (unpatched 63bcca4 here: 152), plus the integration suite (1 passed).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.

tiling_rejects_null_out_when_count_nonzero passes. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205198674 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3172#issuecomment-7205198674). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:15Z. --- Windows 11, `63bcca4` + this PR: - `cargo test -p victory-hle`: lib 153 passed / 0 failed (unpatched `63bcca4` here: 152), plus the integration suite (1 passed). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. `tiling_rejects_null_out_when_count_nonzero` passes. Synthetic only. AI-assisted.
fuzeofficlal commented 2026-11-26 23:55:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:55:11Z.

Review: APPROVED


LGTM — verified rustfmt on the touched lines, cargo xtask policy, cargo clippy (--all-targets and --all-features), and cargo test -p victory-hle --lib modules::xg:: (all 5 tests pass, including tiling_rejects_null_out_when_count_nonzero). Returning E_INVALIDARG matches all sibling pointer checks in crates/victory-hle/src/modules/xg.rs, and the count == 0 with null out path continues to return S_OK without touching out.

Two small non-blocking suggestions for consideration:

  • Snapshot *count before writing *tiles (xg.rs:498-539): reading count.as_ref().copied() once before writing *tiles / *packed / *shape avoids creating an early &mut reference and prevents a null write if a caller aliases tiles and count starting at 0 with a null out.
  • Zero-count regression test (xg.rs:778): adding a test case verifying that count == 0 with out == null succeeds with S_OK on a supported 64 KiB layout would lock down both halves of the contract.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081739592 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3172#pullrequestreview-6081739592). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:55:11Z. **Review:** APPROVED --- LGTM — verified `rustfmt` on the touched lines, `cargo xtask policy`, `cargo clippy` (`--all-targets` and `--all-features`), and `cargo test -p victory-hle --lib modules::xg::` (all 5 tests pass, including `tiling_rejects_null_out_when_count_nonzero`). Returning `E_INVALIDARG` matches all sibling pointer checks in `crates/victory-hle/src/modules/xg.rs`, and the `count == 0` with null `out` path continues to return `S_OK` without touching `out`. Two small non-blocking suggestions for consideration: - **Snapshot `*count` before writing `*tiles` (`xg.rs:498-539`)**: reading `count.as_ref().copied()` once before writing `*tiles` / `*packed` / `*shape` avoids creating an early `&mut` reference and prevents a null write if a caller aliases `tiles` and `count` starting at `0` with a null `out`. - **Zero-count regression test (`xg.rs:778`)**: adding a test case verifying that `count == 0` with `out == null` succeeds with `S_OK` on a supported 64 KiB layout would lock down both halves of the contract.
futurepro62 commented 2026-11-27 12:12:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T12:12:10Z.


NVIDIA full-suite run, to go with the reports above by Jackster, since none of them names a GPU run. Tested exact head 7b10327 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: tiling_rejects_null_out_when_count_nonzero.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7217959143 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3172#issuecomment-7217959143). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T12:12:10Z. --- NVIDIA full-suite run, to go with the reports above by Jackster, since none of them names a GPU run. Tested exact head `7b10327` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `tiling_rejects_null_out_when_count_nonzero`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3172:upstream-pr/3172'
git switch 'upstream-pr/3172'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3172'
git switch 'upstream-pr/3172'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3172'
git switch 'upstream-pr/3172'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3172'
git switch 'main'
git merge --squash 'upstream-pr/3172'
git switch 'main'
git merge --ff-only 'upstream-pr/3172'
git switch 'main'
git merge 'upstream-pr/3172'
git push origin 'main'
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
Marvisak/VIctory!3170
No description provided.