VFS: fix Unicode case-folding slicing and verbatim root normalisation #316

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

@⁠Michael-Glaser on GitHub · 2026-11-23 23:08 UTC · original
Michael-Glaser:fix/vfs-unicode-and-verbatim-root → main · +91 −18 · 1 files · 1 commits · open

Vfs::classify_with sliced un-lowercased abs using self.game_root.len() + 1 after .to_lowercase(), which panics or corrupts rel when Unicode case folding changes UTF-8 byte length (ẞ, İ, K). Vfs::new also missed strip_verbatim on game_root and data_root_lc.

What is in it

  • crates/xcl/src/vfs.rs: match game_root_lc per \ component (strip_path_prefix_ci), apply strip_verbatim + trim_sep to roots in Vfs::new, and add classify_handles_unicode_case_folding_and_verbatim_roots.

Tested

  • Cross-checked on macOS (aarch64-apple-darwin, Rust 1.100.0): cargo check --offline --target x86_64-pc-windows-msvc --workspace --tests (0 errors, 0 new warnings).

Not tested

  • Not built or executed on Windows; cargo test and scripts/smoke.ps1 not run yet.

AI use

  • Antigravity with Gemini 4 Neon (audit, fix, unit test, description).
**@⁠Michael-Glaser** on GitHub · 2026-11-23 23:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/316) `Michael-Glaser:fix/vfs-unicode-and-verbatim-root` → `main` · +91 −18 · 1 files · 1 commits · open `Vfs::classify_with` sliced un-lowercased `abs` using `self.game_root.len() + 1` after `.to_lowercase()`, which panics or corrupts `rel` when Unicode case folding changes UTF-8 byte length (`ẞ`, `İ`, `K`). `Vfs::new` also missed `strip_verbatim` on `game_root` and `data_root_lc`. **What is in it** - `crates/xcl/src/vfs.rs`: match `game_root_lc` per `\` component (`strip_path_prefix_ci`), apply `strip_verbatim` + `trim_sep` to roots in `Vfs::new`, and add `classify_handles_unicode_case_folding_and_verbatim_roots`. **Tested** - Cross-checked on macOS (`aarch64-apple-darwin`, Rust 1.100.0): `cargo check --offline --target x86_64-pc-windows-msvc --workspace --tests` (0 errors, 0 new warnings). **Not tested** - Not built or executed on Windows; `cargo test` and `scripts/smoke.ps1` not run yet. **AI use** - Antigravity with Gemini 4 Neon (audit, fix, unit test, description).
Vfs::classify_with compared abs.to_lowercase() against self.game_root_lc and then sliced the original abs at self.game_root.len() + 1. When Unicode case folding changes UTF-8 byte length (e.g. ẞ 3->2 bytes, İ 2->3 bytes, K 3->1 byte), that slice panics (out of bounds or mid-codepoint) inside an extern "system" file hook or returns a corrupted relative path.

Vfs::new also did not call strip_verbatim on game_root or data_root_lc, and strip_verbatim only matched uppercase \?\UNC\ (letting lowercase \?\unc\ or \??\UNC\ fall through as relative paths instead of UNC).

Match game_root_lc component-by-component on abs (strip_path_prefix_ci, trimming any repeated separators after the root), handle \?\ and \??\ UNC prefixes case-insensitively in strip_verbatim, and normalise game_root, data_root_lc, and pls_root_lc with strip_verbatim + trim_sep.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:52 +00:00
Author
Owner

@⁠0xKaji on GitHub · 2026-11-23 23:49 UTC · original

Reviewed commit f0bd1ea statically on Linux (not built or executed on Windows; assisted by T3 Code + Gemini 4 Neon).

strip_path_prefix_ci looks sound: every slice index is on an ASCII \ boundary within abs, so it eliminates the UTF-8 slicing panics and corrupted rel slices for length-changing case folds (ẞ, İ, K) without introducing regressions on standard paths.

A few concrete items before moving this out of draft:

  1. Merge blockers (CONTRIBUTING.md / PR checks):

    • PR checks is currently failing because crates/xcl/src/vfs.rs is runtime code and **Regression run** is missing the two xcl-smoke v1 blocks (main and PR head f0bd1ea, clean working tree) from scripts/smoke.ps1.
    • Windows cargo test --workspace -- --test-threads=4 counts (and green CI) are still needed in **Tested**.
  2. strip_verbatim (crates/xcl/src/vfs.rs:102-113) mishandles lowercase \\?\unc\... and \??\UNC\...:

    • Pre-existing in strip_verbatim, but now also called from Vfs::new (vfs.rs:192, 207, 210).
    • is_device (vfs.rs:157-160) matches \\?\ and \??\ with ASCII case-insensitive unc\, whereas strip_verbatim only checks exact uppercase "\\\\?\\UNC\\".
    • Concrete failing inputs: \\?\unc\server\share\file.bin and \??\UNC\server\share\file.bin bypass is_device, fall through to strip_prefix("\\\\?\\") / strip_prefix("\\??\\"), and become relative "unc\\server\\share\\file.bin" / "UNC\\server\\share\\file.bin". That bypasses the p.starts_with("\\\\") UNC guard (vfs.rs:286) and resolves relative to CWD (misclassifying as Target::Game when CWD is inside game_root).
    • Stripping \\?\ or \??\ first and then checking r.get(..4).is_some_and(|s| s.eq_ignore_ascii_case("UNC\\")) would keep strip_verbatim consistent with is_device (fine either here or as a small follow-up PR).
  3. Minor non-blocking edge cases / test notes:

    • In strip_path_prefix_ci (vfs.rs:143), &abs[pos + 1..] returns a leading \ if abs has repeated separators after the root (e.g. classify_with("C:\\Games\\Title\\\\Data\\a.bin", id) → rel: "\\Data\\a.bin"). GetFullPathNameW collapses \\ for normal paths, but abs[pos + 1..].trim_start_matches('\\') guarantees the Target::Game invariant unconditionally.
    • Pre-existing note (separate scope): if game_root is a drive root like X:\ or \\?\X:\, trim_sep stores "X:", so original_path("") returns "X:" (drive-relative CWD in Win32) instead of "X:\\".
    • In classify_handles_unicode_case_folding_and_verbatim_roots, it would be useful to also assert vc.classify_with("C:\\Games\\Title\\Data\\x.bin", id) (verbatim game_root_lc not hijacked by the C: mount) and a mixed / + \ Unicode case-folding input.
**@⁠0xKaji** on GitHub · 2026-11-23 23:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/316#issuecomment-7117397458) Reviewed commit `f0bd1ea` statically on Linux (not built or executed on Windows; assisted by T3 Code + Gemini 4 Neon). `strip_path_prefix_ci` looks sound: every slice index is on an ASCII `\` boundary within `abs`, so it eliminates the UTF-8 slicing panics and corrupted `rel` slices for length-changing case folds (`ẞ`, `İ`, `K`) without introducing regressions on standard paths. A few concrete items before moving this out of draft: 1. **Merge blockers (`CONTRIBUTING.md` / `PR checks`):** - `PR checks` is currently failing because `crates/xcl/src/vfs.rs` is runtime code and `**Regression run**` is missing the two `xcl-smoke v1` blocks (`main` and PR head `f0bd1ea`, clean working tree) from `scripts/smoke.ps1`. - Windows `cargo test --workspace -- --test-threads=4` counts (and green `CI`) are still needed in `**Tested**`. 2. **`strip_verbatim` (`crates/xcl/src/vfs.rs:102-113`) mishandles lowercase `\\?\unc\...` and `\??\UNC\...`:** - Pre-existing in `strip_verbatim`, but now also called from `Vfs::new` (`vfs.rs:192, 207, 210`). - `is_device` (`vfs.rs:157-160`) matches `\\?\` and `\??\` with ASCII case-insensitive `unc\`, whereas `strip_verbatim` only checks exact uppercase `"\\\\?\\UNC\\"`. - Concrete failing inputs: `\\?\unc\server\share\file.bin` and `\??\UNC\server\share\file.bin` bypass `is_device`, fall through to `strip_prefix("\\\\?\\")` / `strip_prefix("\\??\\")`, and become relative `"unc\\server\\share\\file.bin"` / `"UNC\\server\\share\\file.bin"`. That bypasses the `p.starts_with("\\\\")` UNC guard (`vfs.rs:286`) and resolves relative to CWD (misclassifying as `Target::Game` when CWD is inside `game_root`). - Stripping `\\?\` or `\??\` first and then checking `r.get(..4).is_some_and(|s| s.eq_ignore_ascii_case("UNC\\"))` would keep `strip_verbatim` consistent with `is_device` (fine either here or as a small follow-up PR). 3. **Minor non-blocking edge cases / test notes:** - In `strip_path_prefix_ci` (`vfs.rs:143`), `&abs[pos + 1..]` returns a leading `\` if `abs` has repeated separators after the root (e.g. `classify_with("C:\\Games\\Title\\\\Data\\a.bin", id)` → `rel: "\\Data\\a.bin"`). `GetFullPathNameW` collapses `\\` for normal paths, but `abs[pos + 1..].trim_start_matches('\\')` guarantees the `Target::Game` invariant unconditionally. - Pre-existing note (separate scope): if `game_root` is a drive root like `X:\` or `\\?\X:\`, `trim_sep` stores `"X:"`, so `original_path("")` returns `"X:"` (drive-relative CWD in Win32) instead of `"X:\\"`. - In `classify_handles_unicode_case_folding_and_verbatim_roots`, it would be useful to also assert `vc.classify_with("C:\\Games\\Title\\Data\\x.bin", id)` (verbatim `game_root_lc` not hijacked by the `C:` mount) and a mixed `/` + `\` Unicode case-folding input.
Author
Owner

@⁠regiumlepidi on GitHub · 2026-11-23 23:56 UTC · original

A Windows run for this draft, since Not tested says it has not been built or run on Windows yet: f0bd1ea merged onto current main db1ddb2 (clean merge): builds and passes, and the new test fails on main.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB, driver 617.42 (32.0.16.1742); also with XCL_ADAPTER=radeon (the Ryzen 7 9800X3D's RDNA2 iGPU, driver 32.0.21030.2001)
  • Ryzen 7 9800X3D, 48 GB, Windows 11 Pro 25H2, rustc 1.100.0 MSVC, DXC from Windows SDK 10.0.26100, debug
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4), no XCL_SAMPLE_* set
Build RTX 5070 Ti RDNA2 iGPU
main db1ddb2 666 passed, 0 failed, 41 ignored 666 passed, 0 failed, 41 ignored
f0bd1ea on db1ddb2 667 passed, 0 failed, 41 ignored 667 passed, 0 failed, 41 ignored

classify_handles_unicode_case_folding_and_verbatim_roots copied unchanged into main's vfs.rs fails at its first case, with the corrupted slice the description names:

assertion `left == right` failed: root="C:\\Games\\GROẞẞ" input="C:\\Games\\großß\\Data\\a.bin"
  left: Game { rel: "ta\\a.bin" }
 right: Game { rel: "Data\\a.bin" }

With this PR's vfs.rs it passes.

Not tested

  • scripts/smoke.ps1 (I have no Series title), so the Regression run blocks the PR check asks for still have to come from someone who has one.
  • The lowercase \\?\unc\ / \??\UNC\ case raised in the review above.

AI use: Claude Code with Claude Opus 5.5 ran the build and tests and wrote this comment; the numbers come from those runs.

**@⁠regiumlepidi** on GitHub · 2026-11-23 23:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/316#issuecomment-7117534789) A Windows run for this draft, since **Not tested** says it has not been built or run on Windows yet: `f0bd1ea` merged onto current `main` `db1ddb2` (clean merge): **builds and passes**, and the new test fails on `main`. **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB, driver 617.42 (32.0.16.1742); also with `XCL_ADAPTER=radeon` (the Ryzen 7 9800X3D's RDNA2 iGPU, driver 32.0.21030.2001) - Ryzen 7 9800X3D, 48 GB, Windows 11 Pro 25H2, rustc 1.100.0 MSVC, DXC from Windows SDK 10.0.26100, debug - `.\scripts\test.ps1` (`cargo test --workspace -- --test-threads=4`), no `XCL_SAMPLE_*` set | Build | RTX 5070 Ti | RDNA2 iGPU | |---|---|---| | `main` `db1ddb2` | 666 passed, 0 failed, 41 ignored | 666 passed, 0 failed, 41 ignored | | `f0bd1ea` on `db1ddb2` | 667 passed, 0 failed, 41 ignored | 667 passed, 0 failed, 41 ignored | `classify_handles_unicode_case_folding_and_verbatim_roots` copied unchanged into `main`'s `vfs.rs` fails at its first case, with the corrupted slice the description names: ``` assertion `left == right` failed: root="C:\\Games\\GROẞẞ" input="C:\\Games\\großß\\Data\\a.bin" left: Game { rel: "ta\\a.bin" } right: Game { rel: "Data\\a.bin" } ``` With this PR's `vfs.rs` it passes. **Not tested** - `scripts/smoke.ps1` (I have no Series title), so the **Regression run** blocks the PR check asks for still have to come from someone who has one. - The lowercase `\\?\unc\` / `\??\UNC\` case raised in the review above. AI use: Claude Code with Claude Opus 5.5 ran the build and tests and wrote this comment; the numbers come from those runs.
Author
Owner

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

Thanks @⁠0xKaji and @⁠regiumlepidi! Rebased onto main (a6f5f7a, commit ce99a57) and applied the review items: strip_verbatim now handles \?\ and ??\ UNC prefixes case-insensitively, strip_path_prefix_ci trims repeated separators after the root, and added the extra UNC, mixed-separator, and verbatim game_root test cases.

**@⁠Michael-Glaser** on GitHub · 2026-11-24 00:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/316#issuecomment-7117930406) Thanks @⁠0xKaji and @⁠regiumlepidi! Rebased onto main (a6f5f7a, commit ce99a57) and applied the review items: strip_verbatim now handles \\?\ and \??\ UNC prefixes case-insensitively, strip_path_prefix_ci trims repeated separators after the root, and added the extra UNC, mixed-separator, and verbatim game_root test cases.
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 02:55 UTC · original

Regression run of a9ce85ea 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: a9ce85eaf70e082b55b3b0180755e39c5a79418c
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1634 (PresentX 1635)
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 02:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/316#issuecomment-7151360129) Regression run of `a9ce85ea` 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: a9ce85eaf70e082b55b3b0180755e39c5a79418c gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1634 (PresentX 1635) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 14:29 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 14:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/316#issuecomment-7165350589) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
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/316/head:github-bot/gh-316'
git switch 'github-bot/gh-316'

Merge

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