test: refuse a BC7 copy from an unreadable source #1739

Merged
ChazY11 merged 1 commit from upstream-pr/1746 into main 2026-11-24 18:28:20 +00:00
ChazY11 commented 2026-11-24 18:03:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T18:03:58Z.


What

copy_bc7_4k_s in src/startup_stubs/xg_xs.cpp probes both buffers before copying:

if (!x2w_local::readable(source, source_bytes) || !x2w_local::writable(dest, surface.size()))
    return E_FAIL;

Nothing in tests/startup_xg_bc7_layout_check.py reached that probe. Its five refusal controls — wrong plane, wrong
subresource, short row, short slice, aliased source — are all answered by the earlier E_INVALIDARG checks, so
deleting the probe leaves the fixture green:

probe replaced with `if (false)`    startup_xg_bc7_layout PASSED    (before this change)

Change

One refusal passed an address that is not mapped, expecting the E_FAIL the probe answers with, and the destination
still untouched:

+    # A source that cannot be read is refused before the copy instead of faulting inside it.
+    result = copy(computer, dest, 0, 0, ctypes.cast(1, PTR), row_pitch, slice_pitch)
+    expect(f"{label} unreadable source HRESULT", result & 0xFFFFFFFF, 0x80004005)
+    expect_bytes(f"{label} unreadable source preserves destination", target.raw, GUARD + expected + GUARD)

Tested at origin/main = 68969ed8

ctest --preset dev --no-tests=error -R '^startup_xg_bc7_' -V
with the case, probe intact       startup_xg_bc7_layout PASSED (all three shapes, refusal controls included)
with the case, probe removed      startup_xg_bc7_layout FAILED   (xg_xs.dll rebuilt, timestamp checked)
reverted, rebuilt                 all startup_xg_bc7_* PASSED

Worth naming the failure mode: with the probe removed the fixture does not report a wrong HRESULT, it faults inside the
copy — that is the behaviour the probe exists to prevent, and the fixture failing either way is the point.

Scope

One test file, no behaviour change. E_FAIL rather than E_INVALIDARG is deliberate: the arguments are well formed,
the memory is not.

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588234221 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1746). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T18:03:58Z. --- ## What `copy_bc7_4k_s` in `src/startup_stubs/xg_xs.cpp` probes both buffers before copying: ```cpp if (!x2w_local::readable(source, source_bytes) || !x2w_local::writable(dest, surface.size())) return E_FAIL; ``` Nothing in `tests/startup_xg_bc7_layout_check.py` reached that probe. Its five refusal controls — wrong plane, wrong subresource, short row, short slice, aliased source — are all answered by the earlier `E_INVALIDARG` checks, so deleting the probe leaves the fixture green: ```text probe replaced with `if (false)` startup_xg_bc7_layout PASSED (before this change) ``` ## Change One refusal passed an address that is not mapped, expecting the `E_FAIL` the probe answers with, and the destination still untouched: ```diff + # A source that cannot be read is refused before the copy instead of faulting inside it. + result = copy(computer, dest, 0, 0, ctypes.cast(1, PTR), row_pitch, slice_pitch) + expect(f"{label} unreadable source HRESULT", result & 0xFFFFFFFF, 0x80004005) + expect_bytes(f"{label} unreadable source preserves destination", target.raw, GUARD + expected + GUARD) ``` ## Tested at `origin/main` = `68969ed8` ```powershell ctest --preset dev --no-tests=error -R '^startup_xg_bc7_' -V ``` ```text with the case, probe intact startup_xg_bc7_layout PASSED (all three shapes, refusal controls included) with the case, probe removed startup_xg_bc7_layout FAILED (xg_xs.dll rebuilt, timestamp checked) reverted, rebuilt all startup_xg_bc7_* PASSED ``` Worth naming the failure mode: with the probe removed the fixture does not report a wrong HRESULT, it faults inside the copy — that is the behaviour the probe exists to prevent, and the fixture failing either way is the point. ## Scope One test file, no behaviour change. `E_FAIL` rather than `E_INVALIDARG` is deliberate: the arguments are well formed, the memory is not. ## Notes - AI-assisted.
upstream-sync closed this pull request 2026-11-24 19:01:16 +00:00
tedin7 commented 2026-11-24 19:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:24:52Z.

Review: COMMENTED


Verified at commit 360bbf3112b1b2e100f7cb1e78574ef8c38e749e (tests/startup_xg_bc7_layout_check.py only; no production/tooling/workflow changes; clean-room and title-neutral).

Scope & Code Review

  • Adds a refusal test in check_copy passing an unreadable source pointer (ctypes.cast(1, PTR)) to CopyIntoSubresource, asserting E_FAIL (0x80004005) and confirming the destination buffer and guard bytes remain untouched.
  • Matches the !x2w_local::readable(source, source_bytes) guard in copy_bc7_4k_s (src/startup_stubs/xg_xs.cpp:143-144).
  • No defects found (0 P1, 0 P2).

