XSystemGetXboxLiveSandboxId accepts a buffer smaller than XSystemXboxLiveSandboxIdMaxBytes #862

Open
opened 2026-11-26 04:14:05 +00:00 by github-bot · 5 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-24 12:54 UTC · original

What's wrong

Microsoft's XSystemGetXboxLiveSandboxId reference specifies a minimum buffer size of XSystemXboxLiveSandboxIdMaxBytes (16 in XSystem.h):

  • sandboxIdSize: "This value must be equal to or greater than the XSystemXboxLiveSandboxIdMaxBytes constant defined in XSystem.h."
  • Return value: "If the function fails because sandboxIdSize is set to a value less than XSystemXboxLiveSandboxIdMaxBytes, the return value is set to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)."

In crates/victory-hle/src/modules/xsystem.rs (lines 37 and 64–66), sandbox_id calls put_string(SANDBOX, size, buffer, used) with const SANDBOX: &str = "RETAIL";. put_string (crates/victory-hle/src/modules/xgameruntime.rs, lines 145–149) only checks size < text.len() + 1 (7 bytes).

As a result, calling XSystemGetXboxLiveSandboxId(7, buf, &used) returns 0x8007007A (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) on Xbox regardless of the sandbox's length, but returns S_OK here, writing "RETAIL\0" and setting used = 7.

Impact

Low impact: titles that follow the GDK documentation allocate at least XSystemXboxLiveSandboxIdMaxBytes (16 bytes), so only a title passing a short buffer (7–15 bytes) diverges—it succeeds here and fails on Xbox.

Fix

Define SANDBOX_ID_MAX_BYTES: usize = 16 (XSystemXboxLiveSandboxIdMaxBytes) in crates/victory-hle/src/modules/xsystem.rs and have sandbox_id return xasync::E_NOT_SUFFICIENT_BUFFER (0x8007007A) whenever size < SANDBOX_ID_MAX_BYTES, before calling put_string. Leave put_string itself unchanged; the other two getters in xsystem.rs (console_id, 39 bytes, and device_id, 45 bytes) already match their documented minimums because their strings fill them exactly.

The fix is ready on a branch of my fork, since PR creation is limited to collaborators: https://github.com/BastienRodz/VIctory/commits/hle/sandbox-id-buffer-minimum (one commit on main ffe310e, xsystem.rs +26).

Tests

a_sandbox_id_buffer_under_the_documented_minimum_is_refused: sizes 7 and 15 are refused with E_NOT_SUFFICIENT_BUFFER and the buffer is left untouched; size 16 gives S_OK, "RETAIL\0" and used = 7.

  • On main: it fails at the first case, size 7, left: 0, right: -2147024774 (0x8007007A).
  • With the fix, on GitHub's windows-latest with the upstream CI's commands (clippy -D warnings with and without --all-features, then cargo test --workspace --locked): everything passes; victory-hle 95 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45397649553).

No game data used. AI-assisted: found with GPT-6.2 Astra, written with Gemini 4 Neon, reviewed and verified with Claude Code.

