runtime: add main(argv) CLI and chunk size validation to startup capture reader #2107

Merged
Ammmae0x merged 1 commit from upstream-pr/2115 into main 2026-11-25 01:11:01 +00:00
Ammmae0x commented 2026-11-25 00:45:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:45:33Z.


Change

Harden tools/startup/capture.py with an explicit CLI entry point and chunk-size validation, and add a pure-Python CLI/validation unit suite (tests/startup_capture_cli_check.py, registered in CMakeLists.txt as startup_capture_cli):

  • Extract the CLI entry point into main(argv=None) -> int using argparse, invoking describe(Capture(args.capture), out=sys.stdout) and reporting (OSError, ValueError) via parser.exit(1, ...) without raw Python tracebacks.
  • Validate VIEW chunk headers in Capture.on_VIEW: raise ValueError when len(h) < 48 + desc_bytes instead of silently truncating the descriptor slice.
  • Validate TABL chunk bodies in Capture.on_TABL: raise ValueError when len(b) % 4 != 0 or entries > len(ids) instead of dropping trailing bytes or silently truncating the shadow table.
  • Add 6 pure-Python unit and CLI tests covering empty captures, shadow-only TABL records, exact VIEW boundary (len(h) == 48 + desc_bytes), subprocess CLI smoke tests, truncated VIEW descriptors, malformed TABL bodies, damaged chunk headers/payloads, missing CLI argument (exit 2), and missing/directory path OSError handling (exit 1, zero tracebacks).

Verification

Commit: aaa7d370 (rebased onto upstream/main 3ebc3523).

  • out/pe-env/Scripts/python.exe -B tests/startup_capture_cli_check.py -v -> exit 0 (6 tests OK)
  • out/pe-env/Scripts/python.exe -B tests/startup_capture_check.py -> exit 0 (7/7 checks ok)
  • out/pe-env/Scripts/python.exe -B tests/startup_tools_lint_check.py -> exit 0 (PASS: 7 files under tools/startup parse)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0
  • Spot-mutation verification: independently disabling len(h) < 48 + desc_bytes in on_VIEW, len(b) % 4 != 0 in on_TABL, entries > len(ids) in on_TABL, and except (OSError, ValueError) in main() each caused tests/startup_capture_cli_check.py to fail (exit 1).

No capability skips (exit 77).

Evidence and follow-up

All capture.bin streams in tests/startup_capture_cli_check.py are synthetically constructed in Python matching the src/startup_stubs/d3d12_capture.inl chunk framing (ViewRecord and TABL layouts) under the repository MIT license.

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:6594498020 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2115). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:45:33Z. --- ## Change Harden `tools/startup/capture.py` with an explicit CLI entry point and chunk-size validation, and add a pure-Python CLI/validation unit suite (`tests/startup_capture_cli_check.py`, registered in `CMakeLists.txt` as `startup_capture_cli`): - Extract the CLI entry point into `main(argv=None) -> int` using `argparse`, invoking `describe(Capture(args.capture), out=sys.stdout)` and reporting `(OSError, ValueError)` via `parser.exit(1, ...)` without raw Python tracebacks. - Validate `VIEW` chunk headers in `Capture.on_VIEW`: raise `ValueError` when `len(h) < 48 + desc_bytes` instead of silently truncating the descriptor slice. - Validate `TABL` chunk bodies in `Capture.on_TABL`: raise `ValueError` when `len(b) % 4 != 0` or `entries > len(ids)` instead of dropping trailing bytes or silently truncating the shadow table. - Add 6 pure-Python unit and CLI tests covering empty captures, shadow-only `TABL` records, exact `VIEW` boundary (`len(h) == 48 + desc_bytes`), subprocess CLI smoke tests, truncated `VIEW` descriptors, malformed `TABL` bodies, damaged chunk headers/payloads, missing CLI argument (exit 2), and missing/directory path `OSError` handling (exit 1, zero tracebacks). ## Verification Commit: `aaa7d370` (rebased onto `upstream/main` `3ebc3523`). - `out/pe-env/Scripts/python.exe -B tests/startup_capture_cli_check.py -v` -> exit `0` (6 tests OK) - `out/pe-env/Scripts/python.exe -B tests/startup_capture_check.py` -> exit `0` (7/7 checks ok) - `out/pe-env/Scripts/python.exe -B tests/startup_tools_lint_check.py` -> exit `0` (PASS: 7 files under tools/startup parse) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (form coverage checks passed) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` - Spot-mutation verification: independently disabling `len(h) < 48 + desc_bytes` in `on_VIEW`, `len(b) % 4 != 0` in `on_TABL`, `entries > len(ids)` in `on_TABL`, and `except (OSError, ValueError)` in `main()` each caused `tests/startup_capture_cli_check.py` to fail (exit `1`). No capability skips (exit 77). ## Evidence and follow-up All `capture.bin` streams in `tests/startup_capture_cli_check.py` are synthetically constructed in Python matching the `src/startup_stubs/d3d12_capture.inl` chunk framing (`ViewRecord` and `TABL` layouts) under the repository MIT license. ## 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.
upstream-sync closed this pull request 2026-11-25 02:01:46 +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!2107
No description provided.