Linux Checks

  • git diff --check origin/main...HEAD: pass
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • python3 -m py_compile tests/startup_xg_bc7_layout_check.py: pass

Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)

  • Debug (--preset dev):
    • cmake --build --preset dev --target startup_stream_consumer startup_stub_xg_xs -- -j 8: pass (4.51s)
    • ctest --preset dev -R '^(startup_xg_bc7_layout|startup_xg_bc_array_warp|startup_xg_bc_chain_warp|startup_xg_bc_tiling|startup_xg_tile64_tiling)$' --parallel 6 --no-tests=error --output-on-failure: 5/5 passed (7.75s; startup_xg_bc7_layout 0.16s)
  • Release /O2 (--preset release):
    • cmake --build --preset release --target startup_stream_consumer startup_stub_xg_xs -- -j 8: pass (1.18s)
    • ctest --preset release -R '^(startup_xg_bc7_layout|startup_xg_bc_array_warp|startup_xg_bc_chain_warp|startup_xg_bc_tiling|startup_xg_tile64_tiling)$' --parallel 6 --no-tests=error --output-on-failure: 5/5 passed (7.87s; startup_xg_bc7_layout 0.15s)

Mutation Check (Win2025 Debug)

  • Mutated src/startup_stubs/xg_xs.cpp:143-144 in copy_bc7_4k_s to return E_INVALIDARG (0x80070057) instead of E_FAIL (0x80004005) when !x2w_local::readable(source, source_bytes).
  • Re-ran startup_xg_bc7_layout (ctest --preset dev -R '^startup_xg_bc7_layout$' --output-on-failure): failed as expected (RuntimeError: BC7 81x69 unreadable source HRESULT: got 2147942487, expected 2147500037).

Note: Competing open PRs (#1742, #1748) also modify tests/startup_xg_bc7_layout_check.py.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045000548 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1746#pullrequestreview-6045000548). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:24:52Z. **Review:** COMMENTED --- Verified at commit `360bbf3112b1b2e100f7cb1e78574ef8c38e749e` (`tests/startup_xg_bc7_layout_check.py` only; no production/tooling/workflow changes; clean-room and title-neutral). ### Scope & Code Review - Adds a refusal test in `check_copy` passing an unreadable source pointer (`ctypes.cast(1, PTR)`) to `CopyIntoSubresource`, asserting `E_FAIL` (`0x80004005`) and confirming the destination buffer and guard bytes remain untouched. - Matches the `!x2w_local::readable(source, source_bytes)` guard in `copy_bc7_4k_s` (`src/startup_stubs/xg_xs.cpp:143-144`). - No defects found (0 P1, 0 P2). ### Linux Checks - `git diff --check origin/main...HEAD`: pass - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `python3 -m py_compile tests/startup_xg_bc7_layout_check.py`: pass ### Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target startup_stream_consumer startup_stub_xg_xs -- -j 8`: pass (`4.51s`) - `ctest --preset dev -R '^(startup_xg_bc7_layout|startup_xg_bc_array_warp|startup_xg_bc_chain_warp|startup_xg_bc_tiling|startup_xg_tile64_tiling)$' --parallel 6 --no-tests=error --output-on-failure`: **5/5 passed** (`7.75s`; `startup_xg_bc7_layout` `0.16s`) - **Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target startup_stream_consumer startup_stub_xg_xs -- -j 8`: pass (`1.18s`) - `ctest --preset release -R '^(startup_xg_bc7_layout|startup_xg_bc_array_warp|startup_xg_bc_chain_warp|startup_xg_bc_tiling|startup_xg_tile64_tiling)$' --parallel 6 --no-tests=error --output-on-failure`: **5/5 passed** (`7.87s`; `startup_xg_bc7_layout` `0.15s`) ### Mutation Check (Win2025 Debug) - Mutated `src/startup_stubs/xg_xs.cpp:143-144` in `copy_bc7_4k_s` to return `E_INVALIDARG` (`0x80070057`) instead of `E_FAIL` (`0x80004005`) when `!x2w_local::readable(source, source_bytes)`. - Re-ran `startup_xg_bc7_layout` (`ctest --preset dev -R '^startup_xg_bc7_layout$' --output-on-failure`): **failed as expected** (`RuntimeError: BC7 81x69 unreadable source HRESULT: got 2147942487, expected 2147500037`). Note: Competing open PRs (#1742, #1748) also modify `tests/startup_xg_bc7_layout_check.py`. AI-assisted; commands listed were executed locally.
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!1739
No description provided.