VFS: audit case-insensitive path canonicalization, whiteouts, and traversal boundaries #1560

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

@⁠slopgobblercobbler on GitHub · 2026-11-24 17:40 UTC · original
slopgobblercobbler:fix/vfs-path-canonicalization-bounds → main · +392 −86 · 1 files · 1 commits · open

Summary

Audits virtual file system (VFS) path canonicalization, whiteouts case-insensitivity, and traversal bounds in crates/xcl/src/vfs.rs:

  1. Case-insensitive path canonicalization:
    • In strip_verbatim: made verbatim UNC prefix checks case-insensitive (\\?\unc\, \\?\Unc\, \\?\UNC\) and supported NT object manager namespace prefixes (\??\unc\, \??\), preventing lowercase verbatim UNC paths from being stripped to unc\... and incorrectly treated as local relative paths.
    • In Vfs::new: normalized game_root, data_root, and mount targets with full_path, strip_verbatim, and norm, and normalized mount prefixes with norm and to_ascii_lowercase (so mount definitions containing forward slashes cleanly match normalized paths).
    • In classify_with: fixed character slice calculations when stripping the game root prefix to prevent boundary panics on mixed-case or unicode paths, and verified relative remainders using clean_rel.
  2. Whiteouts canonicalization & case-insensitivity:
    • Added clean_rel(rel: &str) -> Option<String> which normalizes slashes, trims redundant separators, and resolves . and .. segments.
    • Updated wkey: maps relative paths to canonical lowercase keys via clean_rel, ensuring whiteout operations (is_whiteout, has_whiteouts_under, add_whiteout, remove_whiteout) are completely case- and slash-invariant (data\gone.txt, DATA\GONE.TXT, data/gone.txt, data/./gone.txt, \data\gone.txt\).
    • Fixed has_whiteouts_under and needs_merge when queried with trailing or forward slashes (data\, data/, DATA), preventing data\\\\ prefix mismatch bugs.
    • In Vfs::new: canonicalized existing .xcl_whiteouts entries through Self::wkey upon loading.
  3. Boundary checks on directory traversal:
    • In clean_rel: added strict boundary checks that reject paths attempting to traverse above the root via .. (when the component stack is empty) or containing drive letters, UNC, or device streams, returning None.
    • In Vfs methods (delete_file, stage_write, prepare_write, create_dir, remove_dir, open_decision_for, read_path_rel, visible_in_overlay, visible_in_original, exists, is_dir): enforced boundary validation via clean_rel, rejecting traversal escapes with safe Win32 error codes (ERROR_PATH_NOT_FOUND / ERROR_FILE_NOT_FOUND) without filesystem access.
  4. Unit tests:
    • Added comprehensive tests: clean_rel_resolves_dots_and_detects_boundary_traversal, case_insensitive_whiteouts_across_slashes_and_dots, strip_verbatim_supports_mixed_case_unc_and_nt_prefixes, remove_dir_enforces_clean_rel_and_bounds.

