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

Open
opened 2026-11-26 04:20:04 +00:00 by github-bot · 6 comments
Owner

@⁠mastrr9 on GitHub · 2026-11-23 23:27 UTC · original

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

**@⁠mastrr9** on GitHub · 2026-11-23 23:27 UTC · [original](https://github.com/xcl-dev/xcl/issues/325) `dec` in `crates/xcl/src/hle/xgameruntime/gamesave.rs` (line 100 on `main` `85bdf21`) slices `&file[i + 1..i + 3]` by byte index: ```rust 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:04 +00:00
Author
Owner

@⁠Amzi-01 on GitHub · 2026-11-24 00:16 UTC · original

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

**@⁠Amzi-01** on GitHub · 2026-11-24 00:16 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7117892606) 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).
Author
Owner

@⁠raulmesa96 on GitHub · 2026-11-24 00:37 UTC · original

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

**@⁠raulmesa96** on GitHub · 2026-11-24 00:37 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7118269857) 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.)*
Author
Owner

@⁠Grimkaaah on GitHub · 2026-11-24 01:08 UTC · original

Opened https://github.com/ivall/xcl/pull/514 — decode %XX from bytes only (no str slice panic, no %+1).

**@⁠Grimkaaah** on GitHub · 2026-11-24 01:08 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7118791152) Opened https://github.com/ivall/xcl/pull/514 — decode %XX from bytes only (no str slice panic, no %+1).
Author
Owner

@⁠PurpleDizzy on GitHub · 2026-11-24 01:53 UTC · original

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

  • #442: Correct. The smallest change that still has an end-to-end test of the abort path. The enumeration test builds a Provider directly in its own temp dir. That is safe without ASYNC_TEST_LOCK, because enumeration runs synchronously and does not use XAsync. Its only blocker is that it is still a draft.
  • #448: Correct, and it has the widest test cases. One defect: the new tests are inserted between the existing doc comment /// Names Windows does not keep as file names … and #[test] fn names_windows_would_change_round_trip. That doc comment now sits above the new test, and the existing test is left without one. Moving the two existing doc-comment lines back down fixes it.
  • #457: Correct, and its unit cases are good (x%4€y covers a multi-byte character in the second digit's position). It has no main-side smoke block, so PR description fails. It also has no end-to-end test.
  • #514: Correct, but it duplicates the others: it was opened after #442, #448 and #457, which already cover this issue. It has no Tested counts, no smoke blocks and fewer tests. hex_nibble's _ => 0 arm is unreachable after the is_ascii_hexdigit check. It also adds a blank line before the final } of the test module.

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

**@⁠PurpleDizzy** on GitHub · 2026-11-24 01:53 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7119542773) **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** - **#442**: Correct. The smallest change that still has an end-to-end test of the abort path. The enumeration test builds a `Provider` directly in its own temp dir. That is safe without `ASYNC_TEST_LOCK`, because enumeration runs synchronously and does not use XAsync. Its only blocker is that it is still a draft. - **#448**: Correct, and it has the widest test cases. One defect: the new tests are inserted between the existing doc comment `/// Names Windows does not keep as file names …` and `#[test] fn names_windows_would_change_round_trip`. That doc comment now sits above the new test, and the existing test is left without one. Moving the two existing doc-comment lines back down fixes it. - **#457**: Correct, and its unit cases are good (`x%4€y` covers a multi-byte character in the second digit's position). It has no main-side smoke block, so `PR description` fails. It also has no end-to-end test. - **#514**: Correct, but it duplicates the others: it was opened after #442, #448 and #457, which already cover this issue. It has no **Tested** counts, no smoke blocks and fewer tests. `hex_nibble`'s `_ => 0` arm is unreachable after the `is_ascii_hexdigit` check. It also adds a blank line before the final `}` of the test module. **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.)
Author
Owner

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

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:

  • #448: the new test went in between the existing doc comment ("Names Windows does not keep as file names …") and names_windows_would_change_round_trip. That comment now sits on dec_keeps_bad_escapes_literal, and the old test has lost its doc. Its enumeration test also creates the provider through XGameSaveInitializeProvider. It then removes only the container, so each run leaves %TEMP%\xcl_unit_data\gamesave\xcl-test-325-<pid> behind. Its round-trip loop (enc → dec over device names, a trailing dot, CJK) covers the most of the four.
  • #442: the enumeration test builds a Provider on its own temp root and deletes the whole root afterwards. It leaves nothing behind and does not depend on the provider's data folder.
  • #457, #514: the fix is fine, but the description check fails (#457 has one smoke block, #514 has none). As things stand they cannot be merged.

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.

**@⁠lordon1a** on GitHub · 2026-11-24 03:47 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7121432929) 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: - **#448**: the new test went in between the existing doc comment ("Names Windows does not keep as file names …") and `names_windows_would_change_round_trip`. That comment now sits on `dec_keeps_bad_escapes_literal`, and the old test has lost its doc. Its enumeration test also creates the provider through `XGameSaveInitializeProvider`. It then removes only the container, so each run leaves `%TEMP%\xcl_unit_data\gamesave\xcl-test-325-<pid>` behind. Its round-trip loop (`enc` → `dec` over device names, a trailing dot, CJK) covers the most of the four. - **#442**: the enumeration test builds a `Provider` on its own temp root and deletes the whole root afterwards. It leaves nothing behind and does not depend on the provider's data folder. - **#457, #514**: the fix is fine, but the description check fails (#457 has one smoke block, #514 has none). As things stand they cannot be merged. 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.
Author
Owner

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

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.

**@⁠pickles976** on GitHub · 2026-11-24 04:23 UTC · [original](https://github.com/xcl-dev/xcl/issues/325#issuecomment-7121968202) 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`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.