**@⁠BastienRodz** on GitHub · 2026-11-24 12:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/862) ## What's wrong Microsoft's [XSystemGetXboxLiveSandboxId reference](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xsystem/functions/xsystemgetxboxlivesandboxid) specifies a minimum buffer size of `XSystemXboxLiveSandboxIdMaxBytes` (`16` in `XSystem.h`): - `sandboxIdSize`: "This value must be equal to or greater than the **XSystemXboxLiveSandboxIdMaxBytes** constant defined in XSystem.h." - Return value: "If the function fails because *sandboxIdSize* is set to a value less than **XSystemXboxLiveSandboxIdMaxBytes**, the return value is set to **HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)**." In `crates/victory-hle/src/modules/xsystem.rs` (lines 37 and 64–66), `sandbox_id` calls `put_string(SANDBOX, size, buffer, used)` with `const SANDBOX: &str = "RETAIL";`. `put_string` (`crates/victory-hle/src/modules/xgameruntime.rs`, lines 145–149) only checks `size < text.len() + 1` (7 bytes). As a result, calling `XSystemGetXboxLiveSandboxId(7, buf, &used)` returns `0x8007007A` (`HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)`) on Xbox regardless of the sandbox's length, but returns `S_OK` here, writing `"RETAIL\0"` and setting `used = 7`. ## Impact Low impact: titles that follow the GDK documentation allocate at least `XSystemXboxLiveSandboxIdMaxBytes` (16 bytes), so only a title passing a short buffer (7–15 bytes) diverges—it succeeds here and fails on Xbox. ## Fix Define `SANDBOX_ID_MAX_BYTES: usize = 16` (`XSystemXboxLiveSandboxIdMaxBytes`) in `crates/victory-hle/src/modules/xsystem.rs` and have `sandbox_id` return `xasync::E_NOT_SUFFICIENT_BUFFER` (`0x8007007A`) whenever `size < SANDBOX_ID_MAX_BYTES`, before calling `put_string`. Leave `put_string` itself unchanged; the other two getters in `xsystem.rs` (`console_id`, 39 bytes, and `device_id`, 45 bytes) already match their documented minimums because their strings fill them exactly. The fix is ready on a branch of my fork, since PR creation is limited to collaborators: https://github.com/BastienRodz/VIctory/commits/hle/sandbox-id-buffer-minimum (one commit on `main` `ffe310e`, `xsystem.rs` +26). ## Tests `a_sandbox_id_buffer_under_the_documented_minimum_is_refused`: sizes 7 and 15 are refused with `E_NOT_SUFFICIENT_BUFFER` and the buffer is left untouched; size 16 gives `S_OK`, `"RETAIL\0"` and `used = 7`. - **On `main`:** it fails at the first case, `size 7`, `left: 0`, `right: -2147024774` (`0x8007007A`). - **With the fix,** on GitHub's `windows-latest` with the upstream CI's commands (clippy `-D warnings` with and without `--all-features`, then `cargo test --workspace --locked`): everything passes; `victory-hle` 95 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45397649553). No game data used. AI-assisted: found with GPT-6.2 Astra, written with Gemini 4 Neon, reviewed and verified with Claude Code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:05 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 13:37 UTC · original

Claiming this issue.

Technical Analysis

In crates/victory-hle/src/modules/xsystem.rs:
sandbox_id delegates to put_string(SANDBOX, size, buffer, used) with const SANDBOX = RETAIL. Because put_string only checks size < text.len() + 1 (7 bytes), buffer sizes 7..15 erroneously succeed with S_OK.

However, the official GDK specification for XSystemGetXboxLiveSandboxId specifies:

  • sandboxIdSize must be at least XSystemXboxLiveSandboxIdMaxBytes (16 bytes).
  • If sandboxIdSize < XSystemXboxLiveSandboxIdMaxBytes, the return value must be HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) (0x8007007A).

Proposed Fix

Define const SANDBOX_ID_MAX_BYTES: usize = 16 in xsystem.rs and guard sandbox_id with:
if size < SANDBOX_ID_MAX_BYTES { return xasync::E_NOT_SUFFICIENT_BUFFER; }
before calling put_string. Add regression tests asserting that buffer sizes 7 and 15 return E_NOT_SUFFICIENT_BUFFER with unchanged buffers, while size 16 succeeds.

Preparing clean branch with Rust 2024 compliance on fork.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 13:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/862#issuecomment-7133104992) Claiming this issue. ### Technical Analysis In crates/victory-hle/src/modules/xsystem.rs: sandbox_id delegates to put_string(SANDBOX, size, buffer, used) with const SANDBOX = RETAIL. Because put_string only checks size < text.len() + 1 (7 bytes), buffer sizes 7..15 erroneously succeed with S_OK. However, the official GDK specification for XSystemGetXboxLiveSandboxId specifies: - sandboxIdSize must be at least XSystemXboxLiveSandboxIdMaxBytes (16 bytes). - If sandboxIdSize < XSystemXboxLiveSandboxIdMaxBytes, the return value must be HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) (0x8007007A). ### Proposed Fix Define const SANDBOX_ID_MAX_BYTES: usize = 16 in xsystem.rs and guard sandbox_id with: if size < SANDBOX_ID_MAX_BYTES { return xasync::E_NOT_SUFFICIENT_BUFFER; } before calling put_string. Add regression tests asserting that buffer sizes 7 and 15 return E_NOT_SUFFICIENT_BUFFER with unchanged buffers, while size 16 succeeds. Preparing clean branch with Rust 2024 compliance on fork.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 13:39 UTC · original · edited 2026-11-24 14:22 UTC