Changes

  • crates/xcl/src/vfs.rs:
    • clean_rel helper for robust segment resolution and traversal escape defense.
    • Case- and separator-insensitive UNC and NT namespace handling in strip_verbatim.
    • Canonical lowercase whiteout keys in wkey and .xcl_whiteouts loader.
    • Traversal rejection in VFS mutations and lookups.
    • Unit tests covering traversal attempts, case normalization, and whiteouts.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- vfs: 22 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Non-Windows POSIX host filesystems (case-preserving vs case-insensitive mounted shares).

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 17:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560) `slopgobblercobbler:fix/vfs-path-canonicalization-bounds` → `main` · +392 −86 · 1 files · 1 commits · open ## Summary Audits virtual file system (VFS) path canonicalization, whiteouts case-insensitivity, and traversal bounds in `crates/xcl/src/vfs.rs`: 1. **Case-insensitive path canonicalization**: - In `strip_verbatim`: made verbatim UNC prefix checks case-insensitive (`\\?\unc\`, `\\?\Unc\`, `\\?\UNC\`) and supported NT object manager namespace prefixes (`\??\unc\`, `\??\`), preventing lowercase verbatim UNC paths from being stripped to `unc\...` and incorrectly treated as local relative paths. - In `Vfs::new`: normalized `game_root`, `data_root`, and mount targets with `full_path`, `strip_verbatim`, and `norm`, and normalized mount prefixes with `norm` and `to_ascii_lowercase` (so mount definitions containing forward slashes cleanly match normalized paths). - In `classify_with`: fixed character slice calculations when stripping the game root prefix to prevent boundary panics on mixed-case or unicode paths, and verified relative remainders using `clean_rel`. 2. **Whiteouts canonicalization & case-insensitivity**: - Added `clean_rel(rel: &str) -> Option<String>` which normalizes slashes, trims redundant separators, and resolves `.` and `..` segments. - Updated `wkey`: maps relative paths to canonical lowercase keys via `clean_rel`, ensuring whiteout operations (`is_whiteout`, `has_whiteouts_under`, `add_whiteout`, `remove_whiteout`) are completely case- and slash-invariant (`data\gone.txt`, `DATA\GONE.TXT`, `data/gone.txt`, `data/./gone.txt`, `\data\gone.txt\`). - Fixed `has_whiteouts_under` and `needs_merge` when queried with trailing or forward slashes (`data\`, `data/`, `DATA`), preventing `data\\\\` prefix mismatch bugs. - In `Vfs::new`: canonicalized existing `.xcl_whiteouts` entries through `Self::wkey` upon loading. 3. **Boundary checks on directory traversal**: - In `clean_rel`: added strict boundary checks that reject paths attempting to traverse above the root via `..` (when the component stack is empty) or containing drive letters, UNC, or device streams, returning `None`. - In `Vfs` methods (`delete_file`, `stage_write`, `prepare_write`, `create_dir`, `remove_dir`, `open_decision_for`, `read_path_rel`, `visible_in_overlay`, `visible_in_original`, `exists`, `is_dir`): enforced boundary validation via `clean_rel`, rejecting traversal escapes with safe Win32 error codes (`ERROR_PATH_NOT_FOUND` / `ERROR_FILE_NOT_FOUND`) without filesystem access. 4. **Unit tests**: - Added comprehensive tests: `clean_rel_resolves_dots_and_detects_boundary_traversal`, `case_insensitive_whiteouts_across_slashes_and_dots`, `strip_verbatim_supports_mixed_case_unc_and_nt_prefixes`, `remove_dir_enforces_clean_rel_and_bounds`. ## Changes - `crates/xcl/src/vfs.rs`: - `clean_rel` helper for robust segment resolution and traversal escape defense. - Case- and separator-insensitive UNC and NT namespace handling in `strip_verbatim`. - Canonical lowercase whiteout keys in `wkey` and `.xcl_whiteouts` loader. - Traversal rejection in VFS mutations and lookups. - Unit tests covering traversal attempts, case normalization, and whiteouts. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- vfs`: 22 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Non-Windows POSIX host filesystems (case-preserving vs case-insensitive mounted shares). ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:32 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 17:54 UTC · original

Regression run for this PR: head 6caef61, based on main 9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s.

main 9e3831e:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1601 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 72801 MB

this PR:

xcl-smoke v1
commit: 6caef6199a6a25d274ad4ae5e2bd496b93c76cf9
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1356 (PresentX 1356)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 82225 MB

No device removals or crashes; 85 % of main's frames, 113 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run (21–92 GB with the same build), so it says little about this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

**@⁠Anon64** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#issuecomment-7139871667) Regression run for this PR: head `6caef61`, based on `main` `9e3831e`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s. main `9e3831e`: ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1601 (PresentX 1602) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 72801 MB ``` this PR: ``` xcl-smoke v1 commit: 6caef6199a6a25d274ad4ae5e2bd496b93c76cf9 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1356 (PresentX 1356) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 82225 MB ``` No device removals or crashes; 85 % of main's frames, 113 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run (21–92 GB with the same build), so it says little about this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 19:26 UTC · original

Full-suite run at the new head c43ac38 (on its base 9e3831e). One existing test now fails, deterministically.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB, driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17, debug.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form (that skip is #1651, unrelated): 764 passed, 1 failed. Same result twice, once with nothing else running on the machine.
  • The failure is disk_free_space_ex_reports_pls_quota (crates/xcl/tests/pls_quota.rs:129): GetDiskFreeSpaceExW returns 0 (left: 0, right: 0 on assert_ne!).
  • The previous head 6caef61 passed that test (full suite on the AMD Radeon integrated GPU of the 9800X3D: 0 failed). So the change is the latest commit.

Cause (from reading the diff)

  • The test on main expects a .. that climbs out of the S: (PLS) mount to work and to report the host's free space, not the PLS quota:
    for path in [&host, &wide(r"T:\"), &wide(r"S:\..\pls-other")] {
        assert_ne!(GetDiskFreeSpaceExW(path.as_ptr(), ...), 0);
        assert_eq!(total, host_total);
    }
    
  • c43ac38 now refuses traversal that leaves a mount root (classify -> Target::Game { rel: ".." }, as in the new translated_mount_validates_path_against_mount_root_and_rejects_traversal). S:\..\pls-other is exactly that case, so the call now fails.
  • So the two disagree on intent. Either S:\..\pls-other should keep resolving (and the new check is too broad), or it should be refused and pls_quota.rs needs that case changed to expect failure. That's a call for you or the maintainers; I haven't changed anything.

Not tested

  • The new head on the AMD iGPU, a game (no title here).
  • Because cargo stops at the first failing test binary, the binaries after pls_quota did not run on this head (29 ignored instead of 41).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests, traced the cause and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 19:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#issuecomment-7142102341) Full-suite run at the new head `c43ac38` (on its base `9e3831e`). One existing test now fails, deterministically. **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB, driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17, debug. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form` (that skip is #1651, unrelated): **764 passed, 1 failed**. Same result twice, once with nothing else running on the machine. - The failure is `disk_free_space_ex_reports_pls_quota` (`crates/xcl/tests/pls_quota.rs:129`): `GetDiskFreeSpaceExW` returns 0 (`left: 0, right: 0` on `assert_ne!`). - The previous head `6caef61` passed that test (full suite on the AMD Radeon integrated GPU of the 9800X3D: 0 failed). So the change is the latest commit. **Cause (from reading the diff)** - The test on main expects a `..` that climbs out of the `S:` (PLS) mount to work and to report the host's free space, not the PLS quota: ```rust for path in [&host, &wide(r"T:\"), &wide(r"S:\..\pls-other")] { assert_ne!(GetDiskFreeSpaceExW(path.as_ptr(), ...), 0); assert_eq!(total, host_total); } ``` - `c43ac38` now refuses traversal that leaves a mount root (`classify` -> `Target::Game { rel: ".." }`, as in the new `translated_mount_validates_path_against_mount_root_and_rejects_traversal`). `S:\..\pls-other` is exactly that case, so the call now fails. - So the two disagree on intent. Either `S:\..\pls-other` should keep resolving (and the new check is too broad), or it should be refused and `pls_quota.rs` needs that case changed to expect failure. That's a call for you or the maintainers; I haven't changed anything. **Not tested** - The new head on the AMD iGPU, a game (no title here). - Because cargo stops at the first failing test binary, the binaries after `pls_quota` did not run on this head (29 ignored instead of 41). **AI use** - Claude Code (Claude Opus 5.5) ran the tests, traced the cause and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 19:32 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 19:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#issuecomment-7142245608) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 03:34 UTC · original

Regression run of c43ac386 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: c43ac386d92d988966f6af898fd52063fa304453
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14813 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

**@⁠Toons29** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#issuecomment-7152045014) Regression run of `c43ac386` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: c43ac386d92d988966f6af898fd52063fa304453 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1630 (PresentX 1630) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14813 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
@ -298,1 +368,3 @@
return Target::Game { rel: abs[self.game_root.len() + 1..].to_string() };
let skip = abs.len().saturating_sub(rest.len());
let rel_str = abs[skip..].trim_start_matches('\\');
if let Some(clean) = clean_rel(rel_str) {
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:00 UTC · original

Could the boundary also be enforced for translated mounts? With a G: mount rooted at C:\mount, G:\..\outside.txt maps to C:\mount\..\outside.txt; full_path resolves it to C:\outside.txt, and Target::Translated later reaches Decision::Use without clean_rel. A console path can therefore escape its mapped root despite this traversal check. Please validate translated paths against their mount root before using them. AI-assisted review: I traced this through apply_mounts, classify_with, and open_decision_for.

**@⁠gut0to** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#discussion_r4684329539) Could the boundary also be enforced for translated mounts? With a `G:` mount rooted at `C:\mount`, `G:\..\outside.txt` maps to `C:\mount\..\outside.txt`; `full_path` resolves it to `C:\outside.txt`, and `Target::Translated` later reaches `Decision::Use` without `clean_rel`. A console path can therefore escape its mapped root despite this traversal check. Please validate translated paths against their mount root before using them. AI-assisted review: I traced this through `apply_mounts`, `classify_with`, and `open_decision_for`.
@ -298,1 +368,3 @@
return Target::Game { rel: abs[self.game_root.len() + 1..].to_string() };
let skip = abs.len().saturating_sub(rest.len());
let rel_str = abs[skip..].trim_start_matches('\\');
if let Some(clean) = clean_rel(rel_str) {
Author
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-24 18:27 UTC · original

Addressed in commit c43ac38: tracked the mount target through apply_mounts and enforced root boundary validation in classify_with. If an absolutised translated path escapes its mapped mount root (whether a custom translated mount or a game mount rooted elsewhere), it is rejected as out-of-bounds (clean_rel / Target::Game { rel: ..\ }) and returns ERROR_PATH_NOT_FOUND from open_decision, rather than escaping via Target::Translated. Added unit test translated_mount_validates_path_against_mount_root_and_rejects_traversal verifying traversal rejection across both custom and game mounts.

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 18:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1560#discussion_r4684664289) Addressed in commit c43ac38: tracked the mount target through apply_mounts and enforced root boundary validation in classify_with. If an absolutised translated path escapes its mapped mount root (whether a custom translated mount or a game mount rooted elsewhere), it is rejected as out-of-bounds (clean_rel / Target::Game { rel: \..\ }) and returns ERROR_PATH_NOT_FOUND from open_decision, rather than escaping via Target::Translated. Added unit test translated_mount_validates_path_against_mount_root_and_rejects_traversal verifying traversal rejection across both custom and game mounts.
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/1560/head:github-bot/gh-1560'
git switch 'github-bot/gh-1560'

Merge

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