Scripts: harden check_layout CLI, DXBC validation, and error handling #2151

Open
github-bot wants to merge 1 commit from github-bot/gh-2151 into main AGit
Owner

@⁠HumanlyDev on GitHub · 2026-11-25 06:24 UTC · original
HumanlyDev:scripts/harden-check-layout → main · +338 −21 · 2 files · 1 commits · open

Harden scripts/re/check_layout.py so malformed/non-DXBC files, DXBC blobs without RTS0, subdirectories, disassembler errors, off-boundary loads, and missing/invalid CLI arguments are handled cleanly instead of crashing or silently passing, and add unit tests in scripts/test_check_layout.py. Non-runtime change under scripts/.

What is in it

  • scripts/re/check_layout.py:
    • Move CLI execution under if __name__ == '__main__': (parse_args, check_listing, main) with <dir> [--xcl <path>] argument validation.
    • Validate b'DXBC' magic and chunk/RTS0 bounds in parts() and layout(), skip subdirectories and non-.dxbc files, handle rs is None cleanly, and read files with with open(...).
    • Verify the xcl binary exists and subprocess.run exits 0, and return exit code 1 when off-boundary loads (bad > 0) or disassembler errors occur.
  • scripts/test_check_layout.py:
    • 8 unit tests covering parts/layout (with/without RTS0, non-DXBC, truncated containers), directory scanning with subdirs/non-.dxbc/invalid .dxbc, mocked xcl disasm failures and missing --xcl, on-boundary vs off-boundary s_load_dword detection, and CLI argument error handling.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 4060 (32.0.16.1088), AMD Ryzen 5 7600, Windows 11 Pro 10.0.26200 (build 26200), Python 3.14.6, rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.8.2502.11.
  • python -m unittest scripts/test_check_layout.py -v: 8 passed, 0 failed (OK in 0.218s).
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4, RTX 4060, debug): 1154 passed, 0 failed, 46 ignored across 21 targets (25 SKIPPED GPU checks: 20 no wave64, 3 per-lane form #1426 refusals, 1 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode is required)).

Regression run

  • Not needed: script/test-only change under scripts/ (no runtime files under crates/xcl/src/ modified).

Not tested

  • Running scripts/re/check_layout.py against a live directory of extracted bvhb_shaders.py .dxbc files (not present on this machine), retail titles / XCL_SAMPLE_*, AMD RDNA3/4, Linux / Wine.

AI use

  • Antigravity (Google DeepMind; Gemini 4): audited scripts/re/check_layout.py, wrote the hardening changes and scripts/test_check_layout.py, ran the unit tests and workspace suite, and drafted this PR description.
**@⁠HumanlyDev** on GitHub · 2026-11-25 06:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151) `HumanlyDev:scripts/harden-check-layout` → `main` · +338 −21 · 2 files · 1 commits · open Harden `scripts/re/check_layout.py` so malformed/non-DXBC files, DXBC blobs without `RTS0`, subdirectories, disassembler errors, off-boundary loads, and missing/invalid CLI arguments are handled cleanly instead of crashing or silently passing, and add unit tests in `scripts/test_check_layout.py`. Non-runtime change under `scripts/`. **What is in it** - `scripts/re/check_layout.py`: - Move CLI execution under `if __name__ == '__main__':` (`parse_args`, `check_listing`, `main`) with `<dir> [--xcl <path>]` argument validation. - Validate `b'DXBC'` magic and chunk/RTS0 bounds in `parts()` and `layout()`, skip subdirectories and non-`.dxbc` files, handle `rs is None` cleanly, and read files with `with open(...)`. - Verify the `xcl` binary exists and `subprocess.run` exits `0`, and return exit code `1` when off-boundary loads (`bad > 0`) or disassembler errors occur. - `scripts/test_check_layout.py`: - 8 unit tests covering `parts`/`layout` (with/without `RTS0`, non-DXBC, truncated containers), directory scanning with subdirs/non-`.dxbc`/invalid `.dxbc`, mocked `xcl disasm` failures and missing `--xcl`, on-boundary vs off-boundary `s_load_dword` detection, and CLI argument error handling. **Tested** - Hardware & toolchain: NVIDIA GeForce RTX 4060 (`32.0.16.1088`), AMD Ryzen 5 7600, Windows 11 Pro `10.0.26200` (build `26200`), Python `3.14.6`, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, DXC `1.8.2502.11`. - `python -m unittest scripts/test_check_layout.py -v`: 8 passed, 0 failed (`OK` in 0.218s). - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`, RTX 4060, debug): 1154 passed, 0 failed, 46 ignored across 21 targets (25 SKIPPED GPU checks: 20 `no wave64`, 3 `per-lane form` `#1426` refusals, 1 `no heap windows`, 1 `cannot disable the driver cache (Windows Developer Mode is required)`). **Regression run** - Not needed: script/test-only change under `scripts/` (no runtime files under `crates/xcl/src/` modified). **Not tested** - Running `scripts/re/check_layout.py` against a live directory of extracted `bvhb_shaders.py` `.dxbc` files (not present on this machine), retail titles / `XCL_SAMPLE_*`, AMD RDNA3/4, Linux / Wine. **AI use** - Antigravity (Google DeepMind; Gemini 4): audited `scripts/re/check_layout.py`, wrote the hardening changes and `scripts/test_check_layout.py`, ran the unit tests and workspace suite, and drafted this PR description.
Replace top-level argv/execution with an argparse main() entrypoint (<dir> [--xcl <path>]), validate DXBC headers/chunk bounds and RTS0 bounds, skip non-files/non-DXBC entries and DXBCs lacking RTS0 safely, and fail with exit code 1 when xcl is missing, disasm fails, or off-boundary scalar loads are detected. Added unit tests in scripts/test_check_layout.py.

