XGameSave: a save whose blob path passes MAX_PATH fails (MoveFileExW without the verbatim prefix) #722

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

@⁠lordon1a on GitHub · 2026-11-24 04:04 UTC · original

replace_file (crates/xcl/src/hle/xgameruntime/gamesave.rs) passes the plain paths to MoveFileExW. Unless a path is in its \\?\ form, MoveFileExW refuses it once it reaches 260 characters, with ERROR_PATH_NOT_FOUND (3). The temp file written just before it goes through std::fs, which adds \\?\ itself. So the write works and only the final move fails, and every save to such a container returns E_FAIL.

With the data folder under %LOCALAPPDATA%\XCL\<title>\gamesave\<id>\, a blob path passes 260 characters at a container name of about 170 characters. The GDK allows 256. This is separate from #326: the hashed folders in #481 / #492 start only past 200 characters of enc(name), so names of roughly 170–200 characters still fail. I checked this on each of those PRs merged with main f4ce27c: a 190-character container name gives a 267-character container folder in the test data folder, and XGameSaveSubmitUpdate returns E_FAIL.

Measured on main, in a unit test (same folder, same temp file):

len 284  create_dir_all ok  std::fs::write ok  replace_file (MoveFileExW) Err(3)  std::fs::rename ok
len 254  create_dir_all ok  std::fs::write ok  replace_file (MoveFileExW) ok

Failing test (in gamesave.rs's mod tests):

/// A blob whose path is longer than MAX_PATH (a long container name under the data folder)
/// is saved: the files are written through Rust's `std::fs`, which takes long paths, and
/// the final move took only paths under 260 characters (ERROR_PATH_NOT_FOUND past them).
#[test]
fn a_blob_past_max_path_is_saved() {
    let root = std::env::temp_dir().join(format!("xcl-gamesave-long-path-{}", std::process::id()));
    let dir = root.join("a".repeat(200));
    let ops = [("data".to_string(), Some(b"v".to_vec()))];
    let hr = apply(&dir, Some("Long"), &ops);
    let data = std::fs::read(dir.join("b").join("data")).ok();
    let display = std::fs::read_to_string(dir.join("display")).ok();
    let _ = std::fs::remove_dir_all(&root);
    assert!(dir.join("b").join("data").as_os_str().len() > 260);
    assert_eq!(hr, S_OK);
    assert_eq!(data.as_deref(), Some(&b"v"[..]));
    assert_eq!(display.as_deref(), Some("Long"));
}

On main it fails with left: -2147467259 (E_FAIL).

Proposed fix: give both paths their \\?\ form (or \\?\UNC\ for a share) before the call:

+        // MoveFileExW takes paths past MAX_PATH only in their "\\?\" form (std::fs, which
+        // wrote the temp file, adds it itself): a long container name otherwise fails here
+        let verbatim = |p: &Path| -> std::io::Result<Vec<u16>> {
+            let abs = std::path::absolute(p)?;
+            let s = abs.as_os_str().to_string_lossy();
+            let v = if s.starts_with(r"\\?\") {
+                abs.into_os_string()
+            } else if let Some(unc) = s.strip_prefix(r"\\") {
+                format!(r"\\?\UNC\{unc}").into()
+            } else {
+                format!(r"\\?\{s}").into()
+            };
+            Ok(v.encode_wide().chain(std::iter::once(0)).collect())
+        };
-        let src: Vec<u16> = tmp.as_os_str().encode_wide().chain(std::iter::once(0)).collect();
-        let dst: Vec<u16> = dest.as_os_str().encode_wide().chain(std::iter::once(0)).collect();
+        let src = verbatim(tmp)?;
+        let dst = verbatim(dest)?;

Branch with the test and the fix, one commit on main f4ce27c: https://github.com/lordon1a/xcl/tree/gamesave-long-path

With the fix, the new test passes, and so does a save through the API (XGameSaveCreateContainer with a 190-character name, a blob write, XGameSaveSubmitUpdate returns S_OK). cargo test -p xcl --lib -- --test-threads=4 gives 661 passed, 0 failed, 21 ignored. The fix touches the same function as #543 (#324) but not the same lines, so whichever lands second needs a small rebase.

Tested

  • i7-12700H, RTX 3070 Ti Laptop, Windows 11 build 26200, NTFS. Long paths are not enabled in the registry (the test binary is not long-path aware).
  • rustc 1.100.0 x86_64-pc-windows-gnullvm, debug, --lib tests only

Not tested

  • the MSVC toolchain, cargo test --workspace
  • a UNC data folder (the \\?\UNC\ branch is not exercised)
  • scripts/smoke.ps1: I have no title. This is a runtime change, so a PR needs someone who can make the two xcl-smoke blocks; the branch is ready for that.

AI use

  • Claude Code, Claude Opus 5.5: found this while reviewing the #326 PRs, wrote the test, the fix and this issue. I checked the test failing on main and passing with the fix.
**@⁠lordon1a** on GitHub · 2026-11-24 04:04 UTC · [original](https://github.com/xcl-dev/xcl/issues/722) `replace_file` (`crates/xcl/src/hle/xgameruntime/gamesave.rs`) passes the plain paths to `MoveFileExW`. Unless a path is in its `\\?\` form, `MoveFileExW` refuses it once it reaches 260 characters, with `ERROR_PATH_NOT_FOUND` (3). The temp file written just before it goes through `std::fs`, which adds `\\?\` itself. So the write works and only the final move fails, and every save to such a container returns `E_FAIL`. With the data folder under `%LOCALAPPDATA%\XCL\<title>\gamesave\<id>\`, a blob path passes 260 characters at a container name of about 170 characters. The GDK allows 256. This is separate from #326: the hashed folders in #481 / #492 start only past 200 characters of `enc(name)`, so names of roughly 170–200 characters still fail. I checked this on each of those PRs merged with `main` f4ce27c: a 190-character container name gives a 267-character container folder in the test data folder, and `XGameSaveSubmitUpdate` returns `E_FAIL`. Measured on `main`, in a unit test (same folder, same temp file): ``` len 284 create_dir_all ok std::fs::write ok replace_file (MoveFileExW) Err(3) std::fs::rename ok len 254 create_dir_all ok std::fs::write ok replace_file (MoveFileExW) ok ``` **Failing test** (in `gamesave.rs`'s `mod tests`): ```rust /// A blob whose path is longer than MAX_PATH (a long container name under the data folder) /// is saved: the files are written through Rust's `std::fs`, which takes long paths, and /// the final move took only paths under 260 characters (ERROR_PATH_NOT_FOUND past them). #[test] fn a_blob_past_max_path_is_saved() { let root = std::env::temp_dir().join(format!("xcl-gamesave-long-path-{}", std::process::id())); let dir = root.join("a".repeat(200)); let ops = [("data".to_string(), Some(b"v".to_vec()))]; let hr = apply(&dir, Some("Long"), &ops); let data = std::fs::read(dir.join("b").join("data")).ok(); let display = std::fs::read_to_string(dir.join("display")).ok(); let _ = std::fs::remove_dir_all(&root); assert!(dir.join("b").join("data").as_os_str().len() > 260); assert_eq!(hr, S_OK); assert_eq!(data.as_deref(), Some(&b"v"[..])); assert_eq!(display.as_deref(), Some("Long")); } ``` On `main` it fails with `left: -2147467259` (`E_FAIL`). **Proposed fix**: give both paths their `\\?\` form (or `\\?\UNC\` for a share) before the call: ```diff + // MoveFileExW takes paths past MAX_PATH only in their "\\?\" form (std::fs, which + // wrote the temp file, adds it itself): a long container name otherwise fails here + let verbatim = |p: &Path| -> std::io::Result<Vec<u16>> { + let abs = std::path::absolute(p)?; + let s = abs.as_os_str().to_string_lossy(); + let v = if s.starts_with(r"\\?\") { + abs.into_os_string() + } else if let Some(unc) = s.strip_prefix(r"\\") { + format!(r"\\?\UNC\{unc}").into() + } else { + format!(r"\\?\{s}").into() + }; + Ok(v.encode_wide().chain(std::iter::once(0)).collect()) + }; - let src: Vec<u16> = tmp.as_os_str().encode_wide().chain(std::iter::once(0)).collect(); - let dst: Vec<u16> = dest.as_os_str().encode_wide().chain(std::iter::once(0)).collect(); + let src = verbatim(tmp)?; + let dst = verbatim(dest)?; ``` Branch with the test and the fix, one commit on `main` f4ce27c: https://github.com/lordon1a/xcl/tree/gamesave-long-path With the fix, the new test passes, and so does a save through the API (`XGameSaveCreateContainer` with a 190-character name, a blob write, `XGameSaveSubmitUpdate` returns `S_OK`). `cargo test -p xcl --lib -- --test-threads=4` gives 661 passed, 0 failed, 21 ignored. The fix touches the same function as #543 (#324) but not the same lines, so whichever lands second needs a small rebase. **Tested** - i7-12700H, RTX 3070 Ti Laptop, Windows 11 build 26200, NTFS. Long paths are not enabled in the registry (the test binary is not long-path aware). - rustc 1.100.0 `x86_64-pc-windows-gnullvm`, debug, `--lib` tests only **Not tested** - the MSVC toolchain, `cargo test --workspace` - a UNC data folder (the `\\?\UNC\` branch is not exercised) - `scripts/smoke.ps1`: I have no title. This is a runtime change, so a PR needs someone who can make the two `xcl-smoke` blocks; the branch is ready for that. **AI use** - Claude Code, Claude Opus 5.5: found this while reviewing the #326 PRs, wrote the test, the fix and this issue. I checked the test failing on `main` and passing with the fix.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:35 +00:00
Author
Owner

@⁠ldeep98154deep-jpg on GitHub · 2026-11-24 04:13 UTC · original

Claiming this

**@⁠ldeep98154deep-jpg** on GitHub · 2026-11-24 04:13 UTC · [original](https://github.com/xcl-dev/xcl/issues/722#issuecomment-7121817944) Claiming this
This discussion has been locked. Commenting is limited to contributors.
No description provided.