startup-runtime: report long or truncated X2W_INPUT_SCRIPT values instead of dropping them #1852

Merged
Leyukaka merged 3 commits from upstream-pr/1859 into main 2026-11-24 20:07:30 +00:00
Leyukaka commented 2026-11-24 19:42:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-24T19:42:13Z.


Change

X2W_INPUT_SCRIPT=<mask hex>@<second>[,...] drives timed presses of the GameInput stand-in's virtual gamepad. The stand-in read the value into a 512-byte buffer and kept at most 32 entries, both silently:

  • a value of 512 characters or more was ignored entirely: GetEnvironmentVariableA returns the required size when the buffer is too small and leaves its contents undefined; here the zero-initialized buffer stayed empty, so no entry ran;
  • entries after the 32nd were dropped.

A longer unattended script could therefore lose all of its presses, or its later ones, without any diagnostic.

src/startup_stubs/gameinput.cpp now reads up to 4,095 characters and keeps up to 256 entries. A longer value is still ignored, but logged (x2w-input X2W_INPUT_SCRIPT ignored: N characters, at most 4095), and dropped or malformed entries are logged with their counts. Scripts that worked before (at most 32 entries, under 512 characters) parse exactly as before. The docs/startup-runtime.md switch row states the limits.

Verification

On e8b3a510 (based on main at 106555ab), Windows 11 build 26300, MSVC 14.44.35207:

ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries)|keys|history)$'

All four pass. tests/startup_gameinput_script.cpp loads the built stand-in, sets a script whose last entry presses D-pad right (200@0) after filler entries due at second 9000, and checks that a gamepad reading within the first 200 ms has bit 0x200 set and that it is clear again after 0.6 s. It runs in two modes:

  • long: 41 entries, 725 characters;
  • entries: 33 entries, 229 characters.

Measured by rebuilding the stand-in with each variant of gameinput.cpp:

gameinput.cpp long entries
this change pass pass
main fail: script did not press D-pad right fail: script did not press D-pad right
this change with the 512-byte buffer fail pass
this change with the 32-entry limit fail fail

So each old limit is caught on its own: the buffer by long, the entry limit by entries.

Evidence and follow-up

  • The fixture is source-built (tests/startup_gameinput_script.cpp, MIT) and needs no title or package.
  • Not covered by the test: the over-4,095-character log line and the malformed-entry count; the parsing of each entry is unchanged.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589952970 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1859). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-24T19:42:13Z. --- ## Change `X2W_INPUT_SCRIPT=<mask hex>@<second>[,...]` drives timed presses of the GameInput stand-in's virtual gamepad. The stand-in read the value into a 512-byte buffer and kept at most 32 entries, both silently: - a value of 512 characters or more was ignored entirely: `GetEnvironmentVariableA` returns the required size when the buffer is too small and leaves its contents undefined; here the zero-initialized buffer stayed empty, so no entry ran; - entries after the 32nd were dropped. A longer unattended script could therefore lose all of its presses, or its later ones, without any diagnostic. `src/startup_stubs/gameinput.cpp` now reads up to 4,095 characters and keeps up to 256 entries. A longer value is still ignored, but logged (`x2w-input X2W_INPUT_SCRIPT ignored: N characters, at most 4095`), and dropped or malformed entries are logged with their counts. Scripts that worked before (at most 32 entries, under 512 characters) parse exactly as before. The `docs/startup-runtime.md` switch row states the limits. ## Verification On `e8b3a510` (based on `main` at `106555ab`), Windows 11 build 26300, MSVC 14.44.35207: ```text ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries)|keys|history)$' ``` All four pass. `tests/startup_gameinput_script.cpp` loads the built stand-in, sets a script whose last entry presses D-pad right (`200@0`) after filler entries due at second 9000, and checks that a gamepad reading within the first 200 ms has bit `0x200` set and that it is clear again after 0.6 s. It runs in two modes: - `long`: 41 entries, 725 characters; - `entries`: 33 entries, 229 characters. Measured by rebuilding the stand-in with each variant of `gameinput.cpp`: | `gameinput.cpp` | `long` | `entries` | |---|---|---| | this change | pass | pass | | `main` | fail: script did not press D-pad right | fail: script did not press D-pad right | | this change with the 512-byte buffer | fail | pass | | this change with the 32-entry limit | fail | fail | So each old limit is caught on its own: the buffer by `long`, the entry limit by `entries`. ## Evidence and follow-up - The fixture is source-built (`tests/startup_gameinput_script.cpp`, MIT) and needs no title or package. - Not covered by the test: the over-4,095-character log line and the malformed-entry count; the parsing of each entry is unchanged. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-24 20:01:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:46:13Z.

