HLE: virtual drives mishandle verbatim/drive-root mounts and GetDiskFreeSpaceW volume roots (fix on a fork) #1742

Open
opened 2026-11-26 04:43:26 +00:00 by github-bot · 1 comment
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 21:45 UTC · original

Summary

In crates/victory-hle/src/modules/files.rs, virtual-drive path translation and GetDiskFreeSpaceW mishandle three host-root forms on Windows:

  1. Verbatim (\\?\) mounted host roots (for example, any path returned by std::fs::canonicalize on Windows):

    • translate() only entered verbatim() when prefix.is_empty() && root.len() + tail.len() >= LONG.
    • For short title paths with forward slashes (X:/a/b.txt) or dot segments (X:/sub/../b.txt), translate() kept / and . / .. verbatim inside the \\?\ host path, which Windows rejects (CreateFileW returns INVALID_HANDLE_VALUE).
    • For extended title paths (\\?\X:\a.txt), translate() prepended a second \\?\, producing \\?\\\?\C:\...\a.txt (ERROR_INVALID_NAME, code 123).
    • root_wide() stripped the trailing \ from verbatim drive roots (\\?\C:\ -> \\?\C:, length 6) because the minimum kept length was hardcoded to 3.
  2. Drive-root mounts (C:\) and UNC mounts under \\?\:

    • root_wide() keeps the trailing \ on C:\ (length 3), so translate() doubled the separator on X:\foo (C:\\foo), X: (C:\\), and \\?\X:\foo (\\?\C:\\foo).
    • verbatim() stripped the trailing \ from \\?\C:\ when tail had no remaining components, leaving \\?\C:.
    • For a UNC host root \\server\share\dir with an extended title path \\?\X:\foo, translate() produced \\?\\\server\share\dir\foo instead of \\?\UNC\server\share\dir\foo.
  3. GetDiskFreeSpaceW volume-root extraction:

    • GetDiskFreeSpaceW only matched [letter, b':', sep, ..] at the start of the translated host path.
    • Whenever translate() emitted a \\?\ path (e.g. a verbatim query \\?\X:\, a canonicalized \\?\ mount, or a long host root >= 248 chars) or a UNC path (\\server\share\... / \\?\UNC\server\share\...), it failed to reduce the path to its volume root (C:\ or \\server\share\), causing Win32 GetDiskFreeSpaceW to fail (ERROR_INVALID_NAME / ERROR_PATH_NOT_FOUND).

