runtime: hand the executable a storage root that ends in a separator and is not cut off #1447

Merged
JohnConnorNPC merged 1 commit from upstream-pr/1454 into main 2026-11-24 12:28:48 +00:00
JohnConnorNPC commented 2026-11-24 11:50:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T11:50:39Z.


Change

Two faults in how X2W_STORAGE_PATH reaches a console executable as its persistent-local-storage root (storage_path() in src/startup_stubs/runtime_proxy.cpp).

No trailing separator. The executable appends names to the root as it is. The default S:\ ends in a separator, but a value such as D:\saves, which is what run.ps1 -StoragePath D:\saves sets, was passed on unchanged. The executable then created D:\savessettings\, D:\savescloudpers\ and D:\savescloudcache\ beside the folder it was given, and wrote its settings file there.

64-byte buffer. The value was read with GetEnvironmentVariableA into char path[64]. For a longer value that call returns the size it needs and fills nothing, so the buffer stayed empty, the default was not applied either (the call's result is not zero), and the executable was handed an empty root.

Now (src/startup_stubs/storage_root.h):

  • a value that does not end in \ or / gets a trailing \;
  • values up to 258 characters fit (a 260-byte root with room for the separator);
  • a longer value is refused with a log line and the default S:\ is used, instead of a cut-off or empty root;
  • the value is read once, under InitOnceExecuteOnce.

The game-save stand-in builds its own path with std::filesystem from the same root and is not affected by the added separator.

What was measured

One console executable under the startup debugger, clang-cl build under Wine 11.0 with vkd3d-proton, main at e84829de. Paths below are shortened to their last components.

X2W_STORAGE_PATH main this PR
...\storage (no separator) folders created as ...\storagesettings\, ...\storagecloudpers\, ...\storagecloudcache\; settings file written to ...\storagesettings\settings.xml logged root ends in \; the three folders are created inside the given folder
83 characters logged root is empty; none of the three folder creations appears in a 25 s file trace (they appear 0.3 s into every other run) logged root is the full value; the three folders are created inside it

The 22 s runs with this PR do not reach the point where the settings file is written; only the folder creations were observed for it.

Tests

tests/startup_storage_root_check.cpp, without a process or a device:

  • nine roots: a drive root, folders with and without a separator, a forward slash, a relative folder, a bare drive, a 64-character value, and the longest values that fit with and without their own separator;
  • five refusals: empty, null, one character too long with and without a separator, and four times the capacity. Each must leave the output untouched;
  • every case checks that nothing is written past the capacity;
  • startup_storage_root_separator_control runs the old rule (the value as it is) and must fail (WILL_FAIL).
$ startup_storage_root_check
startup_storage_root: PASS (9 roots, 5 refusals)
$ startup_storage_root_check --mutate separator
FAIL bare drive: gave "S:", expected S:\
FAIL longest value without a separator: ...
FAIL one character too long without a separator: ...
startup_storage_root: 5 FAILED

docs_links_check.py passes. docs/startup-runtime.md and the run.ps1 parameter comment now state the rule.

Not verified

  • Windows. The tests are plain C++ and the runs above are on a translation-layer host.
  • The over-long refusal inside the stand-in (a value above 258 characters): the helper's refusal is tested, the log line and the fall-back to S:\ in storage_path() were not exercised in a run.
  • Whether the executable itself copes with a root close to 260 characters. It asks for the size before it asks for the path, and 83 characters worked.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6581108884 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1454). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-24T11:50:39Z. --- ## Change Two faults in how `X2W_STORAGE_PATH` reaches a console executable as its persistent-local-storage root (`storage_path()` in `src/startup_stubs/runtime_proxy.cpp`). **No trailing separator.** The executable appends names to the root as it is. The default `S:\` ends in a separator, but a value such as `D:\saves`, which is what `run.ps1 -StoragePath D:\saves` sets, was passed on unchanged. The executable then created `D:\savessettings\`, `D:\savescloudpers\` and `D:\savescloudcache\` beside the folder it was given, and wrote its settings file there. **64-byte buffer.** The value was read with `GetEnvironmentVariableA` into `char path[64]`. For a longer value that call returns the size it needs and fills nothing, so the buffer stayed empty, the default was not applied either (the call's result is not zero), and the executable was handed an empty root. Now (`src/startup_stubs/storage_root.h`): - a value that does not end in `\` or `/` gets a trailing `\`; - values up to 258 characters fit (a 260-byte root with room for the separator); - a longer value is refused with a log line and the default `S:\` is used, instead of a cut-off or empty root; - the value is read once, under `InitOnceExecuteOnce`. The game-save stand-in builds its own path with `std::filesystem` from the same root and is not affected by the added separator. ## What was measured One console executable under the startup debugger, clang-cl build under Wine 11.0 with vkd3d-proton, `main` at `e84829de`. Paths below are shortened to their last components. | `X2W_STORAGE_PATH` | `main` | this PR | |---|---|---| | `...\storage` (no separator) | folders created as `...\storagesettings\`, `...\storagecloudpers\`, `...\storagecloudcache\`; settings file written to `...\storagesettings\settings.xml` | logged root ends in `\`; the three folders are created inside the given folder | | 83 characters | logged root is empty; none of the three folder creations appears in a 25 s file trace (they appear 0.3 s into every other run) | logged root is the full value; the three folders are created inside it | The 22 s runs with this PR do not reach the point where the settings file is written; only the folder creations were observed for it. ## Tests `tests/startup_storage_root_check.cpp`, without a process or a device: - nine roots: a drive root, folders with and without a separator, a forward slash, a relative folder, a bare drive, a 64-character value, and the longest values that fit with and without their own separator; - five refusals: empty, null, one character too long with and without a separator, and four times the capacity. Each must leave the output untouched; - every case checks that nothing is written past the capacity; - `startup_storage_root_separator_control` runs the old rule (the value as it is) and must fail (`WILL_FAIL`). ```text $ startup_storage_root_check startup_storage_root: PASS (9 roots, 5 refusals) $ startup_storage_root_check --mutate separator FAIL bare drive: gave "S:", expected S:\ FAIL longest value without a separator: ... FAIL one character too long without a separator: ... startup_storage_root: 5 FAILED ``` `docs_links_check.py` passes. `docs/startup-runtime.md` and the `run.ps1` parameter comment now state the rule. ## Not verified - Windows. The tests are plain C++ and the runs above are on a translation-layer host. - The over-long refusal inside the stand-in (a value above 258 characters): the helper's refusal is tested, the log line and the fall-back to `S:\` in `storage_path()` were not exercised in a run. - Whether the executable itself copes with a root close to 260 characters. It asks for the size before it asks for the path, and 83 characters worked.