Verified Implementation Ready on Fork

The implementation enforcing XSystemXboxLiveSandboxIdMaxBytes (16 bytes) on sandbox_id is complete and pushed to my fork:

Compare: https://github.com/Marvisak/VIctory/compare/main...pushkarreddyy:VIctory:fix/hle-sandbox-id-buffer-minimum

Changes (crates/victory-hle/src/modules/xsystem.rs):

  • Defined const SANDBOX_ID_MAX_BYTES: usize = 16; matching GDK XSystem.h.
  • In sandbox_id, checked if size < SANDBOX_ID_MAX_BYTES { return super::xasync::E_NOT_SUFFICIENT_BUFFER; } prior to delegating to put_string.
  • Added unit test ^G_sandbox_id_buffer_under_the_documented_minimum_is_refused verifying:
    • Sizes
**@⁠pushkarreddyy** on GitHub · 2026-11-24 13:39 UTC · [original](https://github.com/Marvisak/VIctory/issues/862#issuecomment-7133151389) · edited 2026-11-24 14:22 UTC ### Verified Implementation Ready on Fork The implementation enforcing XSystemXboxLiveSandboxIdMaxBytes (16 bytes) on sandbox_id is complete and pushed to my fork: - **Branch:** [fix/hle-sandbox-id-buffer-minimum](https://github.com/pushkarreddyy/VIctory/tree/fix/hle-sandbox-id-buffer-minimum) - **Commit:** [d3633c5](https://github.com/pushkarreddyy/VIctory/commit/d3633c5) based on main (ffe310e) Compare: https://github.com/Marvisak/VIctory/compare/main...pushkarreddyy:VIctory:fix/hle-sandbox-id-buffer-minimum #### Changes (crates/victory-hle/src/modules/xsystem.rs): - Defined const SANDBOX_ID_MAX_BYTES: usize = 16; matching GDK XSystem.h. - In sandbox_id, checked if size < SANDBOX_ID_MAX_BYTES { return super::xasync::E_NOT_SUFFICIENT_BUFFER; } prior to delegating to put_string. - Added unit test ^G_sandbox_id_buffer_under_the_documented_minimum_is_refused verifying: - Sizes
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 14:37 UTC · original

Pull request is now open for review: #972.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 14:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/862#issuecomment-7134681797) Pull request is now open for review: #972.
Author
Owner

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

I tested the four fixes side by side, as Windows builds run under Wine 10.0 on Linux: BastienRodz's branch (460e4c6), #939 (d4306f4), #972 (886a867, the same commit as pushkarreddyy's fork branch) and the xsystem.rs part of #1330 (fb40a8f). They make the same code change: SANDBOX_ID_MAX_BYTES = 16 and a size < 16 guard before put_string. Only their tests differ.

The value 16 is right. Microsoft's docs refer to the constant but don't state its value. Microsoft's own XBOX-GDK-dotnet interop does: XSystemXboxLiveSandboxIdMaxBytes` from XSystem.h: includes null terminator → 16, next to ConsoleIdBytes = 39 and AppSpecificDeviceIdBytes = 45, which match the other two getters here. The SystemInfo sample uses char sandbox[XSystemXboxLiveSandboxIdMaxBytes] with a nullptr sandboxIdUsed.

main Bastien #939 #972 #1330
xsystem:: tests 4 pass 5 pass 5 pass 5 pass 5 pass
New test fails with the guard removed n/a yes yes yes yes
Probe: 3 getters × sizes 0–64, plus a null used 9 fail (sandbox 7–15 return S_OK) 0 fail 0 fail 0 fail 0 fail
clippy -D warnings clean clean clean clean (bundle)

