shader: reject DXIL VBR operands above 64 bits #460

Merged
agilesh08 merged 1 commit from upstream-pr/466 into main 2026-11-22 05:37:13 +00:00
agilesh08 commented 2026-11-22 05:27:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T05:27:52Z.


## Change

In tools/dxil_retarget.py, BitReader.read_vbr() checked whether cumulative shift > 64 only after shifting and or-ing the incoming payload chunks into value. If a malformed or adversarial bitstream supplied a multi-chunk VBR operand whose highest payload bits crossed the 64-bit boundary during shift <= 64, Python's arbitrary-precision integers allowed value to silently exceed uint64_t.

This change:

  1. Validates payload.bit_length() > 64 - shift before shifting each piece, raising ValueError("VBR integer exceeds 64 bits") immediately when an operand exceeds 64 bits.
  2. Adds synthetic in-memory round-trip checks in tests/dxil_retarget_check.py for boundary values (0, 1, (1 << 64) - 1) and negative controls asserting rejection for 1 << 64 and (1 << 65) - 1.

Verification

Run on Windows x64 with Python 3.14 (D:\Xbox2Windows\.venv\Scripts\python.exe):

python -B tests/dxil_retarget_check.py

Output:

pure-python dxil_retarget controls: ok

Full platform-independent suite (20 checks including docs_links_check.py and bidi_controls_check.py):

python -B tests/script_state_check.py
python -B tests/resource_root_check.py
python -B tests/bcpack_check.py
python -B tests/bc7_blocks_check.py
python -B tests/bc7_tiles_check.py
python -B tests/form_coverage_check.py
python -B tests/resource_ranges_check.py
python -B tests/awc_metadata_check.py
python -B tests/sgd5_effects_check.py
python -B tests/dxcontainer_part_offsets_check.py
python -B tests/layout_chunks_check.py
python -B tests/dependency_paths_check.py
python -B tests/intake/paths_check.py
python -B tests/shader_probe_check.py
python -B tests/dxil_retarget_check.py
python -B tests/rdna2_tools_check.py
python -B tests/pso_readiness_check.py
python -B tests/xmem_attribute_scan_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

Result: All 20 checks passed with exit code 0.

Evidence and follow-up

All fixtures are 100% synthetic in-memory bitstream payloads generated dynamically using BitWriter.

This change is AI-assisted.

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.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6538870221 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/466). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T05:27:52Z. --- ## Change In `tools/dxil_retarget.py`, `BitReader.read_vbr()` checked whether cumulative `shift > 64` only after shifting and or-ing the incoming payload chunks into `value`. If a malformed or adversarial bitstream supplied a multi-chunk VBR operand whose highest payload bits crossed the 64-bit boundary during `shift <= 64`, Python's arbitrary-precision integers allowed `value` to silently exceed `uint64_t`. This change: 1. Validates `payload.bit_length() > 64 - shift` before shifting each piece, raising `ValueError("VBR integer exceeds 64 bits")` immediately when an operand exceeds 64 bits. 2. Adds synthetic in-memory round-trip checks in `tests/dxil_retarget_check.py` for boundary values (`0`, `1`, `(1 << 64) - 1`) and negative controls asserting rejection for `1 << 64` and `(1 << 65) - 1`. ## Verification Run on Windows x64 with Python 3.14 (`D:\Xbox2Windows\.venv\Scripts\python.exe`): ```powershell python -B tests/dxil_retarget_check.py ``` Output: ```text pure-python dxil_retarget controls: ok ``` Full platform-independent suite (20 checks including `docs_links_check.py` and `bidi_controls_check.py`): ```powershell python -B tests/script_state_check.py python -B tests/resource_root_check.py python -B tests/bcpack_check.py python -B tests/bc7_blocks_check.py python -B tests/bc7_tiles_check.py python -B tests/form_coverage_check.py python -B tests/resource_ranges_check.py python -B tests/awc_metadata_check.py python -B tests/sgd5_effects_check.py python -B tests/dxcontainer_part_offsets_check.py python -B tests/layout_chunks_check.py python -B tests/dependency_paths_check.py python -B tests/intake/paths_check.py python -B tests/shader_probe_check.py python -B tests/dxil_retarget_check.py python -B tests/rdna2_tools_check.py python -B tests/pso_readiness_check.py python -B tests/xmem_attribute_scan_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` Result: All 20 checks passed with exit code 0. ## Evidence and follow-up All fixtures are 100% synthetic in-memory bitstream payloads generated dynamically using `BitWriter`. This change is AI-assisted. ## 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. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:43:10 +00:00
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!460
No description provided.