(Note: this is distinct from open PRs #182 and #421, which clean .. / . segments in short and \\?\ title paths over plain host roots without addressing \\?\ mounted roots, drive-root separator doubling, or GetDiskFreeSpaceW.)

Fix on fork

Changes

  • root_wide: keep trailing separator on verbatim drive roots (min = 7 for \\?\, 3 otherwise).
  • verbatim: restore trailing \ when the result ends at a drive colon (\\?\C:).
  • translate: route root.starts_with(&VERBATIM) through verbatim(), convert UNC roots under \\?\ to \\?\UNC\..., and avoid doubling separators when root itself ends with a separator.
  • GetDiskFreeSpaceW: extract volume roots via volume_root() for plain drive, \\?\ verbatim drive, UNC (\\server\share\...), and \\?\UNC\server\share\... paths.
  • Added 3 synthetic unit tests in crates/victory-hle/src/modules/files.rs:
    • verbatim_host_roots_translate_and_open_on_the_host
    • drive_root_mount_does_not_double_separators
    • disk_free_space_handles_verbatim_and_long_virtual_roots

Verification

Tested on Windows 11 x64 MSVC (Rust 1.98.1), synthetic unit tests only (no game files or console SDK data):

  • Before fix (cargo test -p victory-hle --lib files::): all 3 new tests fail:
    • verbatim_host_roots_translate_and_open_on_the_host: CreateFileW returns -1 for \\?\C:\Users\...\from_slash.bin (forward slash in verbatim path).
    • drive_root_mount_does_not_double_separators: Some("C:\\\\foo") != Some("C:\\foo").
    • disk_free_space_handles_verbatim_and_long_virtual_roots: GetDiskFreeSpaceW returns 0 (ERROR_INVALID_NAME, code 123 on \\?\<letter>:\).
  • After fix:
    • rustfmt --edition 2024 --check crates/victory-hle/src/modules/files.rs: 0 diffs on touched lines (1 pre-existing untouched line at kernel_reads_reach_the_buffer).
    • cargo test -p victory-hle: 97 unit tests + 1 integration test passed, 0 failed.
    • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
    • cargo check -p victory --features diagnostics: clean.
    • cargo xtask policy: asset policy: 154 files ok.

AI disclosure: found, verified, and drafted with assistance from Google Antigravity.

**@⁠AndyLatimer** on GitHub · 2026-11-24 21:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/1742) ## Summary In `crates/victory-hle/src/modules/files.rs`, virtual-drive path translation and `GetDiskFreeSpaceW` mishandle three host-root forms on Windows: 1. **Verbatim (`\\?\`) mounted host roots** (for example, any path returned by `std::fs::canonicalize` on Windows): - `translate()` only entered `verbatim()` when `prefix.is_empty() && root.len() + tail.len() >= LONG`. - For short title paths with forward slashes (`X:/a/b.txt`) or dot segments (`X:/sub/../b.txt`), `translate()` kept `/` and `.` / `..` verbatim inside the `\\?\` host path, which Windows rejects (`CreateFileW` returns `INVALID_HANDLE_VALUE`). - For extended title paths (`\\?\X:\a.txt`), `translate()` prepended a second `\\?\`, producing `\\?\\\?\C:\...\a.txt` (`ERROR_INVALID_NAME`, code 123). - `root_wide()` stripped the trailing `\` from verbatim drive roots (`\\?\C:\` -> `\\?\C:`, length 6) because the minimum kept length was hardcoded to 3. 2. **Drive-root mounts (`C:\`) and UNC mounts under `\\?\`**: - `root_wide()` keeps the trailing `\` on `C:\` (length 3), so `translate()` doubled the separator on `X:\foo` (`C:\\foo`), `X:` (`C:\\`), and `\\?\X:\foo` (`\\?\C:\\foo`). - `verbatim()` stripped the trailing `\` from `\\?\C:\` when `tail` had no remaining components, leaving `\\?\C:`. - For a UNC host root `\\server\share\dir` with an extended title path `\\?\X:\foo`, `translate()` produced `\\?\\\server\share\dir\foo` instead of `\\?\UNC\server\share\dir\foo`. 3. **`GetDiskFreeSpaceW` volume-root extraction**: - `GetDiskFreeSpaceW` only matched `[letter, b':', sep, ..]` at the start of the translated host path. - Whenever `translate()` emitted a `\\?\` path (e.g. a verbatim query `\\?\X:\`, a canonicalized `\\?\` mount, or a long host root `>= 248` chars) or a UNC path (`\\server\share\...` / `\\?\UNC\server\share\...`), it failed to reduce the path to its volume root (`C:\` or `\\server\share\`), causing Win32 `GetDiskFreeSpaceW` to fail (`ERROR_INVALID_NAME` / `ERROR_PATH_NOT_FOUND`). *(Note: this is distinct from open PRs #182 and #421, which clean `..` / `.` segments in short and `\\?\` title paths over plain host roots without addressing `\\?\` mounted roots, drive-root separator doubling, or `GetDiskFreeSpaceW`.)* ## Fix on fork - **Branch:** https://github.com/AndyLatimer/VIctory/tree/fix/hle-files-verbatim-root-and-disk-space - **Commit:** https://github.com/AndyLatimer/VIctory/commit/462a64e62d5613977a84320cd30041bec5969446 (based on `origin/main` `ffe310e`) ### Changes - `root_wide`: keep trailing separator on verbatim drive roots (`min = 7` for `\\?\`, `3` otherwise). - `verbatim`: restore trailing `\` when the result ends at a drive colon (`\\?\C:`). - `translate`: route `root.starts_with(&VERBATIM)` through `verbatim()`, convert UNC roots under `\\?\` to `\\?\UNC\...`, and avoid doubling separators when `root` itself ends with a separator. - `GetDiskFreeSpaceW`: extract volume roots via `volume_root()` for plain drive, `\\?\` verbatim drive, UNC (`\\server\share\...`), and `\\?\UNC\server\share\...` paths. - Added 3 synthetic unit tests in `crates/victory-hle/src/modules/files.rs`: - `verbatim_host_roots_translate_and_open_on_the_host` - `drive_root_mount_does_not_double_separators` - `disk_free_space_handles_verbatim_and_long_virtual_roots` ## Verification Tested on Windows 11 x64 MSVC (Rust 1.98.1), synthetic unit tests only (no game files or console SDK data): - **Before fix (`cargo test -p victory-hle --lib files::`):** all 3 new tests fail: - `verbatim_host_roots_translate_and_open_on_the_host`: `CreateFileW` returns `-1` for `\\?\C:\Users\...\from_slash.bin` (forward slash in verbatim path). - `drive_root_mount_does_not_double_separators`: `Some("C:\\\\foo") != Some("C:\\foo")`. - `disk_free_space_handles_verbatim_and_long_virtual_roots`: `GetDiskFreeSpaceW` returns `0` (`ERROR_INVALID_NAME`, code 123 on `\\?\<letter>:\`). - **After fix:** - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/files.rs`: 0 diffs on touched lines (1 pre-existing untouched line at `kernel_reads_reach_the_buffer`). - `cargo test -p victory-hle`: 97 unit tests + 1 integration test passed, 0 failed. - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo check -p victory --features diagnostics`: clean. - `cargo xtask policy`: `asset policy: 154 files ok`. *AI disclosure: found, verified, and drafted with assistance from Google Antigravity.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:26 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 12:49 UTC · original