upstream-sync closed this pull request 2026-11-24 13:00:32 +00:00
tedin7 commented 2026-11-24 13:00:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:06:48Z.

Review: COMMENTED


Dual-platform peer review at commit daf09b2af2d5a935869b08d25e7452b886f0ad0b.

Audit

  • src/startup_stubs/storage_root.h & src/startup_stubs/runtime_proxy.cpp:
    • storage_root() handles nullptr/empty input without modifying out, preserves existing trailing \ or /, appends \ when missing, and rejects inputs whose length with separator reaches storage_root_capacity (260), leaving out untouched.
    • storage_path() uses InitOnceExecuteOnce with a 261-byte stack buffer for GetEnvironmentVariableA, distinguishing length >= sizeof(value) (logs character count vs 258 limit) from length && !storage_root(...) (e.g., 259-char value without trailing separator or 260-char value) and falling back to "S:\\".
    • Minor observation (non-blocking): tests/startup_storage_root_check.cpp relies on <cstring> transitively via storage_root.h, and storage_path()'s else if log message says "does not fit with its trailing separator" even if a 260-char value already has a trailing separator (accurate enough for diagnostics).
  • Hygiene & Docs:
    • git diff --check origin/main..HEAD: clean.
    • python3 tests/docs_links_check.py: passed (16 Markdown files, 325 links).
    • python3 tests/bidi_controls_check.py: passed.
    • Title-neutrality: clean.

Verification on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_storage_root_check -- -j 6): 3.44s
    • Test (ctest --preset dev -R '^startup_storage_root' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (startup_storage_root 0.02s, startup_storage_root_separator_control 0.01s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_storage_root_check -- -j 6): 0.79s
    • Test (ctest --preset release -R '^startup_storage_root' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (startup_storage_root 0.01s, startup_storage_root_separator_control 0.01s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038892519 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1454#pullrequestreview-6038892519). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:06:48Z. **Review:** COMMENTED --- Dual-platform peer review at commit `daf09b2af2d5a935869b08d25e7452b886f0ad0b`. ### Audit - **`src/startup_stubs/storage_root.h` & `src/startup_stubs/runtime_proxy.cpp`**: - `storage_root()` handles `nullptr`/empty input without modifying `out`, preserves existing trailing `\` or `/`, appends `\` when missing, and rejects inputs whose length with separator reaches `storage_root_capacity` (`260`), leaving `out` untouched. - `storage_path()` uses `InitOnceExecuteOnce` with a `261`-byte stack buffer for `GetEnvironmentVariableA`, distinguishing `length >= sizeof(value)` (logs character count vs `258` limit) from `length && !storage_root(...)` (e.g., 259-char value without trailing separator or 260-char value) and falling back to `"S:\\"`. - Minor observation (non-blocking): `tests/startup_storage_root_check.cpp` relies on `<cstring>` transitively via `storage_root.h`, and `storage_path()`'s `else if` log message says "does not fit with its trailing separator" even if a 260-char value already has a trailing separator (accurate enough for diagnostics). - **Hygiene & Docs**: - `git diff --check origin/main..HEAD`: clean. - `python3 tests/docs_links_check.py`: passed (16 Markdown files, 325 links). - `python3 tests/bidi_controls_check.py`: passed. - Title-neutrality: clean. ### Verification on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_storage_root_check -- -j 6`): `3.44s` - Test (`ctest --preset dev -R '^startup_storage_root' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`startup_storage_root` `0.02s`, `startup_storage_root_separator_control` `0.01s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_storage_root_check -- -j 6`): `0.79s` - Test (`ctest --preset release -R '^startup_storage_root' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`startup_storage_root` `0.01s`, `startup_storage_root_separator_control` `0.01s`)
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!1447
No description provided.