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

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

@⁠fuzeofficlal on GitHub · 2026-11-26 09:39 UTC · original
fuzeofficlal:fix/hle-files-logical-drives-zero → main · +55 −3 · 1 files · 1 commits · open

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/3134) `fuzeofficlal:fix/hle-files-logical-drives-zero` → `main` · +55 −3 · 1 files · 1 commits · open ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:15 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 10:23 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-26 10:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3134#issuecomment-7189294510) 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).
Author
Owner

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

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.

**@⁠AurumCarlos** on GitHub · 2026-11-26 12:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3134#pullrequestreview-6074327285) · **reviewed** 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.
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/3134/head:github-bot/gh-3134'
git switch 'github-bot/gh-3134'

Merge

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