Skip to content

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

Open
Michael-Glaser wants to merge 1 commit into
xcl-dev:mainfrom
Michael-Glaser:fix/vfs-unicode-and-verbatim-root
Open

Michael-Glaser wants to merge 1 commit into
xcl-dev:mainfrom
Michael-Glaser:fix/vfs-unicode-and-verbatim-root

Conversation

@Michael-Glaser

Copy link
Copy Markdown

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

@0xKaji

0xKaji commented Nov 23, 2026

Copy link
Copy Markdown

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.

@regiumlepidi

Copy link
Copy Markdown
Contributor

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.

@Michael-Glaser
Michael-Glaser force-pushed the fix/vfs-unicode-and-verbatim-root branch from f0bd1ea to ce99a57 Compare November 24, 2026 00:16
@Michael-Glaser

Copy link
Copy Markdown
Author

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.

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)
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
… upstream xcl-dev#316)

Per-component game-root match (strip_path_prefix_ci) so folding-expanding
chars (ẞ/İ/K) keep the input's rel casing instead of slicing a lowercased
string at a stale byte offset; strip_verbatim UNC-case-insensitive; Vfs::new
roots normalised through strip_verbatim. Linux reconciliations: matcher is
separator-agnostic (host paths use /), host_path_string strips before
separator replacement, UNC classify arm uses the same helper. Test ports the
upstream table (Windows legs verbatim, Linux legs via UNC/temp roots since
untranslated drive paths Reject).
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…(port upstream xcl-dev#1560, reconciled)

Upstream xcl-dev#1560 base predates Reject/OpenCommit/write_lock/GENERIC_READ,
the Linux norm/logical split, the xcl-dev#316 sep-agnostic matcher and the xcl-dev#1170
clamp, so this ports concepts + 5 tests instead of going verbatim. Linux
keeps its twin layers (checked_*/ensure_mount_contained, host_path_string,
below_mount clamp: mount-escape '..' stays in-mount vs upstream Game '..').

Failing-first E0277 x18 pre-fix; 5/5 new tests green. Lib 631/0/1 (+5).
Title 12 GPU-only FAILs byte-identical to baseline; retail SIGSEGV
+0x2237320 HOLDS, M1-RE TERMINAL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants