Skip to content

XGameSave: a long valid container name makes every save to it fail #326

Backlog

Description

@mastrr9

XGameSaveCreateContainer stores a container in a folder named enc(name) under the provider root (crates/xcl/src/hle/xgameruntime/gamesave.rs on main 85bdf21: enc() at line 73, folder created in apply() at line 567). valid_container_name_length (line 254) allows up to 256 characters, matching the GDK maximum, but Windows caps each path component at 255 characters, and enc() expands every / (which the GDK allows in container names) into %2F (3 characters).

Examples accepted by XGameSaveCreateContainer (S_OK) whose folder cannot be created:

Container name Name length enc(name) length
256 ASCII letters 256 256
"a/" × 85 + "x" 171 341

Because XGameSaveCreateContainer returns S_OK, create_dir_all later fails in apply() and every XGameSaveSubmitUpdate to that container returns E_FAIL.

Repro (clean-room, Linux):
Copied enc() unchanged into a standalone program and called create_dir_all (Linux shares the 255-byte component limit): both the 256-char and 341-char names failed with File name too long.

Suggested fix:
When enc(name) exceeds ~200 characters, store the container under a shortened folder name (e.g. truncated prefix + hash of the full name) and persist the exact container name in a metadata file inside the folder for each_container to read back. Separately, enforcing the GDK's allowed character set in XGameSaveCreateContainer (returning E_GS_INVALID_CONTAINER_NAME for disallowed characters like spaces or :) would match console behavior more closely.

Not tested: on Windows or with a game.

AI use: Initially found and reproduced with Claude Code; re-verified against main (85bdf21) with Antigravity (Gemini 4 Neon).

Activity

  1. Grimkaaah commented on Nov 24, 2026

    @Grimkaaah

    Claim — shortened folder when enc(name) exceeds the path component limit

    Plan: When enc(name) is longer than 255 bytes (Windows/Linux component max), store the container under a short folder (xcl- + SHA-256 prefix of the encoded name) and write the exact container name into a metadata file inside that folder so each_container / enumeration still round-trip. Keep valid_container_name_length at the GDK 256-char max so XGameSaveCreateContainer stays S_OK for valid names; only the on-disk folder is shortened. Unit tests for the 256-ASCII and "a/"×85+"x" cases (folder creates, enumerate returns the original name, submit works).

    AI-assisted (Cursor / Composer). Working now.

  2. DavidM1911 commented on Nov 24, 2026

    @DavidM1911
    Contributor

    I'll take this one. Plan: container_dir_name() returns enc(name) while it fits (~200 chars, matching the suggestion — longer encodings never fit a Windows path component in practice anyway), otherwise ~xcllong.<sip-hash> (the ~ can't appear in enc() output, so no collision). The real name goes in a name file inside the folder, written atomically by apply() (self-healing, since apply gets the name through the Update), and each_container reads it back for ~xcllong.* dirs. delete_path/CreateContainer use the same mapping. Unit test: a 256-char name and an "a/"-heavy name round-trip through create → submit → enumerate → delete.

  3. Grimkaaah commented on Nov 24, 2026

    @Grimkaaah

    Opened a fix PR: uses a hashed ~xclc.<fnv> folder when enc(name) is too long, and stores the exact name in container_name for enumeration. Tests cover the 256-char case from the issue.

  4. added 4 commits that reference this issue on Nov 24, 2026
    08e3c88
    2fd6c7b
    c1d0877
    c75284c
  5. lordon1a commented on Nov 24, 2026

    @lordon1a

    Comparison of the open PRs for #326 (#481, #492; #623 was closed by its author in favour of these), to help pick one.

    Both store a container whose enc(name) is longer than 200 characters under a hashed folder and keep the real name in a file inside it. Both merge cleanly into main f4ce27c and touch only gamesave.rs. I read the diffs before running them and found nothing outside the save folder and the test temp folders. Their own tests pass on the merge with main.

    PR head PR description check xcl-smoke hash
    #481 f9947a0 fail (no smoke blocks) 0 FNV-1a 64, written out in the PR
    #492 560368c pass 2 std::collections::hash_map::DefaultHasher

    Points:

    Suggestion: #492 passes the checks and keeps the change to hashed folders only. It can be merged once DefaultHasher is replaced by a fixed hash (FNV-1a as in #481). Then close #481. #722 is a separate fix and works with either.

    Tested on an i7-12700H with an RTX 3070 Ti Laptop, Windows 11 build 26200. Toolchain: rustc 1.100.0 x86_64-pc-windows-gnullvm, debug, cargo test -p xcl --lib gamesave on each PR merged into main f4ce27c, plus a 190-character-name save test. Not tested: the MSVC toolchain, cargo test --workspace, smoke runs.

    Written with Claude Code (Claude Opus 5.5). I checked each point against the diffs and the runs above.

  6. pickles976 commented on Nov 24, 2026

    @pickles976

    Adjudication of the two PRs (design review + one measurement, 2026-11-24):

    Both converge on the right shape — names whose enc() fits stay in their current folder (existing saves untouched, no migration), only over-long names move to a hash folder, and both handle the enumeration read-back (XGameSaveEnumerateContainerInfo must report the container's name, not the hash folder). Neither can collide with an enc() folder (~ is percent-encoded by enc, so both prefixes are reserved).

    head hash prefix read-back description check
    #481 FNV-1a 64 (deterministic by construction) ~… stored_container_name() via the apply-signature plumbing ❌ failure
    #492 DefaultHasher::new() (SipHash-1-3, fixed seed) ~xcllong. strip-prefix in enumeration, with enumerate-based tests ✅ success

    The measurement I added: #492's choice of DefaultHasher::new() looks risky — a randomly-seeded hasher would give a different folder every process launch and silently orphan long-name saves across game sessions (worse than the original bug). It isn't: DefaultHasher::new() is deterministically seeded — I hashed the issue's ("a/"*85)+"x" case in 10 separate processes, 10/10 identical — so #492's folder mapping is run-stable. #481 doesn't need the argument (FNV has no seed at all), but its description check is red and its apply()-signature change touches more surface than the defect needs.

    Recommendation: merge #492; #481's author's stored_container_name framing is the more future-proof read-back, worth cherry-picking if LONG_PREFIX ever grows — as-is it's a description-fix and a smaller-diff duplicate away from #492.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions