HLE XG: reject null output buffer when *count > 0 in GetResourceTiling #3072

Closed
github-bot wants to merge 2 commits from github-bot/gh-3072 into main AGit
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 06:26 UTC · original
Dukestar69:fix/xg-tiling-null-out → main · +78 −3 · 1 files · 2 commits · closed without merging

Summary

Guards against a null-pointer dereference in XGTextureAddressComputer::GetResourceTiling (tiling, vtable slot 0x50) when a caller passes a non-null count with *count > 0 and a null out buffer, returning E_INVALIDARG before writing any output parameters.

Why

In crates/victory-hle/src/modules/xg.rs, tiling checked every other optional output pointer (tiles, packed, shape, count) via .as_mut(), but never checked out: *mut SubresourceTiling for null. On any 64 KiB tiled texture with at least one standard mip, passing *count > 0 with out == null executed out.add(i as usize).write(entry) through a null pointer (access violation / UB). Passing *count == 0 with out == null remains accepted (S_OK, writing 0 entries).

Verification

  • Added unit test modules::xg::tests::tiling_rejects_null_out_when_count_nonzero verifying:
    • *count > 0 with out == null returns E_INVALIDARG without mutating tiles or count.
    • *count == 0 with out == null returns S_OK and still fills tiles.
  • cargo test -p victory-hle xg::tests: 5 passed, 0 failed.
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 06:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072) `Dukestar69:fix/xg-tiling-null-out` → `main` · +78 −3 · 1 files · 2 commits · closed without merging ## Summary Guards against a null-pointer dereference in `XGTextureAddressComputer::GetResourceTiling` (`tiling`, vtable slot `0x50`) when a caller passes a non-null `count` with `*count > 0` and a null `out` buffer, returning `E_INVALIDARG` before writing any output parameters. ### Why In `crates/victory-hle/src/modules/xg.rs`, `tiling` checked every other optional output pointer (`tiles`, `packed`, `shape`, `count`) via `.as_mut()`, but never checked `out: *mut SubresourceTiling` for null. On any 64 KiB tiled texture with at least one standard mip, passing `*count > 0` with `out == null` executed `out.add(i as usize).write(entry)` through a null pointer (access violation / UB). Passing `*count == 0` with `out == null` remains accepted (`S_OK`, writing 0 entries). ### Verification - Added unit test `modules::xg::tests::tiling_rejects_null_out_when_count_nonzero` verifying: - `*count > 0` with `out == null` returns `E_INVALIDARG` without mutating `tiles` or `count`. - `*count == 0` with `out == null` returns `S_OK` and still fills `tiles`. - `cargo test -p victory-hle xg::tests`: 5 passed, 0 failed. - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:28:06 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 06:32 UTC · original · approved these changes

Verified: *count>0 + null out -> E_INVALIDARG before any output write (tiles/count untouched, asserted); *count==0 + null out stays valid and returns S_OK with 0 entries. Matches XG semantics.

**@⁠kotekompotek** on GitHub · 2026-11-26 06:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072#pullrequestreview-6069537051) · **approved these changes** Verified: *count>0 + null out -> E_INVALIDARG before any output write (tiles/count untouched, asserted); *count==0 + null out stays valid and returns S_OK with 0 entries. Matches XG semantics.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:03 UTC · original · requested changes

Tested locally on Windows 11 x64 (rustc 1.98.1):

  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.
  • cargo test -p victory-hle --locked: 153 lib + 1 fidelityfx + 1 no_dll_planting passed, 0 failed.

One aliasing edge case remains in tiling (crates/victory-hle/src/modules/xg.rs:487-537):

  • The entry guard reads *count to decide whether out.is_null() is allowed, then if let Some(t) = tiles.as_mut() writes *t = (l.size / TILE) as u32 (e.g. 2 for the existing BC7 fixture), and finally the loop re-reads *count to compute wanted = (standard * slices).saturating_sub(first).min(*n).
  • If a caller aliases tiles and count to the same initially zero u32 while passing out == null, the entry check sees 0 and passes, writing *tiles mutates *count to a nonzero tile count, and the loop then writes through a null out.

