Skip to content

shader_meta: reject incomplete DXBC input signatures - #4572

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
check3D:fix/shader-meta-isg1-table
Nov 23, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
check3D:fix/shader-meta-isg1-table

Conversation

@check3D

@check3D check3D commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: New BUILD item

What and why

Validate the DXBC ISG1 element table in tools/shader_meta.py before publishing input_signature. Previously, a truncated table could publish a partial signature, and an offset inside the chunk header could cause the header to be read as an element.

The metadata reader now omits the input signature when the table is invalid. It still reports feature flags from a valid SFI0 chunk.

Tested

  • python3 -I tests/test_shader_meta.py — all 20 tests passed on Linux. Both malformed-table cases failed before the fix.
  • CPU-only testing with synthetic inputs. No GPU, driver, or game files were used.
  • Full shader corpus translation and spirv-val were outside the scope of this metadata change.

AI-assisted (Codex).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — this change validates build-time metadata.)

@Atomic258

Copy link
Copy Markdown
Contributor

Tested head 6f447e7891690fecd14ec030bed3523dec190ab5 on Linux, Python 3.10.12, standard library only, synthetic DXBC signature inputs (no game files, no GPU).

  • python -I tests/test_shader_meta.py on the PR head: Ran 20 tests — OK
  • Negative control, same test file against main's tools/shader_meta.py: FAILED (failures=2) — the incomplete-signature rejection is exercised by the new tests.

The DXBC input signature validation rejects incomplete signatures as described. AI-assisted (Devin).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 6f447e78 on Windows 11: python -I tests/test_shader_meta.py -> 20 tests, OK; git diff --check clean.

An ISG1 table whose declared elements run past the chunk is now dropped whole (input_signature absent) instead of publishing the prefix; the entity offset must also be at least 8, so a table cannot point back into its own header. The added cases cover count=2 with the payload of one element and offset=0, and keep the unrelated SFI0 flags. No blocking issue.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 6f447e7 merged with main d0835dd (merge f448d43c1, no conflicts) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.

  • tests/test_shader_meta.py: 20/20 OK on both.
  • Negative control: tools/shader_meta.py from main, same tests: 2 failures (the two malformed-table subtests) on Linux and on Windows.
  • Read the diff: the table is now accepted only when 8 <= offset and offset + 32 * count fits in the chunk, so a partial signature is never published and the SFI0 flags still come through (the test asserts both). A valid table, and count == 0, behave as before. Fixtures are hand-built.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The element-table bounds check is sound, but malformed semantic-name offsets still produce and publish a partial signature.

Comment thread tools/shader_meta.py
end = p.find(b"\x00", noff)
if end > noff:
semantic = p[noff:end].decode("ascii", "replace")
elems.append({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] If NameOffset is out of range, points into the element table, or has no terminating NUL, this code leaves semantic empty or decodes unrelated bytes and still appends the element. That publishes a malformed input_signature instead of rejecting it. The semantic name is part of the signature contract: Microsoft describes SemanticName as the per-parameter string that identifies data use, and signature compatibility requires exact semantics (https://learn.microsoft.com/en-us/windows/win32/api/d3d11shader/ns-d3d11shader-d3d11_signature_parameter_desc). Please validate every name offset/terminator against the string area and omit the whole signature if any entry is invalid.

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verdict: approve-with-nits.

tools/shader_meta.py:612 now accepts the ISG1 table only when 8 <= eo and eo + 32*ecnt <= len(p); otherwise input_signature is not published and the SFI0 flags stay. Legitimate cases are untouched: a valid table publishes as before, ecnt = 0 (PS/CS) and an empty DXBC behave like main. The 23 deleted lines are the re-indentation of the same loop plus the old break that published the truncated table — nothing working is dropped.

Verified: python -I tests/test_shader_meta.py → 20 tests OK; pytest tests/test_shader_meta.py → 20 passed, 13 subtests; tests/test_shader_index.py and tests/test_shader_meta_operands.py → 0. On the old file the same synthetic DXBC publishes a partial or garbage signature ((2,8) → 1 of 2 elements, (1,0) → an element taken from the chunk header); on the new one, nothing. Fuzz: 4000 random ISG1 chunks with ecnt/eo up to 0xFFFFFFFF → 0 exceptions.

Also checked for regression: the full tests/semantic is red on this machine (36 failures + 2 errors), and the failure set is byte-identical on the base commit 03b09a08 (FAIL:/ERROR: lines diff clean, 38/38), so the diff adds nothing red.

Nits:

  1. No count over the corpus (AGENTS.md). A container whose eo is not 8, or whose table runs past the payload, now silently loses input_signature for a VS, which is indistinguishable from "no inputs". A metadata pass over your own work folder with "before/after: N with input_signature, 0 diffs" would close this.
  2. tools/rdna2spirv.py:13269-13301 parses the same chunk with no checks (unpack_from at :13278 and :13293): a truncated ISG1 still raises struct.error there, and eo = 0 still yields garbage vertex_inputs/vertex_input_signature. One shared validated helper, or a finding: as a follow-up, keeps the two readers in step.
  3. runtime/src/shader_library.h:791 and d3d12_vulkan_device.cpp:2326 (layout_feeds) treat an empty signature as "any input layout fits", so a broken container now selects a PSO as a VS with no inputs instead of failing loudly. Not a blocker here, but a line in docs/d3d12_vulkan.md:1603 would record it.
  4. The description references the claim but not the item ID — in Coordinating who works on what (24) (moved to #4683) #4571 this is BUILD-1326.

AI-assisted review.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 2b53baf merged with main 98fa503 on Linux (Python 3.12.16): pass - tests/test_shader_meta.py 21 OK, tests/test_docs_*.py (10 files) OK; negative control: upstream/main tools/shader_meta.py with the new tests: 5 failures. The new docs sentence checks out against the runtime: an empty input_signature makes layout_feeds() in runtime/shims/d3d12_vulkan_device.cpp return true for any layout. No issue found.

@memorypressure

Copy link
Copy Markdown

Merged cleanly with current main: all 21 shader-metadata tests and the docs guards (repo paths, cli flags, table ids) pass under python -I. The synthetic containers correctly demonstrate that malformed tables or name offsets drop the whole signature without losing unrelated SFI0 metadata. The #3634 overlap is only on docs/d3d12_vulkan.md and main already carries that table cleanup via adea815 — unrelated to ISG1. No CI checks were reported. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants