HLE: reject failed GetLogicalDrives() mask when mounting virtual drives #3132

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3134 into main
fuzeofficlal commented 2026-11-26 09:39:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:39:17Z.


Summary

Win32 GetLogicalDrives() returns 0 on failure. files::mount (crates/victory-hle/src/modules/files.rs) previously did not check for 0, so (0 >> bit) & 1 == 0 treated every drive letter D..=Z as free and allocated Z:, risking shadowing a real host drive.

Fix

  • Extract mount_in so mount logs a warning and returns None without modifying the mount table when GetLogicalDrives() returns 0, while still returning cached letters for already-mounted roots.
  • Add isolated unit tests in modules::files::tests covering 0, full bitmasks (0x03ff_ffff / 0x03ff_fff8), and normal letter allocation/reuse without mutating global DRIVES.

Verification

  • cargo test -p victory-hle --locked: 155 lib (including 9 modules::files::tests) + 1 fidelityfx + 1 no_dll_planting passed, 0 failed.
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings and --all-features: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5507579802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3134). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:39:17Z. --- ## Summary Win32 `GetLogicalDrives()` returns `0` on failure. `files::mount` (`crates/victory-hle/src/modules/files.rs`) previously did not check for `0`, so `(0 >> bit) & 1 == 0` treated every drive letter `D..=Z` as free and allocated `Z:`, risking shadowing a real host drive. ## Fix - Extract `mount_in` so `mount` logs a warning and returns `None` without modifying the mount table when `GetLogicalDrives()` returns `0`, while still returning cached letters for already-mounted roots. - Add isolated unit tests in `modules::files::tests` covering `0`, full bitmasks (`0x03ff_ffff` / `0x03ff_fff8`), and normal letter allocation/reuse without mutating global `DRIVES`. ## Verification - `cargo test -p victory-hle --locked`: 155 lib (including 9 `modules::files::tests`) + 1 `fidelityfx` + 1 `no_dll_planting` passed, 0 failed. - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` and `--all-features`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed.
cloph-dsp commented 2026-11-26 11:04:00 +00:00 (Migrated from github.com)

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


Independent local verification of head 8416b0b on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-hle --lib modules::files::tests — 6 passed, 0 failed (including the three new mount_in_* tests).
  • git diff --check origin/main HEAD — clean.

Synthetic drive masks only; no game assets, extracted data or DRM material used. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189294510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3134#issuecomment-7189294510). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T10:23:08Z. --- Independent local verification of head `8416b0b` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-hle --lib modules::files::tests` — 6 passed, 0 failed (including the three new `mount_in_*` tests). - `git diff --check origin/main HEAD` — clean. Synthetic drive masks only; no game assets, extracted data or DRM material used. AI-assisted (Hy4 flash).
AurumCarlos commented 2026-11-26 12:44:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The refactor is clean: injecting host_drives into mount_in makes the letter choice testable without touching the global DRIVES. I also like the || panic!(..) in the reuse test, which proves a cached root never queries the host. The guard does what the description says. I do have one question about the trade-off it makes.

What a failed query now costs. On main, the only non-test caller of files::mount is storage::folder(). If mount returns None, the persistent-storage path calls (0x18/0x20) answer NOT_SUPPORTED, so the title gets no save-storage drive at all. Before this change, the same failure gave the title Z:\, which works unless the host really has a Z: that the title would also want to reach. These drives are path rewrites inside our own file hooks, not OS mounts, so "shadowing" only affects the title's own paths to that letter, which it has no reason to use for anything but the storage it was given.

So the change swaps an unlikely, mostly harmless collision for a hard failure of saving. GetLogicalDrives failing is itself very rare, so this may never matter in practice. But if it does happen, I'd expect "saves still work" to be the better outcome. Some options:

  • Keep the warn! but fall back to picking from D..=Z as before, so the failure is visible in the log without breaking storage.
  • Or, if you'd rather never guess, say in the PR (and in the mount doc comment) that a failed query now means no storage path, so that trade-off is explicit.

A minor point, for consistency: mount_at also calls GetLogicalDrives, and treats 0 as "hides no host drive". It's only used for the hides_host_drive log field there, so it's harmless, but a failed query will log false instead of saying the query failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074327285 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3134#pullrequestreview-6074327285). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T12:44:04Z. **Review:** COMMENTED --- The refactor is clean: injecting `host_drives` into `mount_in` makes the letter choice testable without touching the global `DRIVES`. I also like the `|| panic!(..)` in the reuse test, which proves a cached root never queries the host. The guard does what the description says. I do have one question about the trade-off it makes. **What a failed query now costs.** On `main`, the only non-test caller of `files::mount` is `storage::folder()`. If `mount` returns `None`, the persistent-storage path calls (0x18/0x20) answer `NOT_SUPPORTED`, so the title gets no save-storage drive at all. Before this change, the same failure gave the title `Z:\`, which works unless the host really has a `Z:` that the title would also want to reach. These drives are path rewrites inside our own file hooks, not OS mounts, so "shadowing" only affects the title's own paths to that letter, which it has no reason to use for anything but the storage it was given. So the change swaps an unlikely, mostly harmless collision for a hard failure of saving. `GetLogicalDrives` failing is itself very rare, so this may never matter in practice. But if it does happen, I'd expect "saves still work" to be the better outcome. Some options: - Keep the `warn!` but fall back to picking from `D..=Z` as before, so the failure is visible in the log without breaking storage. - Or, if you'd rather never guess, say in the PR (and in the `mount` doc comment) that a failed query now means no storage path, so that trade-off is explicit. A minor point, for consistency: `mount_at` also calls `GetLogicalDrives`, and treats `0` as "hides no host drive". It's only used for the `hides_host_drive` log field there, so it's harmless, but a failed query will log `false` instead of saying the query failed.
futurepro62 commented 2026-11-27 12:02:47 +00:00 (Migrated from github.com)

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


NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head 8416b0b (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: 869 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: mount_in_rejects_failed_host_drive_query, mount_in_uses_only_d_through_z, mount_in_chooses_highest_free_letter_and_reuses_mounts.
  • --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:7217774040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3134#issuecomment-7217774040). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T12:02:47Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head `8416b0b` (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`: **869 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `mount_in_rejects_failed_host_drive_query`, `mount_in_uses_only_d_through_z`, `mount_in_chooses_highest_free_letter_and_reuses_mounts`. - `--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/3134:upstream-pr/3134'
git switch 'upstream-pr/3134'

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/3134'
git switch 'upstream-pr/3134'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3134'
git switch 'upstream-pr/3134'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3134'
git switch 'main'
git merge --squash 'upstream-pr/3134'
git switch 'main'
git merge --ff-only 'upstream-pr/3134'
git switch 'main'
git merge 'upstream-pr/3134'
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!3132
No description provided.