Guard slice footprint byte spans and uploads against invalid indices #1487

Merged
tedin7 merged 2 commits from upstream-pr/1494 into main 2026-11-24 13:35:13 +00:00
tedin7 commented 2026-11-24 12:54:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:54:27Z.


Change

SliceFootprints::bytes(i) computed RowPitch * (Depth * rows[i] - 1) + row_bytes[i] unconditionally. For an index past the arrays it read out of bounds, and for an entry that was never filled (no device, unsupported format, mip count 0 or above 15) or with zero rows or depth the unsigned subtraction wrapped to a value near 2^64. SliceFootprints::upload() divided by the mip count (i % mips, i / mips), so 0 mips divided by zero, and it did not check the object pointers, the slice, the plan index or the plan size.

  • bytes() returns 0 (nothing to span) for an index past the 30 entries, and for rows or depth of 0. A pitch of 0 still spans one row.
  • upload() returns without copying for a missing list, texture or upload buffer, 0 or more than 15 mips, 0 slices, a slice past the slices, a plan index past the plan, or a plan without a size. Valid requests are unchanged. The mips bound also keeps the subresource index within 32 bits (at most about 2 million).
  • Callers checked: they already refuse an unset size and only pass indices inside the plan, so the 0 result cannot cause an out-of-bounds read or write (a 0-byte ring copy and a 0-byte memset). No caller change.
  • The bound for bytes() is the array capacity, not count, on purpose: the open PR #1486 sets entries by hand on a plan built without a device (count 1) and calls bytes(29). That test passes unchanged with this header (51 cases, run locally). No file overlap with #1486.

Verification

Test added to tests/startup_plane_refresh.cpp (check_footprint_guards, runs before any device is created): plans filled by hand for one plane and for NV12, with expected byte counts written out; invalid indices, rows 0, depth 0, pitch 0, unset plan; upload() through a stand-in command list whose only live method is CopyTextureRegion (any other method ends the run), with the expected subresource index computed by the D3D12 subresource definition (mip + slice * mips + plane * mips * slices), and nine refused requests that must make no call.

Executed locally (MinGW g++ 14 x86_64, run under Wine; the GPU part of the file is not run there):

  • Header from this branch: slice footprint guards: PASS, exit 0.
  • Header from origin/main, same test: FAIL on "index just past the arrays", "far index", "no rows", "no depth", then a page fault.
  • Header with the i >= max_mips * 2 guard removed: stack overflow from the out-of-range read. With the rows/depth guard removed: FAIL "no rows", "no depth". With the !mips check removed: divide by zero. With i >= count removed: FAIL "subresource past the plan" then crash. With size == UINT64_MAX removed: FAIL "a plan without footprints copies nothing".
  • The other open PR's test (startup_slice_footprints_check) built against this header: PASS (51 cases).
  • git diff --check: clean.

Not run here: the Windows GPU part (startup_plane_refresh_warp, startup_nv12_draw_warp). These are outside --preset pr; run on the Windows node: ctest --preset dev --no-tests=error -R "^(startup_plane_refresh|startup_nv12_draw)_warp$" -V.

Evidence and follow-up

  • No change to the XG writer or the draw uploader; valid plans (NV12 Y+UV, mips 1 to 15, slice below slices) take the same path as before.
  • docs/experiments.md is not changed: no public capability is added.
  • x2w_pipe.py preflight is blocked by a local command hook, so title, overlap and secrets were checked by hand.

AI-assisted; commands listed were executed locally.

