fix: guard runtime method tables past their last slot #257

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

@⁠Skyfrye on GitHub · 2026-11-25 21:57 UTC · original
Skyfrye:nep/runtime-table-bounds → main · +173 −29 · 14 files · 1 commits · draft

Draft: the in-game check on this base is pending (the test machine's GPU is in use for a few hours). Everything else below is done.

Change

The runtime objects VIctory hands to the title (the QueryApiImpl areas and the DirectStorage objects) each point at a fixed-length array holding the methods implemented so far (Methods<N> in victory-hle/src/modules/xgameruntime.rs). Nothing came after the array. A title that calls a method past the last slot we list (a newer runtime interface, or a method we have not met yet) read a function address from whatever memory followed the table and jumped there: a crash far from its cause, with nothing in the log to name the area or the slot.

Every table built through Methods::new now carries 64 more slots after its known methods. Each is a stub that logs runtime method not implemented (past the end of its table) with the area and the slot offset at WARN, once per area and slot, and returns E_NOTIMPL. The stub takes only this, so any argument list is safe to pass under the x64 convention (the caller cleans up). Existing slots are unchanged, and missing::<SLOT> keeps answering for the unimplemented slots inside a table.

Why 64: the runtime's interfaces are not public, so their real method counts are unknown; 64 slots is 512 bytes of static data per table (26 tables in 14 modules).

Not covered here (other table types, each its own change if wanted): GameInput's Table<N>, the XG Vtable, the media and audio structs, and the D3D tables in victory-gpu.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), builds and tests at below-normal priority, RTX 5080, on upstream main at affaf15 (the Neptune base, PR #243), from third_party/victory.

cargo test --locked -p victory-hle   -> main: 110 passed (+1 integration); this branch: 113 passed, 0 failed (+1)
cargo build --locked --release -p victory                              -> Finished, no new warning (the 3 of main)
cargo build --locked --profile diag -p victory --features diagnostics  -> Finished, no new warning
cargo xtask policy                                                     -> asset policy: 197 files ok

With the 64 slots left null and the tests kept, both every_*_guarded tests fail (the third test, a call into slot 4, is not run that way: it would jump through null).

In game: pending on this base. On the previous base (4f2cf5c), two runs of 240 s and 300 s to the prologue's first interior (GTA VI 1.0.2.1, my own copy, launcher settings) with this and three other local fixes: no exception, no device loss, and the new WARN line never appeared (the title did not call past a table there).

Oracle and test data

None involved. Failure case: a_call_past_the_end_returns_e_notimpl_and_is_logged_once calls slot 4 of a 4-slot table, and every_area_table_is_guarded_past_its_methods (plus the DirectStorage one) calls all 64 slots past every served table with five arguments. Without the change the tests do not compile (they use Methods::new); what they exercise is, before the change, a jump through unrelated memory, which a test cannot assert safely.

Checklist

  • The PR covers a single reviewable behaviour (a call past the end of a runtime method table).
  • A test fails without this change and passes with it. — Does not compile without it, see above.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (the title was not seen calling past a table).
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Opus 5.5 wrote the change and its tests from a review of the HLE modules; Claude Fable 5.2 reviewed the diff and ran it in game on the previous base; Claude Sonnet 5.5 ported it to the Neptune base and ran the checks there; Claude Opus 5.5 reviewed the port, ran the game on my machine and wrote this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/257) `Skyfrye:nep/runtime-table-bounds` → `main` · +173 −29 · 14 files · 1 commits · draft **Draft: the in-game check on this base is pending** (the test machine's GPU is in use for a few hours). Everything else below is done. ## Change The runtime objects VIctory hands to the title (the `QueryApiImpl` areas and the DirectStorage objects) each point at a fixed-length array holding the methods implemented so far (`Methods<N>` in `victory-hle/src/modules/xgameruntime.rs`). Nothing came after the array. A title that calls a method past the last slot we list (a newer runtime interface, or a method we have not met yet) read a function address from whatever memory followed the table and jumped there: a crash far from its cause, with nothing in the log to name the area or the slot. Every table built through `Methods::new` now carries 64 more slots after its known methods. Each is a stub that logs `runtime method not implemented (past the end of its table)` with the area and the slot offset at WARN, once per area and slot, and returns `E_NOTIMPL`. The stub takes only `this`, so any argument list is safe to pass under the x64 convention (the caller cleans up). Existing slots are unchanged, and `missing::<SLOT>` keeps answering for the unimplemented slots inside a table. Why 64: the runtime's interfaces are not public, so their real method counts are unknown; 64 slots is 512 bytes of static data per table (26 tables in 14 modules). Not covered here (other table types, each its own change if wanted): GameInput's `Table<N>`, the XG `Vtable`, the media and audio structs, and the D3D tables in `victory-gpu`. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), builds and tests at below-normal priority, RTX 5080, on upstream `main` at `affaf15` (the Neptune base, PR #243), from `third_party/victory`. ``` cargo test --locked -p victory-hle -> main: 110 passed (+1 integration); this branch: 113 passed, 0 failed (+1) cargo build --locked --release -p victory -> Finished, no new warning (the 3 of main) cargo build --locked --profile diag -p victory --features diagnostics -> Finished, no new warning cargo xtask policy -> asset policy: 197 files ok ``` With the 64 slots left null and the tests kept, both `every_*_guarded` tests fail (the third test, a call into slot 4, is not run that way: it would jump through null). In game: pending on this base. On the previous base (`4f2cf5c`), two runs of 240 s and 300 s to the prologue's first interior (GTA VI 1.0.2.1, my own copy, launcher settings) with this and three other local fixes: no exception, no device loss, and the new WARN line never appeared (the title did not call past a table there). ## Oracle and test data None involved. Failure case: `a_call_past_the_end_returns_e_notimpl_and_is_logged_once` calls slot 4 of a 4-slot table, and `every_area_table_is_guarded_past_its_methods` (plus the DirectStorage one) calls all 64 slots past every served table with five arguments. Without the change the tests do not compile (they use `Methods::new`); what they exercise is, before the change, a jump through unrelated memory, which a test cannot assert safely. ## Checklist - [x] The PR covers a single reviewable behaviour (a call past the end of a runtime method table). - [x] A test fails without this change and passes with it. — Does not compile without it, see above. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (the title was not seen calling past a table). - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Opus 5.5 wrote the change and its tests from a review of the HLE modules; Claude Fable 5.2 reviewed the diff and ran it in game on the previous base; Claude Sonnet 5.5 ported it to the Neptune base and ran the checks there; Claude Opus 5.5 reviewed the port, ran the game on my machine and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The runtime objects handed to the title (QueryApiImpl areas and the
DirectStorage objects) pointed at fixed-length arrays of the methods
implemented so far. A title calling a method past the end of an array
read a function address from whatever memory followed it and jumped
there: a crash far from the cause, with nothing in the log.

