startup_stubs: reject invalid ranges in publish_placement #1502

Merged
tedin7 merged 1 commit from upstream-pr/1509 into main 2026-11-24 14:09:45 +00:00
tedin7 commented 2026-11-24 13:21:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:21:59Z.


Summary

  • Validate placement ranges in x2w_startup::publish_placement (src/startup_stubs/placement_publish.h): reject start == 0, record.bytes == 0, and start + record.bytes uint64 overflow with E_INVALIDARG before acquiring lock or mutating records, by_start, or max_width.
  • Extend tests/startup_placement_alloc.cpp with negative controls for null start (including an already-registered owner and bytes > max_width), zero-byte size, and exact 1-byte / multi-byte uint64_t end-address overflow (verifying get_records is not invoked, the lock is released, and records/by_start/max_width remain unchanged), plus a boundary test for start + bytes == UINT64_MAX.

Verification

  • git diff --check origin/main..HEAD (passed)
  • python3 -B tests/docs_links_check.py (passed)
  • python3 -B tests/bidi_controls_check.py (passed)
  • Win2025 Debug and Release /O2 verification for startup_placement_alloc and startup_placement_publish (see verification comment).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582744390 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1509). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:21:59Z. --- ## Summary - Validate placement ranges in `x2w_startup::publish_placement` (`src/startup_stubs/placement_publish.h`): reject `start == 0`, `record.bytes == 0`, and `start + record.bytes` uint64 overflow with `E_INVALIDARG` before acquiring `lock` or mutating `records`, `by_start`, or `max_width`. - Extend `tests/startup_placement_alloc.cpp` with negative controls for null start (including an already-registered owner and `bytes > max_width`), zero-byte size, and exact 1-byte / multi-byte `uint64_t` end-address overflow (verifying `get_records` is not invoked, the lock is released, and `records`/`by_start`/`max_width` remain unchanged), plus a boundary test for `start + bytes == UINT64_MAX`. ## Verification - `git diff --check origin/main..HEAD` (passed) - `python3 -B tests/docs_links_check.py` (passed) - `python3 -B tests/bidi_controls_check.py` (passed) - Win2025 Debug and Release `/O2` verification for `startup_placement_alloc` and `startup_placement_publish` (see verification comment). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 14:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:36:28Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 86f29e63a5057121b44dfae96fad72da345f44ef:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_placement_alloc startup_placement_publish_check -- -j 6): 4.32s (configure 1.81s)
    • Test (ctest --preset dev -R '^startup_placement_(alloc|publish)' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.10s: startup_placement_alloc 0.02s, startup_placement_publish 0.02s, startup_placement_publish_shrink_control 0.01s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_placement_alloc startup_placement_publish_check -- -j 6): 1.76s (configure 1.75s)
    • Test (ctest --preset release -R '^startup_placement_(alloc|publish)' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.10s: startup_placement_alloc 0.02s, startup_placement_publish 0.02s, startup_placement_publish_shrink_control 0.01s)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133072936 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1509#issuecomment-7133072936). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:36:28Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `86f29e63a5057121b44dfae96fad72da345f44ef`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_placement_alloc startup_placement_publish_check -- -j 6`): `4.32s` (configure `1.81s`) - Test (`ctest --preset dev -R '^startup_placement_(alloc|publish)' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.10s`: `startup_placement_alloc` `0.02s`, `startup_placement_publish` `0.02s`, `startup_placement_publish_shrink_control` `0.01s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_placement_alloc startup_placement_publish_check -- -j 6`): `1.76s` (configure `1.75s`) - Test (`ctest --preset release -R '^startup_placement_(alloc|publish)' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.10s`: `startup_placement_alloc` `0.02s`, `startup_placement_publish` `0.02s`, `startup_placement_publish_shrink_control` `0.01s`) AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 14:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:36:42Z.


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-24T13:39:18.728933Z 86f29e6 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:7133078685 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1509#issuecomment-7133078685). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:36:42Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"86f29e63a5057121b44dfae96fad72da345f44ef","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-24T13:39:18.728933Z">2026-11-24T13:39:18.728933Z</relative-time> | `86f29e6` | 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>
upstream-sync closed this pull request 2026-11-24 15:01:47 +00:00
ChazY11 commented 2026-11-24 15:02:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T14:44:59Z.


All three halves of the guard are covered — verified by removing each

Independent reviewer, not the author. Reviewed 86f29e63; nothing pushed to the branch. Mutations were made locally in
src/startup_stubs/placement_publish.h, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_placement_' -V

3 of 3 pass as submitted, and startup_placement_publish still prints its two-record shape
(max_width 0x100000 then 0x400000), so the new guard does not disturb the working path.

The guard under test

if (!start || !record.bytes || record.bytes > (std::numeric_limits<std::uint64_t>::max)() - start)
    return E_INVALIDARG;

Removing each half

-    if (!start || !record.bytes || record.bytes > (std::numeric_limits<std::uint64_t>::max)() - start)
+    if (!start || !record.bytes)
startup_placement_alloc ***Failed
-    if (!start || !record.bytes || ...)
+    if (!record.bytes || ...)
startup_placement_alloc ***Failed
-    if (!start || !record.bytes || ...)
+    if (!start || ...)
startup_placement_alloc ***Failed

Overflow, zero start and zero size each take the test red on their own, and startup_placement_publish plus the shrink
control stay green in all three runs — which matches the description that the new checks sit before the lock and never
touch records, by_start or max_width.

One note, not a request

The three failure branches are indistinguishable in the output: all three show only startup_placement_alloc ***Failed,
so the report cannot tell a reader which half of the guard broke if one ever regresses. If you already rely on the
assertion text inside the test for that, fine — a one-line printed reason per control would make a future bisect
readable.

Verdict

Reviewed 86f29e63. +27/-1 across the header and its test, three cases pass, the happy path is unchanged, and each of the
three rejections is genuinely exercised. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7134884619 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1509#issuecomment-7134884619). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T14:44:59Z. --- ## All three halves of the guard are covered — verified by removing each Independent reviewer, not the author. Reviewed `86f29e63`; nothing pushed to the branch. Mutations were made locally in `src/startup_stubs/placement_publish.h`, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^startup_placement_' -V ``` 3 of 3 pass as submitted, and `startup_placement_publish` still prints its two-record shape (`max_width 0x100000 then 0x400000`), so the new guard does not disturb the working path. ### The guard under test ```cpp if (!start || !record.bytes || record.bytes > (std::numeric_limits<std::uint64_t>::max)() - start) return E_INVALIDARG; ``` ### Removing each half ```diff - if (!start || !record.bytes || record.bytes > (std::numeric_limits<std::uint64_t>::max)() - start) + if (!start || !record.bytes) ``` ```text startup_placement_alloc ***Failed ``` ```diff - if (!start || !record.bytes || ...) + if (!record.bytes || ...) ``` ```text startup_placement_alloc ***Failed ``` ```diff - if (!start || !record.bytes || ...) + if (!start || ...) ``` ```text startup_placement_alloc ***Failed ``` Overflow, zero start and zero size each take the test red on their own, and `startup_placement_publish` plus the shrink control stay green in all three runs — which matches the description that the new checks sit before the lock and never touch `records`, `by_start` or `max_width`. ### One note, not a request The three failure branches are indistinguishable in the output: all three show only `startup_placement_alloc ***Failed`, so the report cannot tell a reader which half of the guard broke if one ever regresses. If you already rely on the assertion text inside the test for that, fine — a one-line printed reason per control would make a future bisect readable. ### Verdict Reviewed `86f29e63`. +27/-1 across the header and its test, three cases pass, the happy path is unchanged, and each of the three rejections is genuinely exercised. No objection from me.
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!1502
No description provided.