tooling: check the capture reader and reject damaged captures #1271

Manually merged
github merged 2 commits from gh-pr/1271/head into gh-pr/1271/base 2026-11-26 22:54:01 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 06:23 UTC · original
tedin7:x2w-c3-capture-check → main · +188 −5 · 4 files · 2 commits · merged 2026-11-24 06:35 UTC

What

  • tests/startup_capture_check.py: builds synthetic capture.bin files with struct.pack, laid out like the writer in src/startup_stubs/d3d12_capture.inl (FRAM, CALL, MEM, PSO, ROOT, RES, HEAP, OBJ, VIEW, TABL with and without id data, TGTS, PRES), loads them with Capture and asserts every decoded field. It also checks Memory.read (latest block at or before a sequence, older bytes for an earlier sequence, None before any capture, an address inside a block, and today's behaviour for a read past the end of a block: the shorter bytes come back without an error) and that describe() runs and names the expected slots, views, targets and present.
  • Negative controls: a truncated body, a truncated chunk header, an unknown tag, a chunk header shorter than its struct, and a RES record with a mutated or swapped field must not decode to the original values.
  • tools/startup/capture.py: the reader now raises ValueError naming the tag and offset for a truncated header or body, an unknown tag, and a chunk header shorter than its struct. Before, a short last body was accepted silently, an unknown tag raised AttributeError, and a trailing partial header was ignored. The dead first statement in on_RES.desc() (... if False else (None,) * 11) is removed. It was dead code, not a skipped decode: the console and desktop descriptions were already decoded correctly by the lines after it.
  • CMakeLists.txt registers ctest startup_capture next to the other pure-Python startup checks (INTAKE_PYTHON block); docs/startup-runtime.md gets a short section with the test command.

Why

The reader had no source-built check. I compared every on_* method with the writer structs (offsets, widths, pad fields, data sizes) and found no layout mismatch; the checks keep it that way. Refs #1149

Tested

Linux, run from the repository root:

python3 -B tests/startup_capture_check.py
python3 -B tests/docs_links_check.py
python3 -B tests/bidi_controls_check.py
python3 -m py_compile tests/startup_capture_check.py tools/startup/capture.py

All pass. Against the old capture.py the new check fails (the truncated-file case). The Windows ctest was not run locally: ctest --preset dev --no-tests=error -R '^startup_capture$' -V.

**@⁠tedin7** on GitHub · 2026-11-24 06:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1271) `tedin7:x2w-c3-capture-check` → `main` · +188 −5 · 4 files · 2 commits · merged 2026-11-24 06:35 UTC ## What - `tests/startup_capture_check.py`: builds synthetic `capture.bin` files with `struct.pack`, laid out like the writer in `src/startup_stubs/d3d12_capture.inl` (FRAM, CALL, MEM, PSO, ROOT, RES, HEAP, OBJ, VIEW, TABL with and without id data, TGTS, PRES), loads them with `Capture` and asserts every decoded field. It also checks `Memory.read` (latest block at or before a sequence, older bytes for an earlier sequence, `None` before any capture, an address inside a block, and today's behaviour for a read past the end of a block: the shorter bytes come back without an error) and that `describe()` runs and names the expected slots, views, targets and present. - Negative controls: a truncated body, a truncated chunk header, an unknown tag, a chunk header shorter than its struct, and a RES record with a mutated or swapped field must not decode to the original values. - `tools/startup/capture.py`: the reader now raises `ValueError` naming the tag and offset for a truncated header or body, an unknown tag, and a chunk header shorter than its struct. Before, a short last body was accepted silently, an unknown tag raised `AttributeError`, and a trailing partial header was ignored. The dead first statement in `on_RES.desc()` (`... if False else (None,) * 11`) is removed. It was dead code, not a skipped decode: the console and desktop descriptions were already decoded correctly by the lines after it. - `CMakeLists.txt` registers ctest `startup_capture` next to the other pure-Python startup checks (`INTAKE_PYTHON` block); `docs/startup-runtime.md` gets a short section with the test command. ## Why The reader had no source-built check. I compared every `on_*` method with the writer structs (offsets, widths, pad fields, data sizes) and found no layout mismatch; the checks keep it that way. Refs #1149 ## Tested Linux, run from the repository root: ``` python3 -B tests/startup_capture_check.py python3 -B tests/docs_links_check.py python3 -B tests/bidi_controls_check.py python3 -m py_compile tests/startup_capture_check.py tools/startup/capture.py ``` All pass. Against the old `capture.py` the new check fails (the truncated-file case). The Windows ctest was not run locally: `ctest --preset dev --no-tests=error -R '^startup_capture$' -V`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:54:00 +00:00
github manually merged commit 84d500d833 into gh-pr/1271/base 2026-11-26 22:54:01 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 06:26 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at c3b18721:

  • Debug (--preset dev): 21/21 PASS (8.59s), including startup_capture (0.09s) and startup_stubs (0.48s)
  • Release /O2 (--preset release): 21/21 PASS (8.30s), including startup_capture (0.09s) and startup_stubs (0.37s)
**@⁠tedin7** on GitHub · 2026-11-24 06:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1271#issuecomment-7123936265) Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at `c3b18721`: - Debug (`--preset dev`): **21/21 PASS** (`8.59s`), including `startup_capture` (`0.09s`) and `startup_stubs` (`0.48s`) - Release `/O2` (`--preset release`): **21/21 PASS** (`8.30s`), including `startup_capture` (`0.09s`) and `startup_stubs` (`0.37s`)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 06:26 UTC · original · edited 2026-11-24 06:29 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T06:29:14.869819Z c3b1872 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 06:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1271#issuecomment-7123938352) · edited 2026-11-24 06:29 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c3b18721f19920c34366c05ea40729477fccb84b","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T06:29:14.869819Z">2026-11-24T06:29:14.869819Z</relative-time> | `c3b1872` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.