Every table built through Methods::new now carries 64 more slots after
its known methods (the runtime's interfaces are not public, so their real
method counts are unknown). Each such slot is a stub that takes no
arguments, so any argument list is safe under the x64 convention; it
logs "runtime method not implemented (past the end of its table)" with
the area and slot offset at WARN, once per area and slot, and returns
E_NOTIMPL. Existing slots are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:43 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 00:06 UTC · original

Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.

**@⁠LooperSalty** on GitHub · 2026-11-26 00:06 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/257#issuecomment-7178410646) Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

Test report for #257.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11 on the RTX 4060 Laptop machine. cargo test --locked -p victory-hle (CPU only, so I did not repeat it per adapter).

victory-hle main main + #257
unit 110 passed 113 passed
no_dll_planting 1 passed 1 passed

No failure. The three new tests pass.

Notes from reading the diff:

  • Object is #[repr(C)] and gets a third field. The DirectStorage instances (File, StatusArray, Queue) start with that header, so their state moves 8 bytes. That is fine while only our code reads past the header. I found nothing that hands a fixed header size to the title.
  • The PAST_END table has 160 entries, so N + 64 <= 160 caps a table at 96 known methods. The const assert catches this at compile time. The message could name the limit ("raise PAST_END rows past 96 methods").
  • past_end derefs this to get area. If a title ever calls a stub with an object we did not create (a wrong pointer), this reads through it. That is no worse than before, but the stub could log this as well.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/257#issuecomment-7189495902) Test report for #257. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11 on the RTX 4060 Laptop machine. `cargo test --locked -p victory-hle` (CPU only, so I did not repeat it per adapter). | `victory-hle` | main | main + #257 | |---|---|---| | unit | 110 passed | 113 passed | | `no_dll_planting` | 1 passed | 1 passed | No failure. The three new tests pass. Notes from reading the diff: - `Object` is `#[repr(C)]` and gets a third field. The DirectStorage instances (`File`, `StatusArray`, `Queue`) start with that header, so their state moves 8 bytes. That is fine while only our code reads past the header. I found nothing that hands a fixed header size to the title. - The `PAST_END` table has 160 entries, so `N + 64 <= 160` caps a table at 96 known methods. The `const` assert catches this at compile time. The message could name the limit ("raise PAST_END rows past 96 methods"). - `past_end` derefs `this` to get `area`. If a title ever calls a stub with an object we did not create (a wrong pointer), this reads through it. That is no worse than before, but the stub could log `this` as well. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-hle/src/modules/xasync.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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