Loader: guard null C++ exception pointers in crash::thrown and Rsp overflow/alignment in unwind_into #2554

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

@⁠reeledMarek on GitHub · 2026-11-25 15:40 UTC · original
reeledMarek:fix/loader-crash-thrown-and-unwind → main · +65 −12 · 1 files · 1 commits · open

Problem

  1. In crash::thrown, MSVC C++ rethrows (throw;) pass p[1] == 0 and p[2] == 0, and malformed exception metadata can have zero RVAs or count == 0. thrown unconditionally dereferenced p[2] + 12, name(0), and p[1] + 8, causing a secondary access violation inside the unhandled crash reporter.
  2. In crash::unwind_into, rsp + 8 > high overflowed if a crashing thread corrupted Rsp near u64::MAX, and (rsp as *const u64).read() caused aligned-read UB if Rsp was misaligned.

Fix

  • Validate p.len() >= 4, non-null p[2]/p[3], non-zero RVAs, bounded non-zero catchable type count, non-null p[1] for std::exception, and read_unaligned in thrown.
  • Use rsp.checked_add(8) and read_unaligned in unwind_into.

Testing

  • Added thrown_and_unwind_handle_rethrow_and_corrupted_rsp in crates/victory-loader/src/crash.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2554) `reeledMarek:fix/loader-crash-thrown-and-unwind` → `main` · +65 −12 · 1 files · 1 commits · open ### Problem 1. In `crash::thrown`, MSVC C++ rethrows (`throw;`) pass `p[1] == 0` and `p[2] == 0`, and malformed exception metadata can have zero RVAs or `count == 0`. `thrown` unconditionally dereferenced `p[2] + 12`, `name(0)`, and `p[1] + 8`, causing a secondary access violation inside the unhandled crash reporter. 2. In `crash::unwind_into`, `rsp + 8 > high` overflowed if a crashing thread corrupted `Rsp` near `u64::MAX`, and `(rsp as *const u64).read()` caused aligned-read UB if `Rsp` was misaligned. ### Fix - Validate `p.len() >= 4`, non-null `p[2]`/`p[3]`, non-zero RVAs, bounded non-zero catchable type count, non-null `p[1]` for `std::exception`, and `read_unaligned` in `thrown`. - Use `rsp.checked_add(8)` and `read_unaligned` in `unwind_into`. ### Testing - Added `thrown_and_unwind_handle_rethrow_and_corrupted_rsp` in `crates/victory-loader/src/crash.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:06 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:37 UTC · original

Automated triage for the maintainers.

Hardens the crash reporter in crates/victory-loader/src/crash.rs. thrown now returns "unknown" for a C++ rethrow (throw; raises the MSVC exception with null object/ThrowInfo pointers, and main read p[2] + 12 and faulted inside the reporter). It also returns "unknown" for zero RVAs or an empty type list, and skips the std::exception message when the object pointer is null. unwind_into now uses checked_add for rsp + 8; on main a corrupted Rsp near u64::MAX wrapped past the bounds check. It also reads the return address with read_unaligned, since a misaligned read() is UB and panics in debug builds. I checked the call site (report, which only requires NumberParameters >= 4 and the magic) and the loop exit on Rip == 0. The new test's expectations ([0x1000], [0x2000]) match that code. Reporting only, with no change to emulation behaviour.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2554#issuecomment-7171164680) <!-- victory-triage v1 head=06cebbf704c71ff449fa81be05a90f0157c27b25 verdict=merge-candidate at=2026-11-25T18:37:15Z --> Automated triage for the maintainers. Hardens the crash reporter in `crates/victory-loader/src/crash.rs`. `thrown` now returns "unknown" for a C++ rethrow (`throw;` raises the MSVC exception with null object/ThrowInfo pointers, and `main` read `p[2] + 12` and faulted inside the reporter). It also returns "unknown" for zero RVAs or an empty type list, and skips the `std::exception` message when the object pointer is null. `unwind_into` now uses `checked_add` for `rsp + 8`; on `main` a corrupted `Rsp` near `u64::MAX` wrapped past the bounds check. It also reads the return address with `read_unaligned`, since a misaligned `read()` is UB and panics in debug builds. I checked the call site (`report`, which only requires `NumberParameters >= 4` and the magic) and the loop exit on `Rip == 0`. The new test's expectations (`[0x1000]`, `[0x2000]`) match that code. Reporting only, with no change to emulation behaviour. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:52 UTC · original