Assisted-by: Antigravity (Gemini 4)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:39 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 07:04 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 07:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151#issuecomment-7155464288) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 10:46 UTC · original

Diff audited (scripts/re/check_layout.py bounds checks + test_check_layout.py) and CI workflow approved (running). Needs Build and test green plus independent test verification.

**@⁠raylitebull** on GitHub · 2026-11-25 10:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151#issuecomment-7160161659) Diff audited (`scripts/re/check_layout.py` bounds checks + `test_check_layout.py`) and CI workflow approved (running). Needs `Build and test` green plus independent test verification.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:28 UTC · original

Review note on aa825c0: @RavenCurseBurg noted that scripts/re/check_layout.py misses zero-offset s_load_dword ..., null spellings (emitted by XCL's formatter and LLVM AMDGPU examples). Addressing that plus getting independent verification of test_check_layout.py will unblock merge.

**@⁠raylitebull** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151#issuecomment-7170958261) Review note on `aa825c0`: `@RavenCurseBurg` noted that `scripts/re/check_layout.py` misses zero-offset `s_load_dword ..., null` spellings (emitted by XCL's formatter and LLVM AMDGPU examples). Addressing that plus getting independent verification of `test_check_layout.py` will unblock merge.
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 11:43 UTC · original · edited 2026-11-26 10:39 UTC

I compared this head (aa825c088e65db380f67a112e0474e56ea841b6a) with #1088 using a native disassembler stand-in and the same two synthetic shader files. Both reported stderr, but a child that exited 23 with a stdout-only diagnostic lost its message here. A one-line follow-up and regression assertion retain stdout when stderr is empty. The batch still checks the second file, counts its successful load and exits 1. Stderr still takes precedence; a silent failure retains the numeric fallback. Five native cases passed on the candidate, including an all-success control. The new assertion failed on the original script; with the fix, python -B -m unittest discover -s scripts -p "test_*.py" passed 33/33. The eight focused tests also passed when combined locally with the earlier null-offset candidate 931c40a. Windows 11, Core i7-13700, Python 3.14.3; no retail shaders or GPU work. OpenAI Codex (GPT-6) prepared the fix and ran the checks.

Earlier verification

Tested aa825c088e65db380f67a112e0474e56ea841b6a on Windows 11 24H2 (26100.9711), i7-13700, Python 3.14.3.

Tested

  • python -B -m unittest discover -s scripts -p test_check_layout.py passed all 8 tests (0 failures, 0 skips).
  • Ran scripts/re/check_layout.py <fixture-dir> --xcl <fixture-disasm.cmd> on a synthetic root signature with one 8-byte CBV at offset 0. The stand-in printed the pointer-copy instructions and one scalar load. Offsets 0x0 and 0x4 each counted as one on-boundary load (exit 0). Offset 0x8 counted as one off-boundary load (exit 1).
  • For the zero-offset spelling s_load_dword s5, s[2:3], null, the checker reported 0 on, 0 off (exit 0). This exact load is in the tracked LLVM example, and XCL's formatter emits null for this case.
  • I tested a follow-up commit based on this head. The extended assertion failed on the PR head and all 8 tests passed with the patch. In the same CLI fixture, null then counted as one on-boundary load and the other three results stayed the same.

Not tested

Actual XCL disassembly, retail shader inputs or the Rust/GPU workspace suite.

AI use

OpenAI Codex (GPT-6) ran the tests, wrote the CLI fixture and follow-up patch, and prepared this report.

Follow-up on the review at aa825c088e65. Tested candidate 23825658d. A directory containing only a four-byte DXBC file previously returned 0. The candidate returned 1 and reported that no valid container remained, without invoking disassembly. The existing mixed batch with a valid container lacking RTS0 and an invalid file still passed. All 34 script tests passed.

Command on the candidate: python -B -m unittest discover -s scripts -p "test_*.py". Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 11:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151#issuecomment-7161411009) · edited 2026-11-26 10:39 UTC I compared this head (`aa825c088e65db380f67a112e0474e56ea841b6a`) with #1088 using a native disassembler stand-in and the same two synthetic shader files. Both reported stderr, but a child that exited 23 with a stdout-only diagnostic lost its message here. A [one-line follow-up and regression assertion](https://github.com/RavenCurseBurg/xcl/commit/1272701ae58bbf705c85c9d2fa9564f9c87476ef) retain stdout when stderr is empty. The batch still checks the second file, counts its successful load and exits 1. Stderr still takes precedence; a silent failure retains the numeric fallback. Five native cases passed on the candidate, including an all-success control. The new assertion failed on the original script; with the fix, `python -B -m unittest discover -s scripts -p "test_*.py"` passed 33/33. The eight focused tests also passed when combined locally with the earlier null-offset candidate `931c40a`. Windows 11, Core i7-13700, Python 3.14.3; no retail shaders or GPU work. OpenAI Codex (GPT-6) prepared the fix and ran the checks. <details> <summary>Earlier verification</summary> Tested `aa825c088e65db380f67a112e0474e56ea841b6a` on Windows 11 24H2 (26100.9711), i7-13700, Python 3.14.3. **Tested** - `python -B -m unittest discover -s scripts -p test_check_layout.py` passed all 8 tests (0 failures, 0 skips). - Ran `scripts/re/check_layout.py <fixture-dir> --xcl <fixture-disasm.cmd>` on a synthetic root signature with one 8-byte CBV at offset 0. The stand-in printed the pointer-copy instructions and one scalar load. Offsets `0x0` and `0x4` each counted as one on-boundary load (exit 0). Offset `0x8` counted as one off-boundary load (exit 1). - For the zero-offset spelling `s_load_dword s5, s[2:3], null`, the checker reported **0 on, 0 off** (exit 0). This exact load is in the [tracked LLVM example](https://github.com/xcl-dev/xcl/blob/aa825c088e65db380f67a112e0474e56ea841b6a/tests/data/llvm-amdgpu/gfx10_smem.txt#L829), and [XCL's formatter](https://github.com/xcl-dev/xcl/blob/aa825c088e65db380f67a112e0474e56ea841b6a/crates/xcl/src/gpu/rdna2.rs#L725) emits `null` for this case. - I tested a [follow-up commit based on this head](https://github.com/RavenCurseBurg/xcl/commit/931c40ae2586f1b259b2c381c3aa9a5b67e8cf90). The extended assertion failed on the PR head and all 8 tests passed with the patch. In the same CLI fixture, `null` then counted as one on-boundary load and the other three results stayed the same. **Not tested** Actual XCL disassembly, retail shader inputs or the Rust/GPU workspace suite. **AI use** OpenAI Codex (GPT-6) ran the tests, wrote the CLI fixture and follow-up patch, and prepared this report. </details> Follow-up on [the review](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2151) at `aa825c088e65`. [Tested candidate 23825658d](https://github.com/RavenCurseBurg/xcl/commit/23825658dda90e3bc14826b9cd72ddc9ba649d9a). A directory containing only a four-byte `DXBC` file previously returned 0. The candidate returned 1 and reported that no valid container remained, without invoking disassembly. The existing mixed batch with a valid container lacking `RTS0` and an invalid file still passed. All 34 script tests passed. Command on the candidate: `python -B -m unittest discover -s scripts -p "test_*.py"`. Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 10:06 UTC · original · reviewed

On aa825c0, a directory whose only .dxbc file is malformed now exits 0 after validating nothing. I reproduced this with a four-byte bad.dxbc containing only DXBC and an existing stand-in --xcl executable that was never called. This head printed skipping invalid DXBC (not a DXBC container) and loads on parameter boundaries: 0, off: 0, then exited 0; the PR base and current main exited 1 on the same input. The new catch skips the file without incrementing errors, so an all-invalid batch appears green. The existing mixed-file fixture expects success despite a corrupt file, which leaves the intended contract for an all-invalid directory unclear.

Could the script distinguish malformed inputs from valid files that simply lack RTS0, and fail when no checkable file remains (or count malformed .dxbc files as validation errors if that is the intended policy)? A malformed-only fixture should pin down the exit status while the scanner still continues through a mixed batch. This was an exact-head CPU-only differential; no GPU shader disassembly ran.

**@⁠luckyteagirl** on GitHub · 2026-11-26 10:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2151#pullrequestreview-6072089852) · **reviewed** On `aa825c0`, a directory whose only `.dxbc` file is malformed now exits 0 after validating nothing. I reproduced this with a four-byte `bad.dxbc` containing only `DXBC` and an existing stand-in `--xcl` executable that was never called. This head printed `skipping invalid DXBC (not a DXBC container)` and `loads on parameter boundaries: 0, off: 0`, then exited 0; the PR base and current main exited 1 on the same input. The new catch skips the file without incrementing `errors`, so an all-invalid batch appears green. The existing mixed-file fixture expects success despite a corrupt file, which leaves the intended contract for an all-invalid directory unclear. Could the script distinguish malformed inputs from valid files that simply lack `RTS0`, and fail when no checkable file remains (or count malformed `.dxbc` files as validation errors if that is the intended policy)? A malformed-only fixture should pin down the exit status while the scanner still continues through a mixed batch. This was an exact-head CPU-only differential; no GPU shader disassembly ran.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2151/head:github-bot/gh-2151'
git switch 'github-bot/gh-2151'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2151'
git switch 'github-bot/gh-2151'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2151'
git switch 'github-bot/gh-2151'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2151'
git switch 'main'
git merge --squash 'github-bot/gh-2151'
git switch 'main'
git merge --ff-only 'github-bot/gh-2151'
git switch 'main'
git merge 'github-bot/gh-2151'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.