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

Merged
tedin7 merged 2 commits from upstream-pr/1271 into main 2026-11-24 06:35:44 +00:00
tedin7 commented 2026-11-24 06:23:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:23:04Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575976475 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1271). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:23:04Z. --- ## 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`.
upstream-sync closed this pull request 2026-11-24 06:47:28 +00:00
tedin7 commented 2026-11-24 06:50:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:26:32Z.


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)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123936265 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1271#issuecomment-7123936265). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:26:32Z. --- 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`)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:26:39Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123938352 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1271#issuecomment-7123938352). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:26:39Z. --- <!-- 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>
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!1264
No description provided.