shader: pin candidate container field refusals in sgd5_effects_check #1829

Merged
Asimmimx merged 1 commit from upstream-pr/1836 into main 2026-11-24 19:35:25 +00:00
Asimmimx commented 2026-11-24 19:20:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T19:20:28Z.


Change

tests/sgd5_effects_check.py built every program record with the same wrapper,
reflection block and DXIL header. As a result, most of the checks that
tools/sgd5_effects.py applies to one candidate container were never run with
a value that fails them. I applied single-point mutants to the tool by hand and
ran the existing check after each one. These ten mutants passed the existing
check:

Mutant (in tools/sgd5_effects.py) Existing check With the new cases
read_program: 12 < size -> 12 <= size (accept an empty compressed stream) survived killed
read_program: reflection length 9 + 24 * (registers + buffers) -> 9 + 24 * registers survived killed
read_program: drop reflection != repeated survived killed
inspect_container: drop not decoder.eof survived killed
inspect_container: drop decoder.unused_data survived killed
inspect_container: len(blob) != program.decoded -> > survived killed
inspect_container: len(dxil) < 24 -> < 0 survived killed
inspect_container: drop magic != b"DXIL" survived killed
inspect_container: payload_offset < 16 -> < 15 survived killed
inspect_container: payload_size < 4 -> < 0 survived killed

The program() helper gets optional dxil, pack, declared and
reflection arguments. Their defaults produce the same bytes as before, and the
existing cases do not change. The new test_container_fields places one program
in the PS table of a one-effect group and selects it. The cases are:

  • a valid record with one register and one buffer. The reflection block is
    9 + 2 * 24 = 57 bytes. The candidate digest must match.
  • reflection length 9 with the repeated length 10: reflection block error.
  • a wrapper with no compressed bytes (size 12): bounded error.
  • a stream with one byte after the final deflate block, a stream that ends
    without a final block (Z_SYNC_FLUSH), and a decoded size that is one byte
    too long: each gives container disagrees.
  • a DXIL part of 20 bytes: Truncated error.
  • a program tag of DXBC, a payload offset of 15 and a payload size of 3: each
    gives invalid header. The part still declares eight words (32 bytes), so
    8 + 15 + 8 = 31 and 8 + 16 + 3 = 27 both fit. Only the field under test is
    wrong.

Each refusal is matched by its message, so a case cannot pass because a later
check rejects the input. For example, without the size check the empty stream
reaches the decoder and fails as container disagrees. The bounded regex
does not match that message.

Verification

Based on origin/main 813045b3c1. Windows 11 Pro
26300.9974, Python 3.12.10.

> python -B tests/sgd5_effects_check.py -v
test_candidates_and_boundaries (__main__.EffectChecks.test_candidates_and_boundaries) ... ok
test_container_fields (__main__.EffectChecks.test_container_fields) ... ok
test_padded_dxil_part (__main__.EffectChecks.test_padded_dxil_part) ... ok
test_selected_container_reads (__main__.EffectChecks.test_selected_container_reads) ... ok
Ran 4 tests in 0.298s
OK

> python -B tests/docs_links_check.py
Checked 18 Markdown files and 369 links.

> python -B tests/bidi_controls_check.py
Checked 1320 tracked source, script and build/CI files: no bidirectional controls.

For the mutation table, I applied each mutant to tools/sgd5_effects.py and ran
python -B tests/sgd5_effects_check.py. Then I restored the file. On the
unmodified tool, all ten mutants fail the new test and the check passes.

Evidence and follow-up

All inputs are synthetic and built inside the check. No game files are used.