Code review and Windows 11 verification at head 06cebbf704c7 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-loader/src/crash.rs:595-652, 754-796):
    • thrown safely rejects p.len() < 4 || p[2] == 0 || p[3] == 0 (covering C++ throw; rethrows), checks RVA non-zero and p[3].checked_add(...), guards count == 0, and reads integer/message values with p[1] != 0 and read_unaligned().
    • unwind_into prevents u64::MAX wraparound via rsp.checked_add(8).is_none_or(|end| end > high) and uses read_unaligned() on the leaf (entry.is_null()) return-address read.
    • Minor non-blocking note: when a crashing frame does have a RUNTIME_FUNCTION (!entry.is_null()), a misaligned context.Rsp is still passed directly to RtlVirtualUnwind, and a few small fixed offsets inside thrown (p[2] + 12, types + 4 + 4 * i, descriptor + 16) still use plain +. Still a solid improvement over main.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-loader --all-targets --locked -- -D warnings (default + --all-features): 0 warnings
    • cargo test -p victory-loader --locked: 36/36 unit + 4/4 integration passed; --all-features: 38/38 unit + 4/4 integration passed (including thrown_and_unwind_handle_rethrow_and_corrupted_rsp).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2554#issuecomment-7179205869) Code review and Windows 11 verification at head `06cebbf704c7` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-loader/src/crash.rs:595-652, 754-796`)**: - `thrown` safely rejects `p.len() < 4 || p[2] == 0 || p[3] == 0` (covering C++ `throw;` rethrows), checks RVA non-zero and `p[3].checked_add(...)`, guards `count == 0`, and reads integer/message values with `p[1] != 0` and `read_unaligned()`. - `unwind_into` prevents `u64::MAX` wraparound via `rsp.checked_add(8).is_none_or(|end| end > high)` and uses `read_unaligned()` on the leaf (`entry.is_null()`) return-address read. - Minor non-blocking note: when a crashing frame *does* have a `RUNTIME_FUNCTION` (`!entry.is_null()`), a misaligned `context.Rsp` is still passed directly to `RtlVirtualUnwind`, and a few small fixed offsets inside `thrown` (`p[2] + 12`, `types + 4 + 4 * i`, `descriptor + 16`) still use plain `+`. Still a solid improvement over `main`. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy -p victory-loader --all-targets --locked -- -D warnings` (default + `--all-features`): 0 warnings - `cargo test -p victory-loader --locked`: **36/36 unit + 4/4 integration passed**; `--all-features`: **38/38 unit + 4/4 integration passed** (including `thrown_and_unwind_handle_rethrow_and_corrupted_rsp`). LGTM.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 01:35 UTC · original

NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head 06cebbf (on its base 67e8ae1).

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: 774 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: thrown_and_unwind_handle_rethrow_and_corrupted_rsp.
  • --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.
**@⁠futurepro62** on GitHub · 2026-11-26 01:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2554#issuecomment-7179931227) NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `06cebbf` (on its base `67e8ae1`). **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`: **774 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `thrown_and_unwind_handle_rethrow_and_corrupted_rsp`. - `--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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 15:38 UTC · original · approved these changes

Reviewed 06cebbf704c71ff449fa81be05a90f0157c27b25 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 across dev, --all-features, and --release builds.

