startup: refuse an image instruction with fewer than three operands #2365

Merged
ChazY11 merged 1 commit from upstream-pr/2373 into main 2026-11-25 14:17:43 +00:00
ChazY11 commented 2026-11-25 14:04:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T14:04:31Z.


What

image() reads vdata, an address and a descriptor, but indexed them without checking how many operands it was given, so a shorter list reached ops[1] or ops[2] and came back as translator crash in <op>: IndexError — the batch translator's marker for a translator defect, not for an instruction it does not lower — and the single-shader path does not catch it at all. Seven handlers share that body: image_sample, image_sample_l, image_sample_lz, image_sample_b, image_get_lod, image_load, image_load_mip.

One guard, before the first index:

if len(ops) < 3:
    raise Unsupported('image instruction with %d operands, expected at least 3' % len(ops))

Measured through the real Stage entry point

image_sample v[8:11], v0   before: translator crash in image_sample: IndexError
                           after:  image instruction with 2 operands, expected at least 3
image_load v[8:11]         before: translator crash in image_load: IndexError
                           after:  image instruction with 1 operands, expected at least 3

The three-operand forms are unchanged: image_load v[8:11], v0, s[16:19] still reports descriptor operand s[16:19] holds None, so the guard replaces the crash and nothing else.

Fail-first

Removing exactly the guard:

AssertionError: ('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')])

restoring it returns startup gfx2hlsl image arity: 7 forms refused at 1 and 2 operands, exit 0.

The check is a new file, deliberately

tests/startup_gfx2hlsl_image_arity_check.py is separate from tests/startup_gfx2hlsl_handler_arity_check.py, which an in-flight PR is editing — two PRs adding a helper at the same anchor would conflict in that hunk for no benefit. The new file asserts the refusal at one and two operands for all seven forms, and that the refusal is not translator crash …, so a handler that starts raising something else fails here too. It is registered in CMakeLists.txt, listed in the Linux CI check list (.github/workflows/windows.yml) and in AGENTS.md.

Verification

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_image_arity_check.py
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py
out/pe-env/Scripts/python.exe -B tests/run_checks_parallel_check.py

exit 0, and all 58 tests/startup_gfx2hlsl_*_check.py exit 0 on this branch. The failing set of all tests/startup_*_check.py run with no arguments is identical on this branch and on main (51 each, none added or removed), so the only checks that move are the ones this PR touches — most of those need a renderer and fail the same way on both.

What this does not touch

The handlers that still index operands without a count check (v_cndmask_b32, v_mov_b32, v_cvt_i32_f32, s_bitcmp*, …) are unchanged: they do not share a body, so each needs its own line and its own accepted-form fixture. Same for the buffer bodies, which #2360 covers.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6606289970 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2373). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T14:04:31Z. --- ## What `image()` reads vdata, an address and a descriptor, but indexed them without checking how many operands it was given, so a shorter list reached `ops[1]` or `ops[2]` and came back as `translator crash in <op>: IndexError` — the batch translator's marker for a translator defect, not for an instruction it does not lower — and the single-shader path does not catch it at all. Seven handlers share that body: `image_sample`, `image_sample_l`, `image_sample_lz`, `image_sample_b`, `image_get_lod`, `image_load`, `image_load_mip`. One guard, before the first index: ```python if len(ops) < 3: raise Unsupported('image instruction with %d operands, expected at least 3' % len(ops)) ``` ## Measured through the real `Stage` entry point ```text image_sample v[8:11], v0 before: translator crash in image_sample: IndexError after: image instruction with 2 operands, expected at least 3 image_load v[8:11] before: translator crash in image_load: IndexError after: image instruction with 1 operands, expected at least 3 ``` The three-operand forms are unchanged: `image_load v[8:11], v0, s[16:19]` still reports `descriptor operand s[16:19] holds None`, so the guard replaces the crash and nothing else. ## Fail-first Removing exactly the guard: ```text AssertionError: ('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')]) ``` restoring it returns `startup gfx2hlsl image arity: 7 forms refused at 1 and 2 operands`, exit 0. ## The check is a new file, deliberately `tests/startup_gfx2hlsl_image_arity_check.py` is separate from `tests/startup_gfx2hlsl_handler_arity_check.py`, which an in-flight PR is editing — two PRs adding a helper at the same anchor would conflict in that hunk for no benefit. The new file asserts the refusal at one and two operands for all seven forms, and that the refusal is not `translator crash …`, so a handler that starts raising something else fails here too. It is registered in `CMakeLists.txt`, listed in the Linux CI check list (`.github/workflows/windows.yml`) and in `AGENTS.md`. ## Verification ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_image_arity_check.py out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py out/pe-env/Scripts/python.exe -B tests/run_checks_parallel_check.py ``` exit 0, and all 58 `tests/startup_gfx2hlsl_*_check.py` exit 0 on this branch. The failing set of all `tests/startup_*_check.py` run with no arguments is identical on this branch and on `main` (51 each, none added or removed), so the only checks that move are the ones this PR touches — most of those need a renderer and fail the same way on both. ## What this does not touch The handlers that still index operands without a count check (`v_cndmask_b32`, `v_mov_b32`, `v_cvt_i32_f32`, `s_bitcmp*`, …) are unchanged: they do not share a body, so each needs its own line and its own accepted-form fixture. Same for the buffer bodies, which #2360 covers. AI-assisted.
upstream-sync closed this pull request 2026-11-25 15:01:49 +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!2365
No description provided.