The same probe found other mutants that the check still does not catch. I left
them out to keep this PR to one behavior. Another contributor can pick them up:

  • candidates: the SGD5 group magic check can be removed, and
    group_start + 32 <= arrays can become + 31. Neither change fails the check.
  • The effect-count fit rule: before // 36 -> // 35, after // 36 -> // 35,
    and either half of before and (before < 36 or effect_count == 1) can be
    dropped without failing the check.
  • Cursor.name: the minimum length (2), the trailing NUL and the printable range
    have no rejecting case.
  • validate_name_block: dropping tail[-1], the minimum length 5 or
    starts != 1 -> starts < 1 (two sized blocks that both end at the boundary)
    are not caught.
  • 32 <= decoded is caught for a selected program because parts() rejects a
    container shorter than 32 bytes, but not for an unselected table entry.
  • The 4096-reference, 65536-program and 64 KiB record budgets are only tested
    on one side, or not at all.

The tool is not changed.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (Not applicable: no capability or requirement changes.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589569127 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1836). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T19:20:28Z. --- ## Change `tests/sgd5_effects_check.py` built every program record with the same wrapper, reflection block and DXIL header. As a result, most of the checks that `tools/sgd5_effects.py` applies to one candidate container were never run with a value that fails them. I applied single-point mutants to the tool by hand and ran the existing check after each one. These ten mutants passed the existing check: | Mutant (in `tools/sgd5_effects.py`) | Existing check | With the new cases | |---|---|---| | `read_program`: `12 < size` -> `12 <= size` (accept an empty compressed stream) | survived | killed | | `read_program`: reflection length `9 + 24 * (registers + buffers)` -> `9 + 24 * registers` | survived | killed | | `read_program`: drop `reflection != repeated` | survived | killed | | `inspect_container`: drop `not decoder.eof` | survived | killed | | `inspect_container`: drop `decoder.unused_data` | survived | killed | | `inspect_container`: `len(blob) != program.decoded` -> `>` | survived | killed | | `inspect_container`: `len(dxil) < 24` -> `< 0` | survived | killed | | `inspect_container`: drop `magic != b"DXIL"` | survived | killed | | `inspect_container`: `payload_offset < 16` -> `< 15` | survived | killed | | `inspect_container`: `payload_size < 4` -> `< 0` | survived | killed | The `program()` helper gets optional `dxil`, `pack`, `declared` and `reflection` arguments. Their defaults produce the same bytes as before, and the existing cases do not change. The new `test_container_fields` places one program in the PS table of a one-effect group and selects it. The cases are: - a valid record with one register and one buffer. The reflection block is 9 + 2 * 24 = 57 bytes. The candidate digest must match. - reflection length 9 with the repeated length 10: `reflection block` error. - a wrapper with no compressed bytes (size 12): `bounded` error. - a stream with one byte after the final deflate block, a stream that ends without a final block (`Z_SYNC_FLUSH`), and a decoded size that is one byte too long: each gives `container disagrees`. - a DXIL part of 20 bytes: `Truncated` error. - a program tag of `DXBC`, a payload offset of 15 and a payload size of 3: each gives `invalid header`. The part still declares eight words (32 bytes), so 8 + 15 + 8 = 31 and 8 + 16 + 3 = 27 both fit. Only the field under test is wrong. Each refusal is matched by its message, so a case cannot pass because a later check rejects the input. For example, without the size check the empty stream reaches the decoder and fails as `container disagrees`. The `bounded` regex does not match that message. ## Verification Based on `origin/main` 813045b3c13f7bad20d8577557b621ee869ccbba. Windows 11 Pro 26300.9974, Python 3.12.10. ```text > python -B tests/sgd5_effects_check.py -v test_candidates_and_boundaries (__main__.EffectChecks.test_candidates_and_boundaries) ... ok test_container_fields (__main__.EffectChecks.test_container_fields) ... ok test_padded_dxil_part (__main__.EffectChecks.test_padded_dxil_part) ... ok test_selected_container_reads (__main__.EffectChecks.test_selected_container_reads) ... ok Ran 4 tests in 0.298s OK > python -B tests/docs_links_check.py Checked 18 Markdown files and 369 links. > python -B tests/bidi_controls_check.py Checked 1320 tracked source, script and build/CI files: no bidirectional controls. ``` For the mutation table, I applied each mutant to `tools/sgd5_effects.py` and ran `python -B tests/sgd5_effects_check.py`. Then I restored the file. On the unmodified tool, all ten mutants fail the new test and the check passes. ## Evidence and follow-up All inputs are synthetic and built inside the check. No game files are used. The same probe found other mutants that the check still does not catch. I left them out to keep this PR to one behavior. Another contributor can pick them up: - `candidates`: the `SGD5` group magic check can be removed, and `group_start + 32 <= arrays` can become `+ 31`. Neither change fails the check. - The effect-count fit rule: `before // 36` -> `// 35`, `after // 36` -> `// 35`, and either half of `before and (before < 36 or effect_count == 1)` can be dropped without failing the check. - `Cursor.name`: the minimum length (2), the trailing NUL and the printable range have no rejecting case. - `validate_name_block`: dropping `tail[-1]`, the minimum length 5 or `starts != 1` -> `starts < 1` (two sized blocks that both end at the boundary) are not caught. - `32 <= decoded` is caught for a selected program because `parts()` rejects a container shorter than 32 bytes, but not for an unselected table entry. - The 4096-reference, 65536-program and 64 KiB record budgets are only tested on one side, or not at all. The tool is not changed. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [ ] I updated README/docs when a capability or build requirement changed. (Not applicable: no capability or requirement changes.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 20:00:54 +00:00
tedin7 commented 2026-11-24 20:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:33:18Z.