Audit

  • C++ exception metadata guards (crates/victory-loader/src/crash.rs:584, :585, :600):
    • Correctly handles short exception parameter arrays and MSVC throw; rethrows (p.len() < 4 || p[2] == 0 || p[3] == 0), validates non-zero types_rva / entry_rva / desc_rva with checked_add, caps count at 64 and guards count == 0, avoids dereferencing a null object pointer (p[1] == 0) for std::exception, and uses read_unaligned() for raw pointer reads.
  • Stack unwind bounds & alignment (crates/victory-loader/src/crash.rs:753, :762):
    • rsp.checked_add(8).is_none_or(|end| end > high) closes the u64 wraparound near u64::MAX that previously bypassed the upper stack bound, and (rsp as *const u64).read_unaligned() removes misaligned-read UB on corrupted leaf frames.

Verification

  • Clean merge onto 63bcca43c6a00a758510398fa43096ce7e4f7df0 + cargo run -p xtask -- policy (191 files ok)
  • cargo clippy -p victory-loader --all-targets -- -D warnings (default & --all-features)
  • cargo test -p victory-loader: 40/40 passed (dev), 42/42 passed (--all-features), 40/40 passed (--release), including thrown_and_unwind_handle_rethrow_and_corrupted_rsp.
  • Also ran a synthetic boundary probe covering p.len() < 4, null p[2]/p[3], zero types_rva/entry_rva/desc_rva, count == 0 and count > 64, null p[1] with .?AVexception@std@@, and unwind_into at u64::MAX, u64::MAX - 7, u64::MAX - 6, and high - 7 — all returned safely without faulting.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 15:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2554#pullrequestreview-6076887659) · **approved these changes** Reviewed `06cebbf704c71ff449fa81be05a90f0157c27b25` (merged cleanly onto `63bcca43c6a00a758510398fa43096ce7e4f7df0`) and verified on Windows 11 across `dev`, `--all-features`, and `--release` builds. ### Audit - **C++ exception metadata guards** (`crates/victory-loader/src/crash.rs:584`, `:585`, `:600`): - Correctly handles short exception parameter arrays and MSVC `throw;` rethrows (`p.len() < 4 || p[2] == 0 || p[3] == 0`), validates non-zero `types_rva` / `entry_rva` / `desc_rva` with `checked_add`, caps `count` at `64` and guards `count == 0`, avoids dereferencing a null object pointer (`p[1] == 0`) for `std::exception`, and uses `read_unaligned()` for raw pointer reads. - **Stack unwind bounds & alignment** (`crates/victory-loader/src/crash.rs:753`, `:762`): - `rsp.checked_add(8).is_none_or(|end| end > high)` closes the `u64` wraparound near `u64::MAX` that previously bypassed the upper stack bound, and `(rsp as *const u64).read_unaligned()` removes misaligned-read UB on corrupted leaf frames. ### Verification - Clean merge onto `63bcca43c6a00a758510398fa43096ce7e4f7df0` + `cargo run -p xtask -- policy` (`191 files ok`) - `cargo clippy -p victory-loader --all-targets -- -D warnings` (default & `--all-features`) - `cargo test -p victory-loader`: **40/40 passed** (`dev`), **42/42 passed** (`--all-features`), **40/40 passed** (`--release`), including `thrown_and_unwind_handle_rethrow_and_corrupted_rsp`. - Also ran a synthetic boundary probe covering `p.len() < 4`, null `p[2]`/`p[3]`, zero `types_rva`/`entry_rva`/`desc_rva`, `count == 0` and `count > 64`, null `p[1]` with `.?AVexception@std@@`, and `unwind_into` at `u64::MAX`, `u64::MAX - 7`, `u64::MAX - 6`, and `high - 7` — all returned safely without faulting.
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/2554/head:github-bot/gh-2554'
git switch 'github-bot/gh-2554'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2554'
git switch 'github-bot/gh-2554'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2554'
git switch 'github-bot/gh-2554'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2554'
git switch 'main'
git merge --squash 'github-bot/gh-2554'
git switch 'main'
git merge --ff-only 'github-bot/gh-2554'
git switch 'main'
git merge 'github-bot/gh-2554'
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!2554
No description provided.