Automated triage for the maintainers. Confirmed by reading main (940d32f), crates/victory-hle/src/modules/files.rs:

  • translate takes the verbatim() route only when the title path has no \\?\ prefix and the result is at least LONG characters. A short path over a \\?\ host root keeps its / and ./.. segments, and a \\?\X:\... title path over a \\?\ (or UNC) root gets a second prefix.
  • root_wide keeps at most 3 characters of trailing separator, so \\?\C:\ becomes \\?\C:. A plain C:\ root keeps its \, and translate then adds another one before the tail (C:\\foo, and C:\\ for X:).
  • GetDiskFreeSpaceW reduces only a host path that starts with letter: plus a separator to its volume root, so \\?\ and UNC host paths are passed through whole.

Open PR #1772 carries the fork fix with the three tests.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 12:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/1742#issuecomment-7162913591) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T21:45:41Z at=2026-11-25T12:49:19Z --> Automated triage for the maintainers. Confirmed by reading `main` (940d32f), `crates/victory-hle/src/modules/files.rs`: - `translate` takes the `verbatim()` route only when the title path has no `\\?\` prefix and the result is at least `LONG` characters. A short path over a `\\?\` host root keeps its `/` and `.`/`..` segments, and a `\\?\X:\...` title path over a `\\?\` (or UNC) root gets a second prefix. - `root_wide` keeps at most 3 characters of trailing separator, so `\\?\C:\` becomes `\\?\C:`. A plain `C:\` root keeps its `\`, and `translate` then adds another one before the tail (`C:\\foo`, and `C:\\` for `X:`). - `GetDiskFreeSpaceW` reduces only a host path that starts with `letter:` plus a separator to its volume root, so `\\?\` and UNC host paths are passed through whole. Open PR #1772 carries the fork fix with the three tests. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#1742
No description provided.