Skip to content

XGameSave: a save file name with a non-ASCII character after '%' panics in an extern "system" call #325

In review

Description

@mastrr9

dec in crates/xcl/src/hle/xgameruntime/gamesave.rs (line 100 on main 85bdf21) slices &file[i + 1..i + 3] by byte index:

if b[i] == b'%' && i + 2 < b.len() {
    if let Ok(v) = u8::from_str_radix(&file[i + 1..i + 3], 16) {

When a name in the save folder has % followed by an ASCII byte and then a multi-byte UTF-8 character, the slice ends inside that character and panics (end byte index 3 is not a char boundary). dec runs on every directory and file name in the save folder during enumeration and reads, from extern "system" functions, where an unwinding panic aborts the process. XCL's own enc never writes such a name, so this requires a file placed there externally (e.g. copied by hand, restored from backup, or left by another tool).

Repro (clean-room, Linux):
Copied dec unchanged into a standalone test: dec("%a\u{e9}") panics.

Suggested fix:
Decode directly from b[i + 1] and b[i + 2], requiring both to be ASCII hex digits (u8::is_ascii_hexdigit), without slicing the &str. That also stops from_str_radix from accepting a leading sign such as "%+1". Add unit tests covering "%a\u{e9}" and "%+1".

Not tested: on Windows.

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

Activity

  1. Amzi-01 commented on Nov 24, 2026

    @Amzi-01

    I'll take this. Plan: dec decodes %XY from b[i + 1] and b[i + 2] only when both are ASCII hex digits (no &str slicing, no from_str_radix), so %a\u{e9} stays literal instead of panicking and %+1 is no longer decoded to 0x01. Unit tests for both cases plus a round-trip with enc, and @jleybourne's enumeration repro (%a\u{e9} folder through XGameSaveEnumerateContainerInfo, no abort). Windows, RTX 3060 for the GPU suite. AI-assisted (Claude Code).

  2. raulmesa96 commented on Nov 24, 2026

    @raulmesa96

    Fix in #457: dec now reads the two digits after % as bytes and requires both to be hex digits, so %aé no longer panics and %+1 / %-1 are no longer decoded. It comes with a unit test that panicked before the fix; the full suite passes on an RTX 3060 (677 passed, 0 failed on a6f5f7a).

    I have no Xbox title to run scripts/smoke.ps1 on, so the PR has no regression run yet. If anyone who can run one has a minute, the two xcl-smoke blocks (main and the PR's head) would unblock it.

    (Claude Code, Claude Opus 5.5, helped write this.)

  3. Grimkaaah commented on Nov 24, 2026

    @Grimkaaah

    Opened #514 — decode %XX from bytes only (no str slice panic, no %+1).

  4. PurpleDizzy commented on Nov 24, 2026

    @PurpleDizzy

    Comparison of the four open PRs for this issue (#442, #448, #457, #514)

    All four make the same fix: dec reads the two characters after % as bytes and decodes them only if both are ASCII hex digits. That fixes both cases in the issue, %aé (the panic) and %+1 (the sign). I read the four diffs against main (508a0c7) and found no difference in what the fixed dec returns. The PRs differ in their tests, their readiness and the regression runs.

    #442 #448 #457 #514
    Opened (UTC, Nov 24) 00:21 (first) 00:25 00:32 01:08
    Draft yes no yes no
    PR description check pass pass fail fail
    xcl-smoke blocks (main + head) 2 2 1 0
    Suite counts in Tested 672 / 0 / 41, 0 skipped 678 / 0 / 41, 2 skipped 677 / 0 / 41 none
    Unit test of dec 4 asserts incl. an enc round trip 7 asserts + 7-name enc round trip 8 asserts + 5-name round trip 5 asserts + 1 round trip
    Test through XGameSaveEnumerateContainerInfo (the abort path) yes, own temp root, cleaned up yes, real provider init under ASYNC_TEST_LOCK no no

    Notes per PR

    Suggestion: merge #442 once it is marked ready for review. It was first, has no defects I could find, has both regression blocks and tests the abort path. If @Amzi-01 moves the misplaced doc comment, #448 is an equally good alternative with broader tests. Either way, #457 and #514 can be closed as duplicates. #448's round-trip names (sauvegarde été, 保存1, 100%) would be a nice addition to whichever PR is merged.

    Not tested: I compared the diffs by reading them. I did not build or run any of the four branches.

    (Claude Code, Opus 5.5, helped write this.)

  5. lordon1a commented on Nov 24, 2026

    @lordon1a

    Comparison of the four open PRs for #325 (#442, #448, #457, #514), to help pick one.

    All four make the same fix: dec reads the two hex digits from bytes instead of slicing the &str, and a sign is no longer taken as a digit. The decoded output is the same in all four for every input I tried. Each diff touches only crates/xcl/src/hle/xgameruntime/gamesave.rs. I read all four diffs before running them: no network, process, build.rs or file access outside the test temp folders.

    PR head PR description check xcl-smoke blocks merges into main f4ce27c
    #442 e310370 pass 2 clean
    #448 df34b7e pass 2 clean
    #457 aebea99 fail 1 clean
    #514 4a17a0a fail 0 clean

    cargo test -p xcl --lib -- --test-threads=4 on each head: #442 632 passed, #448 638 passed, #457 637 passed, #514 638 passed. All had 0 failed and 21 ignored. The counts differ because the PRs start from different main commits.

    Negative control: with main's dec put back, the new tests in #442 and #448 fail. The enumeration tests abort the test process at the panic across extern "system", which is #325 itself.

    Points:

    Suggestion: merge #442, which was opened first, passes the checks and leaves nothing behind. #448's round-trip cases could be added to #442's test. Close the other three as duplicates.

    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, --lib tests only. Not tested: the MSVC toolchain, cargo test --workspace, smoke runs.

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

  6. pickles976 commented on Nov 24, 2026

    @pickles976

    Empirical adjudication of the four PRs on this issue, run 2026-11-24 (Linux, x86_64-pc-windows-gnu cross-build, tests under Wine 9). Canonical battery, added as unit tests to main and each PR head: dec("%a\u{e9}") (char-boundary case), dec("%+1") (signed form), dec("%41A") ("AA"), dec("x%4y%zz") (literals).

    head %a\u{e9} %+1 %41A x%4y%zz battery PR-description check
    main panics at gamesave.rs:100 (confirms the report exactly) decodes to 0x01 (second defect confirmed) ok ok 2/4 —
    #442 ok ok ok ok 4/4 ✅ success
    #448 ok ok ok ok 4/4 ✅ success
    #457 ok ok ok ok 4/4 ❌ failure
    #514 ok ok ok ok 4/4 ❌ failure

    All four converge on the same fix shape (decode the two digits from b[i+1]/b[i+2] with an ASCII-hexdigit check, no &str slicing, no from_str_radix) and are behaviourally equivalent under the battery; diffs are 33–54 added lines in gamesave.rs only.

    Recommendation for the batch merge: #448 — behaviourally equal, cleanest shape (named hex_digit helper rather than a closure or inline cast), smallest deletion count (2 lines), and its description check is green like #442's; #457/#514 are one description-fix away but duplicative regardless. Suggest: merge #448 (or #442 if the maintainer prefers its inline style), close the other three as duplicates — all four authors independently verified the same two defects.

    Repro of the harness: cross-build per #520 (llvm-mingw linker, static libunwind.a first in the search path), cargo test -p xcl --lib --target x86_64-pc-windows-gnu zz_325_review with CARGO_TARGET_…_RUNNER=wine.

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