Checklist

  • One behavior, two files, no new dependencies
  • Test fails on origin/main and passes with the change
  • No game data, dumps or binaries
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582243668 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1494). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:54:27Z. --- ## Change `SliceFootprints::bytes(i)` computed `RowPitch * (Depth * rows[i] - 1) + row_bytes[i]` unconditionally. For an index past the arrays it read out of bounds, and for an entry that was never filled (no device, unsupported format, mip count 0 or above 15) or with zero rows or depth the unsigned subtraction wrapped to a value near 2^64. `SliceFootprints::upload()` divided by the mip count (`i % mips`, `i / mips`), so 0 mips divided by zero, and it did not check the object pointers, the slice, the plan index or the plan size. - `bytes()` returns 0 (nothing to span) for an index past the 30 entries, and for rows or depth of 0. A pitch of 0 still spans one row. - `upload()` returns without copying for a missing list, texture or upload buffer, 0 or more than 15 mips, 0 slices, a slice past the slices, a plan index past the plan, or a plan without a size. Valid requests are unchanged. The mips bound also keeps the subresource index within 32 bits (at most about 2 million). - Callers checked: they already refuse an unset size and only pass indices inside the plan, so the 0 result cannot cause an out-of-bounds read or write (a 0-byte ring copy and a 0-byte memset). No caller change. - The bound for `bytes()` is the array capacity, not `count`, on purpose: the open PR #1486 sets entries by hand on a plan built without a device (count 1) and calls `bytes(29)`. That test passes unchanged with this header (51 cases, run locally). No file overlap with #1486. ## Verification Test added to `tests/startup_plane_refresh.cpp` (`check_footprint_guards`, runs before any device is created): plans filled by hand for one plane and for NV12, with expected byte counts written out; invalid indices, rows 0, depth 0, pitch 0, unset plan; `upload()` through a stand-in command list whose only live method is `CopyTextureRegion` (any other method ends the run), with the expected subresource index computed by the D3D12 subresource definition (mip + slice * mips + plane * mips * slices), and nine refused requests that must make no call. Executed locally (MinGW g++ 14 x86_64, run under Wine; the GPU part of the file is not run there): - Header from this branch: `slice footprint guards: PASS`, exit 0. - Header from origin/main, same test: FAIL on "index just past the arrays", "far index", "no rows", "no depth", then a page fault. - Header with the `i >= max_mips * 2` guard removed: stack overflow from the out-of-range read. With the rows/depth guard removed: FAIL "no rows", "no depth". With the `!mips` check removed: divide by zero. With `i >= count` removed: FAIL "subresource past the plan" then crash. With `size == UINT64_MAX` removed: FAIL "a plan without footprints copies nothing". - The other open PR's test (`startup_slice_footprints_check`) built against this header: PASS (51 cases). - `git diff --check`: clean. Not run here: the Windows GPU part (`startup_plane_refresh_warp`, `startup_nv12_draw_warp`). These are outside `--preset pr`; run on the Windows node: `ctest --preset dev --no-tests=error -R "^(startup_plane_refresh|startup_nv12_draw)_warp$" -V`. ## Evidence and follow-up - No change to the XG writer or the draw uploader; valid plans (NV12 Y+UV, mips 1 to 15, slice below slices) take the same path as before. - docs/experiments.md is not changed: no public capability is added. - `x2w_pipe.py preflight` is blocked by a local command hook, so title, overlap and secrets were checked by hand. AI-assisted; commands listed were executed locally. ## Checklist - [x] One behavior, two files, no new dependencies - [x] Test fails on origin/main and passes with the change - [x] No game data, dumps or binaries
upstream-sync closed this pull request 2026-11-24 14:02:55 +00:00
tedin7 commented 2026-11-24 14:03:22 +00:00 (Migrated from github.com)

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


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

  • Debug (--preset dev): ctest --preset dev -R '^startup_plane_refresh_' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed (startup_plane_refresh_hardware, startup_plane_refresh_warp)
  • Release /O2 (--preset release): ctest --preset release -R '^startup_plane_refresh_' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed
  • Rebased onto current origin/main; git diff --check and tests/bidi_controls_check.py clean; GitHub CI green.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132284311 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1494#issuecomment-7132284311). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:03:19Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `4da7bd7f93d747a38954b374ea40400ad254aec1`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^startup_plane_refresh_' --parallel 4 --no-tests=error --output-on-failure`: **2/2 passed** (`startup_plane_refresh_hardware`, `startup_plane_refresh_warp`) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^startup_plane_refresh_' --parallel 4 --no-tests=error --output-on-failure`: **2/2 passed** - Rebased onto current `origin/main`; `git diff --check` and `tests/bidi_controls_check.py` clean; GitHub CI green. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 14:03:22 +00:00 (Migrated from github.com)

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


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:05:48.672289Z 4da7bd7 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:7132287919 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1494#issuecomment-7132287919). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:03:28Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4da7bd7f93d747a38954b374ea40400ad254aec1","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:05:48.672289Z">2026-11-24T13:05:48.672289Z</relative-time> | `4da7bd7` | 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>
R0Y00 commented 2026-11-24 14:03:25 +00:00 (Migrated from github.com)

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


Maintainer update at 982e0303 checks 64-bit byte spans and calculates the destination index before narrowing to UINT. The source-built overflow controls and both Windows Release plane refresh cases passed on RTX and WARP (2/2).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132929542 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1494#issuecomment-7132929542). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:30:30Z. --- Maintainer update at 982e0303 checks 64-bit byte spans and calculates the destination index before narrowing to UINT. The source-built overflow controls and both Windows Release plane refresh cases passed on RTX and WARP (2/2).
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!1487
No description provided.