Scripts: skip invalid or truncated DXBC matches in bvhb_shaders #1483

Open
microwave805 wants to merge 1 commit from upstream-pr/1493 into main
microwave805 commented 2026-11-24 16:54:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T16:54:20Z.


scripts/re/bvhb_shaders.py scans an input binary for raw b'DXBC' occurrences and unconditionally unpacked the size at +24 and every chunk offset in parts(). A b'DXBC' near EOF, a truncated container, or a false-positive match with an in-range dword at +24 raised struct.error and aborted extraction before later real DXBC containers were reached.

What is in it

  • scripts/re/bvhb_shaders.py: check header bounds before unpacking, validate DXBC version == 1, container length against the file size, non-zero part count, and every chunk's offset and size inside parts(), skipping invalid candidates cleanly.
  • scripts/test_bvhb_shaders.py: add a synthetic binary containing bogus-version, out-of-bounds-offset, valid, truncated, and trailing-EOF DXBC hits and verify only the valid container is extracted.

Tested

  • NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc, debug), Python 3.11.3
  • Before the fix: python -I -m unittest discover -s scripts -p "test_bvhb_shaders.py" -v: 1 passed, 1 error (exit status 1 on invalid DXBC hit)
  • On PR head 7a0ed4c:
    • python -I -m unittest discover -s scripts -p "test_*.py" -v: 17 passed, 0 failed
    • .\scripts\test.ps1 (cargo build --workspace && cargo test --workspace -- --test-threads=4): 770 passed, 0 failed, 41 ignored
    • SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Regression run

  • Not needed: changes only scripts/re/bvhb_shaders.py and scripts/test_bvhb_shaders.py (no runtime or build-input files).

Not tested

  • Real XboxBvhBuilder.dll binary (no console binaries)
  • AMD / wave64 GPUs and retail titles

AI use

  • Antigravity (Gemini 4 Neon): identified the unvalidated DXBC scan crash in scripts/re/bvhb_shaders.py, wrote the fix, unit test, and PR description, and ran the verification commands above.
<!-- greyfinch-sync:ivall/xcl:issue:5476581310 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T16:54:20Z. --- `scripts/re/bvhb_shaders.py` scans an input binary for raw `b'DXBC'` occurrences and unconditionally unpacked the size at `+24` and every chunk offset in `parts()`. A `b'DXBC'` near EOF, a truncated container, or a false-positive match with an in-range dword at `+24` raised `struct.error` and aborted extraction before later real DXBC containers were reached. **What is in it** - `scripts/re/bvhb_shaders.py`: check header bounds before unpacking, validate DXBC version `== 1`, container length against the file size, non-zero part count, and every chunk's offset and size inside `parts()`, skipping invalid candidates cleanly. - `scripts/test_bvhb_shaders.py`: add a synthetic binary containing bogus-version, out-of-bounds-offset, valid, truncated, and trailing-EOF `DXBC` hits and verify only the valid container is extracted. **Tested** - NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`, debug), Python 3.11.3 - Before the fix: `python -I -m unittest discover -s scripts -p "test_bvhb_shaders.py" -v`: 1 passed, 1 error (exit status 1 on invalid `DXBC` hit) - On PR head `7a0ed4c`: - `python -I -m unittest discover -s scripts -p "test_*.py" -v`: 17 passed, 0 failed - `.\scripts\test.ps1` (`cargo build --workspace && cargo test --workspace -- --test-threads=4`): 770 passed, 0 failed, 41 ignored - SKIPPED GPU tests: `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (no wave64) **Regression run** - Not needed: changes only `scripts/re/bvhb_shaders.py` and `scripts/test_bvhb_shaders.py` (no runtime or build-input files). **Not tested** - Real `XboxBvhBuilder.dll` binary (no console binaries) - AMD / wave64 GPUs and retail titles **AI use** - Antigravity (Gemini 4 Neon): identified the unvalidated DXBC scan crash in `scripts/re/bvhb_shaders.py`, wrote the fix, unit test, and PR description, and ran the verification commands above.
DavidM1911 commented 2026-11-24 19:07:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:31Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141297648 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493#issuecomment-7141297648). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:53:31Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
jeroenhaentjens commented 2026-11-25 14:10:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-11-25T13:26:11Z.


