Skip to content

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

Closed
Rednaxeh wants to merge 1 commit into
xcl-dev:mainfrom
Rednaxeh:gamesave-percent-decode
Closed

Rednaxeh wants to merge 1 commit into
xcl-dev:mainfrom
Rednaxeh:gamesave-percent-decode

Conversation

@Rednaxeh

Copy link
Copy Markdown
Contributor

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

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

…icing the str

`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 xcl-dev#325.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants