XGameSave: a "%" in a save folder name is decoded by bytes, not by slicing the str (#325) #442

Closed
github-bot wants to merge 1 commit from gh-pr/442/head into gh-pr/442/base
Owner

@⁠Rednaxeh on GitHub · 2026-11-24 00:21 UTC · original
Rednaxeh:gamesave-percent-decode → main · +37 −6 · 1 files · 1 commits · closed without merging

dec in gamesave.rs turned %XX back into a byte by slicing the name at byte offsets and parsing with from_str_radix. A folder or file name with %, a hex digit and then a multi-byte character (%aé) made the slice end inside the character and panic; dec runs on every name in the save provider's folder from extern "system" entry points, so the panic cannot unwind and XGameSaveEnumerateContainerInfo ended the title with 0xC0000409. XCL's enc never writes such a name, but a save folder restored from a backup or edited by hand can hold one. from_str_radix also accepted a sign, so %+1 decoded to the byte 1. Fixes #325.

What is in it

  • crates/xcl/src/hle/xgameruntime/gamesave.rs: dec reads the two bytes after % and decodes them only when both are hex digits; anything else is kept as it is. Two tests in the file's mod tests: dec_keeps_a_percent_without_two_hex_digits (%aé, %+1, a trailing %, and an enc / dec round trip) and a_container_folder_named_percent_then_multibyte_is_enumerated (a hand-placed %aé container folder goes through XGameSaveEnumerateContainerInfo).

Tested

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 7 7800X3D, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug (release for the regression run); DXC 1.9.2602.17.
  • Without the fix (the tests on main's dec): dec_keeps_a_percent_without_two_hex_digits panics at gamesave.rs:100:52 (end byte index 3 is not a char boundary; it is inside 'é'); a_container_folder_named_percent_then_multibyte_is_enumerated aborts the test process (thread caused non-unwinding panic. aborting., exit code 0xC0000409).
  • With the fix: cargo test -p xcl --lib -- hle::xgameruntime::gamesave::: 12 passed, 0 failed.
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) with XCL_REQUIRE_GPU=wave64,mesh: 672 passed, 0 failed, 41 ignored, 0 SKIPPED.

Regression run
scripts/smoke.ps1 -Game <folder> on a retail title, release builds, no uncommitted changes, one after the other on the machine above (a warm-up run of main first, not shown). The gpu: line names the wrong adapter (the script's known issue); the GPU was the RX 7800 XT. Both blocks unedited.

main 3516080:

xcl-smoke v1
commit: 3516080d53daac0f7749b5c02bc9b1e371479557
gpu: Meta Virtual Monitor
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 393 (PresentX 393)
presents per 2 s (last 3): 9 8 8
device removals: 0
crashes: 0
peak commit: 15296 MB

this PR's head e310370:

xcl-smoke v1
commit: e3103705a1770108b3a46886c9b5a40280077439
gpu: Meta Virtual Monitor
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 395 (PresentX 395)
presents per 2 s (last 3): 8 8 9
device removals: 0
crashes: 0
peak commit: 15290 MB

Not tested

  • NVIDIA / Intel; a title whose save folder holds such a name (none known: the name has to be placed there by something other than XCL). The regression run does not reach the save path (no input in 60 s; the title is in its intro movie, whose 8 presents / 2 s on this card are the known cost discussed on #283): it checks that nothing else changed.

AI use

  • Claude Code with Claude Fable 5.1: wrote the change, the tests and this description from the issue and the Windows confirmation on it; the runs are from the machine above.

🤖 Generated with Claude Code

**@⁠Rednaxeh** on GitHub · 2026-11-24 00:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/442) `Rednaxeh:gamesave-percent-decode` → `main` · +37 −6 · 1 files · 1 commits · closed without merging `dec` in `gamesave.rs` turned `%XX` back into a byte by slicing the name at byte offsets and parsing with `from_str_radix`. A folder or file name with `%`, a hex digit and then a multi-byte character (`%aé`) made the slice end inside the character and panic; `dec` runs on every name in the save provider's folder from `extern "system"` entry points, so the panic cannot unwind and `XGameSaveEnumerateContainerInfo` ended the title with `0xC0000409`. XCL's `enc` never writes such a name, but a save folder restored from a backup or edited by hand can hold one. `from_str_radix` also accepted a sign, so `%+1` decoded to the byte 1. Fixes #325. **What is in it** - `crates/xcl/src/hle/xgameruntime/gamesave.rs`: `dec` reads the two bytes after `%` and decodes them only when both are hex digits; anything else is kept as it is. Two tests in the file's `mod tests`: `dec_keeps_a_percent_without_two_hex_digits` (`%aé`, `%+1`, a trailing `%`, and an `enc` / `dec` round trip) and `a_container_folder_named_percent_then_multibyte_is_enumerated` (a hand-placed `%aé` container folder goes through `XGameSaveEnumerateContainerInfo`). **Tested** - AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 7 7800X3D, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug (release for the regression run); DXC 1.9.2602.17. - Without the fix (the tests on `main`'s `dec`): `dec_keeps_a_percent_without_two_hex_digits` panics at `gamesave.rs:100:52` (`end byte index 3 is not a char boundary; it is inside 'é'`); `a_container_folder_named_percent_then_multibyte_is_enumerated` aborts the test process (`thread caused non-unwinding panic. aborting.`, exit code `0xC0000409`). - With the fix: `cargo test -p xcl --lib -- hle::xgameruntime::gamesave::`: 12 passed, 0 failed. - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`) with `XCL_REQUIRE_GPU=wave64,mesh`: **672 passed, 0 failed, 41 ignored, 0 SKIPPED**. **Regression run** `scripts/smoke.ps1 -Game <folder>` on a retail title, release builds, no uncommitted changes, one after the other on the machine above (a warm-up run of `main` first, not shown). The `gpu:` line names the wrong adapter (the script's known issue); the GPU was the RX 7800 XT. Both blocks unedited. `main` `3516080`: ``` xcl-smoke v1 commit: 3516080d53daac0f7749b5c02bc9b1e371479557 gpu: Meta Virtual Monitor title: retail-game6 seconds: 60 exit: 0x0 frames shown: 393 (PresentX 393) presents per 2 s (last 3): 9 8 8 device removals: 0 crashes: 0 peak commit: 15296 MB ``` this PR's head `e310370`: ``` xcl-smoke v1 commit: e3103705a1770108b3a46886c9b5a40280077439 gpu: Meta Virtual Monitor title: retail-game6 seconds: 60 exit: 0x0 frames shown: 395 (PresentX 395) presents per 2 s (last 3): 8 8 9 device removals: 0 crashes: 0 peak commit: 15290 MB ``` **Not tested** - NVIDIA / Intel; a title whose save folder holds such a name (none known: the name has to be placed there by something other than XCL). The regression run does not reach the save path (no input in 60 s; the title is in its intro movie, whose 8 presents / 2 s on this card are the known cost discussed on #283): it checks that nothing else changed. **AI use** - Claude Code with Claude Fable 5.1: wrote the change, the tests and this description from the issue and the Windows confirmation on it; the runs are from the machine above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`dec` turned "%XX" back into a byte with `u8::from_str_radix(&file[i + 1..i + 3], 16)`.
Slicing the name at byte offsets panics when a multi-byte character follows the
hex digit ("%aé": "end byte index 3 is not a char boundary"), and `dec` runs on every
folder and file name of the save provider from `extern "system"` entry points, where
the panic cannot unwind: XGameSaveEnumerateContainerInfo over such a folder ends the
title with 0xC0000409. XCL's own `enc` never writes such a name; a folder restored
from a backup or placed by hand can have one. `from_str_radix` also took a sign, so
"%+1" decoded to the byte 1.

The two characters after "%" are now read as bytes and must both be hex digits;
anything else stays as it is. Fixes #325.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:56 +00:00
github-bot closed this pull request 2026-11-26 04:21:56 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-24 11:20 UTC · original

Closing in favor of #448 for #325. The comparison in #325 reports equivalent decoding behavior; #448 also includes an enumeration-level regression test and broader malformed-escape and round-trip cases. The fix remains unmerged. Thank you for the contribution.

**@⁠ivall** on GitHub · 2026-11-24 11:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/442#issuecomment-7129972174) Closing in favor of #448 for #325. The comparison in #325 reports equivalent decoding behavior; #448 also includes an enumeration-level regression test and broader malformed-escape and round-trip cases. The fix remains unmerged. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.