Independent Windows/NVIDIA validation of 7a0ed4c62372767a5068b190b8136071a03abaf2 (the PR head, detached checkout with no source changes).

Tested

  • Windows 11 Pro, build 26200; Intel Core i7-9750H; NVIDIA Quadro RTX 3000, driver 32.0.15.9706; Rust 1.100.0; Python 3.10.0.
  • python -B -m unittest discover -s scripts -p 'test_*.py' -v: 17 passed, exit 0.
  • cargo build --workspace --locked: passed, exit 0.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 770 passed, 0 failed, 41 ignored, 20 completed suites, exit 0.
  • Debug profiles with debug information disabled (CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0), CARGO_INCREMENTAL=0, XCL_ADAPTER=nvidia, XCL_HEAP_WINDOWS=1, and XCL_DXC_DIR pointing to DXC 1.9.2609.5.

Two explicit GPU skip records, included in Cargo's passed count and not counted as exercised coverage:

  • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64.
  • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

I also ran five separate, game-data-free CLI cases against the PR script and HEAD^'s script:

Synthetic input Parent exit PR exit PR output
Bare DXBC at EOF 1 0 No files
24-byte truncated DXBC header 1 0 No files
64-byte container with chunk offset 0x100, then a valid container 1 0 One valid file
Valid container, then bare DXBC at EOF 1 0 One valid file
Valid container only 0 0 One valid file

The four parent failures were struct.error. Every extracted file on the PR matched the synthetic valid input byte for byte. The valid fixture was a single RTS0 chunk containing struct.pack('<6I', 1, 0, 24, 0, 0, 0).

Not tested

  • AMD hardware, wave64 execution, retail titles, or a real XboxBvhBuilder.dll. All extractor inputs were synthetic.
  • XCL_SAMPLE_* variables were unset, so sample-dependent tests do not establish coverage of game data.
  • This is a run of the exact PR head, not a merge with current main.

AI use
Codex generated the additional synthetic cases, ran the commands and wrote this report. The exact model identifier was not exposed in this session.

<!-- greyfinch-sync:ivall/xcl:comment:7163773805 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493#issuecomment-7163773805). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-11-25T13:26:11Z. --- Independent Windows/NVIDIA validation of `7a0ed4c62372767a5068b190b8136071a03abaf2` (the PR head, detached checkout with no source changes). **Tested** - Windows 11 Pro, build 26200; Intel Core i7-9750H; NVIDIA Quadro RTX 3000, driver `32.0.15.9706`; Rust 1.100.0; Python 3.10.0. - `python -B -m unittest discover -s scripts -p 'test_*.py' -v`: **17 passed**, exit 0. - `cargo build --workspace --locked`: passed, exit 0. - `cargo test --workspace --locked --no-fail-fast -- --test-threads=4`: **770 passed, 0 failed, 41 ignored**, 20 completed suites, exit 0. - Debug profiles with debug information disabled (`CARGO_PROFILE_DEV_DEBUG=0`, `CARGO_PROFILE_TEST_DEBUG=0`), `CARGO_INCREMENTAL=0`, `XCL_ADAPTER=nvidia`, `XCL_HEAP_WINDOWS=1`, and `XCL_DXC_DIR` pointing to DXC 1.9.2609.5. Two explicit GPU skip records, included in Cargo's passed count and **not** counted as exercised coverage: - `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`: no wave64. - `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`: no wave64. I also ran five separate, game-data-free CLI cases against the PR script and `HEAD^`'s script: | Synthetic input | Parent exit | PR exit | PR output | | --- | --- | --- | --- | | Bare `DXBC` at EOF | 1 | 0 | No files | | 24-byte truncated DXBC header | 1 | 0 | No files | | 64-byte container with chunk offset 0x100, then a valid container | 1 | 0 | One valid file | | Valid container, then bare `DXBC` at EOF | 1 | 0 | One valid file | | Valid container only | 0 | 0 | One valid file | The four parent failures were `struct.error`. Every extracted file on the PR matched the synthetic valid input byte for byte. The valid fixture was a single RTS0 chunk containing `struct.pack('<6I', 1, 0, 24, 0, 0, 0)`. **Not tested** - AMD hardware, wave64 execution, retail titles, or a real XboxBvhBuilder.dll. All extractor inputs were synthetic. - `XCL_SAMPLE_*` variables were unset, so sample-dependent tests do not establish coverage of game data. - This is a run of the exact PR head, not a merge with current main. **AI use** Codex generated the additional synthetic cases, ran the commands and wrote this report. The exact model identifier was not exposed in this session.
upipibi commented 2026-11-26 22:03:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T22:03:12Z.