The probe checks two things. Below the minimum, the call must return E_NOT_SUFFICIENT_BUFFER and leave the buffer and used untouched. At or above it, it must return S_OK with a NUL-terminated string and nothing written past used.

Since the fixes are identical, only one needs to land. #939 is the oldest open PR, and its test checks that both the buffer and used stay untouched. #972's test also covers size 0. Either is fine, and the others can be closed as duplicates.

AI-assisted (Claude Code). Tests were synthetic, with no game files.

**@⁠winne42** on GitHub · 2026-11-24 20:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/862#issuecomment-7142975086) I tested the four fixes side by side, as Windows builds run under Wine 10.0 on Linux: BastienRodz's branch (`460e4c6`), #939 (`d4306f4`), #972 (`886a867`, the same commit as pushkarreddyy's fork branch) and the `xsystem.rs` part of #1330 (`fb40a8f`). They make the same code change: `SANDBOX_ID_MAX_BYTES = 16` and a `size < 16` guard before `put_string`. Only their tests differ. **The value 16 is right.** Microsoft's docs refer to the constant but don't state its value. Microsoft's own [`XBOX-GDK-dotnet` interop](https://github.com/microsoft/XBOX-GDK-dotnet/blob/f8c3438aa366fbbb662d8a5e724021a9d0b65f5d/src/GDK.Net/Interop/NativeTypes.System.cs) does: ``XSystemXboxLiveSandboxIdMaxBytes` from XSystem.h: includes null terminator`` → `16`, next to `ConsoleIdBytes = 39` and `AppSpecificDeviceIdBytes = 45`, which match the other two getters here. The [SystemInfo sample](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/System/SystemInfo/SystemInfo.cpp) uses `char sandbox[XSystemXboxLiveSandboxIdMaxBytes]` with a `nullptr` `sandboxIdUsed`. | | `main` | Bastien | #939 | #972 | #1330 | |---|---|---|---|---|---| | `xsystem::` tests | 4 pass | 5 pass | 5 pass | 5 pass | 5 pass | | New test fails with the guard removed | n/a | yes | yes | yes | yes | | Probe: 3 getters × sizes 0–64, plus a null `used` | **9 fail** (sandbox 7–15 return `S_OK`) | 0 fail | 0 fail | 0 fail | 0 fail | | clippy `-D warnings` | clean | clean | clean | clean | (bundle) | The probe checks two things. Below the minimum, the call must return `E_NOT_SUFFICIENT_BUFFER` and leave the buffer and `used` untouched. At or above it, it must return `S_OK` with a NUL-terminated string and nothing written past `used`. Since the fixes are identical, only one needs to land. #939 is the oldest open PR, and its test checks that both the buffer and `used` stay untouched. #972's test also covers size 0. Either is fine, and the others can be closed as duplicates. _AI-assisted (Claude Code). Tests were synthetic, with no game files._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:50 UTC · original

Automated triage for the maintainers.

Confirmed on current main: in crates/victory-hle/src/modules/xsystem.rs, sandbox_id passes straight to put_string (xgameruntime.rs), which only checks that "RETAIL" and its terminator fit, so a 7–15 byte buffer succeeds where the console refuses it. Open PR #939 makes this change (a 16-byte minimum before put_string); #972 and the bundle #1330 were closed without merging. Per the comparison in this thread the fork branches are the same change, so review can go to #939.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/862#issuecomment-7155205422) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T20:03:14Z at=2026-11-25T06:49:59Z --> Automated triage for the maintainers. Confirmed on current `main`: in `crates/victory-hle/src/modules/xsystem.rs`, `sandbox_id` passes straight to `put_string` (`xgameruntime.rs`), which only checks that `"RETAIL"` and its terminator fit, so a 7–15 byte buffer succeeds where the console refuses it. Open PR #939 makes this change (a 16-byte minimum before `put_string`); #972 and the bundle #1330 were closed without merging. Per the comparison in this thread the fork branches are the same change, so review can go to #939. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#862
No description provided.