microsoft / microsoft/DirectXShaderCompiler
Vector element index out-of-bounds not leading to compile error
Open
Nobody has claimed this yet.
bug
diagnostic
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
It is currently possible to index vector elements out-of-bounds without the compiler issuing and error:
// Load index buffer
uint indexOffset = PrimitiveIndex() * 3 /* indices per primitive */ * 4 /* 4 bytes per index*/;
const uint3 indices = g_indices.Load3(indexOffset);
// Retrieve corresponding vertex normals for the triangle vertices.
float3 vertexNormals[3] = { g_vertices[indices[0]].normal, g_vertices[indices[1]].normal, g_vertices[indices[3]].normal };
// Compute the triangle's interpolated normal
float3 triangleNormal = HitAttribute(vertexNormals, attr);
Notice the indices[3] above is out-of-bounds.
Above can be compiled with this command line (shader attached to bug)
dxc.exe /T lib_6_6 /Zpr /all_resources_bound /Zi /Od /Vn"g_DefaultRT_DXIL_Lib" /Fh"DefaultRT.dxil-lib.h" /nologo DefaultRT.hlsl
Shader repro attached: DefaultRT.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the attached DefaultRT.hlsl repro with the provided dxc.exe command and confirm that indices[3] produces no diagnostic. Trace how vector element indexing is handled, then add coverage for this out-of-bounds case and verify that compilation reports an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100