Tested head 7a0ed4c62372767a5068b190b8136071a03abaf2 (merge-base with main b7aa9f3bd212088e0d927439284dc5ed325ce3c7) on Windows 11 Pro 26100, Python 3.13.0, CPU only.

cd scripts; py -3.13 -m unittest test_bvhb_shaders: head 2 passed, 0 failed; merge-base 1 passed, 0 failed. Negative control: PR's test hunk alone on the merge-base gives 1 passed, 1 failed (test_skips_false_positive_and_truncated_dxbc_headers: CalledProcessError, bvhb_shaders.py exits 1).

Not tested: GPU, retail title, real game binaries. AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

<!-- greyfinch-sync:ivall/xcl:comment:7204311064 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493#issuecomment-7204311064). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-26T22:03:12Z. --- Tested head `7a0ed4c62372767a5068b190b8136071a03abaf2` (merge-base with main `b7aa9f3bd212088e0d927439284dc5ed325ce3c7`) on Windows 11 Pro 26100, Python 3.13.0, CPU only. `cd scripts; py -3.13 -m unittest test_bvhb_shaders`: head 2 passed, 0 failed; merge-base 1 passed, 0 failed. Negative control: PR's test hunk alone on the merge-base gives 1 passed, 1 failed (`test_skips_false_positive_and_truncated_dxbc_headers`: CalledProcessError, bvhb_shaders.py exits 1). Not tested: GPU, retail title, real game binaries. AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
github-actions[bot] commented 2026-12-01 02:35:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:35:56Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298789365 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493#issuecomment-7298789365). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:35:56Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:55:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:55:26Z.


Triage (#1607) – head 7a0ed4c

#1858 also stops scripts/re/bvhb_shaders.py from reading past truncated DXBC matches, but in a different way: it bounds-checks the reads inside a larger CLI rewrite and still extracts false-positive blobs, while this PR validates the container (version 1, total size, part offsets/sizes) and skips the match.
No problems found in the diff; the header fields read at offset 20 (version, total size, part count) follow the DXBC layout.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302282778 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1493#issuecomment-7302282778). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:55:26Z. --- **Triage (#1607)** – head 7a0ed4c #1858 also stops scripts/re/bvhb_shaders.py from reading past truncated DXBC matches, but in a different way: it bounds-checks the reads inside a larger CLI rewrite and still extracts false-positive blobs, while this PR validates the container (version 1, total size, part offsets/sizes) and skips the match. No problems found in the diff; the header fields read at offset 20 (version, total size, part count) follow the DXBC layout. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1493:upstream-pr/1493'
git switch 'upstream-pr/1493'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1493'
git switch 'upstream-pr/1493'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1493'
git switch 'upstream-pr/1493'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1493'
git switch 'main'
git merge --squash 'upstream-pr/1493'
git switch 'main'
git merge --ff-only 'upstream-pr/1493'
git switch 'main'
git merge 'upstream-pr/1493'
git push origin 'main'
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
xcl-dev/xcl!1483
No description provided.