Review: COMMENTED


Reviewed tests/sgd5_effects_check.py at commit 6dfabe097ff6ee43c18362636365371f373cbf25 against tools/sgd5_effects.py (read_program and inspect_container). All new positive and negative container-field assertions pin real reflection-length, deflate framing, decoded-size, and DXIL header bounds; clean-room and title-neutral, 0 P1/P2 defects found.

Linux verification

  • git diff --check origin/main...HEAD — passed
  • python -B tests/bidi_controls_check.py — passed (1320 files checked)
  • python -B tests/sgd5_effects_check.py -v — 4/4 tests passed (0.243s)

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

  • Debug (--preset dev): ctest --preset dev -R '^sgd5_effect_candidates$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (0.35s)
  • Release /O2 (--preset release): ctest --preset release -R '^sgd5_effect_candidates$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (0.35s)

Local mutation checks

  • Mutated tools/sgd5_effects.py to drop not decoder.eof or decoder.unused_data in inspect_container: python -B tests/sgd5_effects_check.py failed (rc=1, killed).
  • Mutated tools/sgd5_effects.py to relax payload_offset < 16 or payload_size < 4 to < 15 / < 3: python -B tests/sgd5_effects_check.py failed (rc=1, killed).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045996691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1836#pullrequestreview-6045996691). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:33:18Z. **Review:** COMMENTED --- Reviewed `tests/sgd5_effects_check.py` at commit `6dfabe097ff6ee43c18362636365371f373cbf25` against `tools/sgd5_effects.py` (`read_program` and `inspect_container`). All new positive and negative container-field assertions pin real reflection-length, deflate framing, decoded-size, and DXIL header bounds; clean-room and title-neutral, 0 P1/P2 defects found. ### Linux verification - `git diff --check origin/main...HEAD` — passed - `python -B tests/bidi_controls_check.py` — passed (1320 files checked) - `python -B tests/sgd5_effects_check.py -v` — 4/4 tests passed (`0.243s`) ### Windows Server 2025 verification (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Debug (`--preset dev`)**: `ctest --preset dev -R '^sgd5_effect_candidates$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`0.35s`) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^sgd5_effect_candidates$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`0.35s`) ### Local mutation checks - Mutated `tools/sgd5_effects.py` to drop `not decoder.eof or decoder.unused_data` in `inspect_container`: `python -B tests/sgd5_effects_check.py` failed (`rc=1`, killed). - Mutated `tools/sgd5_effects.py` to relax `payload_offset < 16 or payload_size < 4` to `< 15` / `< 3`: `python -B tests/sgd5_effects_check.py` failed (`rc=1`, killed). 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!1829
No description provided.