Review: COMMENTED


Reviewed head e8b3a510de834f93f175918dfe2305595129e20b.

Linux checks in a clean worktree:

  • git diff --check origin/main...HEAD: clean (rc 0)
  • python -B tests/docs_links_check.py: rc 0
  • python -B tests/bidi_controls_check.py: rc 0

The C++ tests in this PR are Windows-only. I could not build or run them here, so the rest is source analysis. Win2025 results are still needed.

Findings: 0 P1, 0 P2.

What I checked in src/startup_stubs/gameinput.cpp:

  • GetEnvironmentVariableA returns the required size, including the terminator, when the buffer is too small. So length >= sizeof(text) is the right overflow test. A value of exactly 4,095 characters is accepted, which matches the docs.
  • The buffer is always null-terminated on the strtok path. strtok modifies it, so static char text[4096] inside the one-time initializer is fine: the lambda runs once and thread-safely, and the buffer is not used afterwards.
  • Entries past 256 are counted but not stored, so the array cannot overflow. The summary line fires for extra or malformed entries, and its counts are consistent.
  • max_entries is a static constexpr local, so using it for the array bounds, the loop and the log argument needs no capture.
  • The old code kept a value longer than 511 characters as an empty script without saying so. That silent drop is what this change fixes.

Nits, no change required:

  • The tests only cover 41 entries and 33 entries. The new log lines, the malformed-entry path and the over-4,095 refusal are not asserted, although the docs describe them. One extra mode would pin the docs claim.
  • check_script needs the first read to land within 200 ms and the press to end by 600 ms. A heavily loaded runner could make that flaky. RUN_SERIAL already limits the risk.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046197679 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1859#pullrequestreview-6046197679). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:46:13Z. **Review:** COMMENTED --- Reviewed head `e8b3a510de834f93f175918dfe2305595129e20b`. Linux checks in a clean worktree: - `git diff --check origin/main...HEAD`: clean (rc 0) - `python -B tests/docs_links_check.py`: rc 0 - `python -B tests/bidi_controls_check.py`: rc 0 The C++ tests in this PR are Windows-only. I could not build or run them here, so the rest is source analysis. Win2025 results are still needed. **Findings: 0 P1, 0 P2.** What I checked in `src/startup_stubs/gameinput.cpp`: - `GetEnvironmentVariableA` returns the required size, including the terminator, when the buffer is too small. So `length >= sizeof(text)` is the right overflow test. A value of exactly 4,095 characters is accepted, which matches the docs. - The buffer is always null-terminated on the `strtok` path. `strtok` modifies it, so `static char text[4096]` inside the one-time initializer is fine: the lambda runs once and thread-safely, and the buffer is not used afterwards. - Entries past 256 are counted but not stored, so the array cannot overflow. The summary line fires for extra or malformed entries, and its counts are consistent. - `max_entries` is a static constexpr local, so using it for the array bounds, the loop and the log argument needs no capture. - The old code kept a value longer than 511 characters as an empty script without saying so. That silent drop is what this change fixes. Nits, no change required: - The tests only cover 41 entries and 33 entries. The new log lines, the malformed-entry path and the over-4,095 refusal are not asserted, although the docs describe them. One extra mode would pin the docs claim. - `check_script` needs the first read to land within 200 ms and the press to end by 600 ms. A heavily loaded runner could make that flaky. `RUN_SERIAL` already limits the risk. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:00:57 +00:00
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!1852
No description provided.