Reading the input capacity from *count once into a local variable before writing any output parameters—and using that saved capacity for both the null-out check and wanted—closes this cleanly. Please also add a unit test covering the aliased tiles == count zero-capacity case.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072#pullrequestreview-6070406716) · **requested changes** Tested locally on Windows 11 x64 (`rustc 1.98.1`): - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean. - `cargo test -p victory-hle --locked`: 153 lib + 1 fidelityfx + 1 no_dll_planting passed, 0 failed. One aliasing edge case remains in `tiling` (`crates/victory-hle/src/modules/xg.rs:487-537`): - The entry guard reads `*count` to decide whether `out.is_null()` is allowed, then `if let Some(t) = tiles.as_mut()` writes `*t = (l.size / TILE) as u32` (e.g. `2` for the existing BC7 fixture), and finally the loop re-reads `*count` to compute `wanted = (standard * slices).saturating_sub(first).min(*n)`. - If a caller aliases `tiles` and `count` to the same initially zero `u32` while passing `out == null`, the entry check sees `0` and passes, writing `*tiles` mutates `*count` to a nonzero tile count, and the loop then writes through a null `out`. Reading the input capacity from `*count` once into a local variable before writing any output parameters—and using that saved capacity for both the null-`out` check and `wanted`—closes this cleanly. Please also add a unit test covering the aliased `tiles == count` zero-capacity case.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:19 UTC · original

Good catch @⁠fuzeofficlal, thanks! Fixed in 0d546b2:

  • Read capacity from *count once up front before writing any output pointers, and use that saved capacity for both the null-out guard and wanted.
  • Added the aliased tiles == count zero-capacity with null out regression check to tiling_rejects_null_out_when_count_nonzero.
  • Re-verified cargo test -p victory-hle --locked (153 lib + 2 integration passed), cargo clippy -p victory-hle --all-targets --locked -- -D warnings (clean), and cargo xtask policy (191 files ok).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072#issuecomment-7186454051) Good catch @⁠fuzeofficlal, thanks! Fixed in `0d546b2`: - Read `capacity` from `*count` once up front before writing any output pointers, and use that saved `capacity` for both the null-`out` guard and `wanted`. - Added the aliased `tiles == count` zero-capacity with null `out` regression check to `tiling_rejects_null_out_when_count_nonzero`. - Re-verified `cargo test -p victory-hle --locked` (153 lib + 2 integration passed), `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (clean), and `cargo xtask policy` (191 files ok). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:23 UTC · original

Automated triage for the maintainers.

Verdict: proposed close. The new check in tiling (modules/xg.rs, slot 0x50) guards against a caller passing room for *count > 0 entries with a null out. That breaks the method's own contract, and there's no sign the title does it. The module states its stance at the top: "Title code passes pointers the real library would trust", and tiling's SAFETY comment says out has room for *count entries.

The PR also picks E_INVALIDARG as the console library's answer with no evidence of what the library returns. A guard for an impossible case with an invented return value isn't something the repo takes.

What would change this: evidence that the title (or another real caller) makes this call, and of what the console library returns for it.

CI: not run on this head.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072#issuecomment-7186536467) <!-- victory-triage v1 head=65cc5ef47886393d98ea44dc060a83a50d26504e verdict=proposed-close at=2026-11-26T08:18:50Z --> Automated triage for the maintainers. **Verdict: proposed close.** The new check in `tiling` (`modules/xg.rs`, slot 0x50) guards against a caller passing room for `*count > 0` entries with a null `out`. That breaks the method's own contract, and there's no sign the title does it. The module states its stance at the top: "Title code passes pointers the real library would trust", and `tiling`'s SAFETY comment says `out` has room for `*count` entries. The PR also picks `E_INVALIDARG` as the console library's answer with no evidence of what the library returns. A guard for an impossible case with an invented return value isn't something the repo takes. What would change this: evidence that the title (or another real caller) makes this call, and of what the console library returns for it. CI: not run on this head. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 11:09:46 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 09:31 UTC · original

Closing per triage feedback: modules/xg.rs intentionally trusts caller contracts and there is no evidence of a title passing *count > 0 with out == null. Thanks for the review! Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 09:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3072#issuecomment-7188117068) Closing per triage feedback: `modules/xg.rs` intentionally trusts caller contracts and there is no evidence of a title passing `*count > 0` with `out == null`. Thanks for the review! Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Pull request closed

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!3072
No description provided.