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

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

@⁠cloph-dsp on GitHub · 2026-11-26 10:57 UTC · original
cloph-dsp:fix/xg-null-out-count → main · +39 −1 · 1 files · 1 commits · open

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.

**@⁠cloph-dsp** on GitHub · 2026-11-26 10:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/3172) `cloph-dsp:fix/xg-null-out-count` → `main` · +39 −1 · 1 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:27 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 12:12 UTC · original · reviewed

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.

**@⁠AurumCarlos** on GitHub · 2026-11-26 12:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/3172#pullrequestreview-6073922113) · **reviewed** 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.
This pull request can be merged automatically.
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/3172/head:github-bot/gh-3172'
git switch 'github-bot/gh-3172'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3172'
git switch 'github-bot/gh-3172'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3172'
git switch 'github-bot/gh-3172'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3172'
git switch 'main'
git merge --squash 'github-bot/gh-3172'
git switch 'main'
git merge --ff-only 'github-bot/gh-3172'
git switch 'main'
git merge 'github-bot/gh-3172'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3172
No description provided.