startup: refuse a malformed root signature blob per request in gfx2hlsl #1519
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1526"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:38:05Z.
Change
parse_rootintools/startup/gfx2hlsl.pyunpacked the root-signature blob without length checks. A truncated DXBC header, a part-offset table past the end, or an RTS0 part without a body raisedstruct.error. The per-request handler intranslate_requestonly catches(Unsupported, OSError, UnicodeError), so one such request aborted the whole--pendingrun with a traceback and exit code 1, and later requests in the directory were never translated. An empty root blob was already refused cleanly.Every read in
parse_rootnow goes through a small bounds-checked helper that raises the tool's ownUnsupported('root signature blob truncated'). The request gets a.failfile, the run continues and exits 0. No broadstruct.errorcatch, no change to ALU lowering or the--capturebranch.New
tests/startup_gfx2hlsl_root_check.py(pure Python,--pendingsubprocess), registered in CMakeLists.txt (startup_gfx2hlsl_root), thepython-linuxjob and the AGENTS.md list.Verification
Run from the repo root with Python 3.14.5:
python -B tests/startup_gfx2hlsl_root_check.py-> rc 0, "malformed root blobs refused per request, valid request still translated". Covers: empty blob, truncated header, part count past end, RTS0 without body, parameter table past end, container without RTS0, and a valid request that sorts after a bad one and is still translated (.txtwritten, no.fail).tools/startup/gfx2hlsl.pyreverted toorigin/main, the same check fails withstruct.error: unpack_from requires a buffer of at least 24 bytes ... (actual buffer size is 0)fromparse_root.startup_translator,startup_flat_param,startup_sampler_heap,startup_host_cpu,startup_image_sample_l,startup_image_3d,startup_image_load_mip,startup_image_2d_array,startup_inline_sampler_check.py(no arguments) all rc 0.Evidence and follow-up
Base
origin/main60c72330. Aftercmake --preset dev,ctest --test-dir out/build/dev --no-tests=error -R '^startup_gfx2hlsl_root$'passed (1/1). Not run: thebinary/drawmodes of the inline-sampler check, GPU tests, and the new check on Linux (this PR'spython-linuxjob is the first Linux run). Inputs are synthetic. Well-formed roots take the same path as before. Open PR #1471 edits other parts ofgfx2hlsl.py(image sampling), notparse_root.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:34:49Z.
Review: COMMENTED
Technical review (Linux only; the Windows pipeline was not run).
Checked out the PR head (merge of current main) in a clean tree.
What I ran:
tests/startup_gfx2hlsl_root_check.py: passes.tools/startup/gfx2hlsl.pyfrom main fails withstruct.error(empty RTS0 body), so the test does detect the old behaviour.startup_translator_check,startup_flat_param_check,startup_gfx2hlsl_bit_alu_check,startup_inline_sampler_check: all pass.parse_root: a valid blob with one descriptor-table parameter parses to the expected register, space and count; a table offset past the end and a parameter count of 0xffffffff both raiseUnsupported('root signature blob truncated').Local mutation check (each mutation reverted afterwards; the tree is clean). I replaced one guarded read at a time with a raw
struct.unpack_from, and made the bound check a no-op or length-only:pass: caughtoffset > len(data): caughtif ptype == 1:(p['reg'], p['space'], p['count'] = read(...)): not caught. The test never gives a parameter of type 1 whose table offset lies outside the blob, so this branch is unguarded by any test even though the code is correct.Suggestion (non-blocking): add one case to
BADwith a type-1 parameter whose offset points past the end, for examplestruct.pack("<6I", 1, 1, 24, 0, 36, 0) + struct.pack("<3I", 1, 0, 400)inside an RTS0 part, expecting the "truncated" reason. A positive case with a valid type-1 table would also pin the parsed fields.Observation (not caused by this PR):
d = blob[o + 8:]is not bounded by the RTS0 part length, so a short part can read bytes of a following part without error. It cannot crash now, only mis-parse.The CMake test entry, the workflow list and the AGENTS.md line are consistent with each other.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T15:51:31Z.
Thanks for running the mutations and for the precise example.
I added a "descriptor table past end" case to BAD: a type-1 parameter whose table offset is 400, past the end of the blob, expecting the "truncated" reason. I used the suggested bytes unchanged.
I also added a positive case: a valid blob with one type-1 table, asserting that parse_root returns register 5, space 2 and count 3.
With your mutation (a raw struct.unpack_from at that read), the check now fails with a struct.error, while without the new case it still passed.
I left the point about d = blob[o + 8:] not being bounded by the RTS0 part length out of this pull request, to keep it to one behavior.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:50:13Z.
Review: COMMENTED
Re-review of head
38db697f8a(comment only, not an approval). My earlier review was at99a4863cbb.Verdict: 0 P1 / 0 P2.
Earlier points
99a4863is test-only (+7 lines).d = blob[o + 8:]is not bounded by the RTS0 part length. It can only mis-parse, not crash.Run
python3 -B tests/startup_gfx2hlsl_root_check.py: pass. Also pass: startup_translator, startup_flat_param, startup_gfx2hlsl_bit_alu, startup_inline_sampler, startup_sampler_heap, startup_image_sample_l, startup_image_3d, startup_image_load_mip, startup_image_2d_array, docs_links_check (16 files, 346 links), bidi_controls_check. startup_host_cpu_check fails only on a missingiced_x86module.git checkout --, green again): replacingreadwith a rawstruct.unpack_fromat each of five reads is caught every time (e.g.struct.error: unpack_from requires a buffer of at least 412 bytes ... at offset 400); swapping reg and space in the table read and changingo + 8too + 4are caught.> len(data) + 1(no test reads exactly at the end of the blob), and changing the parameter stride from12 * ito8 * i(the positive case has one parameter, so index 0 hides it).Non-blocking
parse_root.Not run: CMake/ctest, the Windows job, GPU tests. The PR has no shader, ISA or C++ change, so llvm-mc and mingw had nothing to check.
Linux limits: no Windows, MSVC, DXC or D3D12 device here; LLVM 19 only. Anything that needs them was not run.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T02:02:46Z.
I resolved the Linux test-list overlap and kept both the malformed-root and SOPK checks. On Windows the patched batch rejects only the malformed requests, still translates the independent valid request, and passes the startup translator regression.