Heap-buffer-overflow in flattenArgument for an empty stream-output element type
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with SROA_Parameter_HLSL::flattenArgument in lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp, especially the FlatAnnotationList[startArgIndex] access and the branch that skips empty struct parameters. Reproduce with the provided empty GSOut geometry shader using dxc -T gs_6_0 -E main poc.hlsl -Fo poc.dxil, then compare with the non-empty control shader. Done means the empty-element case compiles or produces a diagnostic without an out-of-bounds read.
Written by the indexing model from the issue text.
Description
Description
A geometry shader whose stream-output element type is an empty struct makes DXC read past the end of a heap block in the SROA pass. The shader is valid HLSL. In the release build nothing is printed and the compiler exits with code 0; under AddressSanitizer it is a heap-buffer-overflow READ of size 8. In a build with hardened libc++ (the way Chromium builds DXC) the bounds check of std::vector::operator[] ends the process.
The read is in SROA_Parameter_HLSL::flattenArgument, lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp, lines 5798–5801 at b43c5651:
if (inputQual == DxilParamInputQual::OutStream0 || ... OutStream3)
startArgIndex++;
DxilParameterAnnotation &flatParamAnnotation =
FlatAnnotationList[startArgIndex];
For a stream-output parameter the index is advanced past the stream object and then used without checking that flattening the element type produced an entry. With an empty struct it produces none (the "skip empty struct parameters" branch a little above, lines 5508–5513, continues without appending), so the list holds only the stream object and the access reads past its end.
Steps to Reproduce
A geometry shader with an empty stream-output element type:
poc.hlsl
struct GSOut { };
[maxvertexcount(1)]
void main(inout PointStream<GSOut> stream) { }
dxc -T gs_6_0 -E main poc.hlsl -Fo poc.dxil
Control, control.hlsl: the same shader with a non-empty element type. It compiles on every build listed under Environment.
control.hlsl
struct GSOut { float4 c : SV_Position; };
[maxvertexcount(1)]
void main(inout PointStream<GSOut> stream) { GSOut o = (GSOut)0; o.c = float4(0, 0, 0, 1); stream.Append(o); }
Actual Behavior
Release 1.9.2609.5: no output, exit code 0. The read happens and nothing observes it.
Build with AddressSanitizer, with or without assertions: exit code 1 and heap-buffer-overflow READ of size 8 in SROA_Parameter_HLSL::flattenArgument, on memory that flattenArgument itself allocated.
AddressSanitizer report (abbreviated)
The frames carry symbols but no line information, so they show the library offset instead.
==1821290==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x50f0000006b8 at pc 0x7fbba8f20fe5 bp 0x7fff87ead510 sp 0x7fff87ead500
READ of size 8 at 0x50f0000006b8 thread T0
#0 in SROA_Parameter_HLSL::flattenArgument(...) libdxcompiler.so+0x1d20fe4
#1 in SROA_Parameter_HLSL::createFlattenedFunction(llvm::Function*) libdxcompiler.so+0x1d37679
#2 in SROA_Parameter_HLSL::runOnModule(llvm::Module&) libdxcompiler.so+0x1d463ce
#3 in llvm::legacy::PassManagerImpl::run(llvm::Module&) libdxcompiler.so+0x64ad66d
...
#10 in DxcCompiler::Compile(...) libdxcompiler.so+0x86769d
0x50f0000006b8 is located 40 bytes after 176-byte region [0x50f0000005e0,0x50f000000690)
allocated by thread T0 here:
#0 in operator new(unsigned long)
#1 in std::vector<hlsl::DxilParameterAnnotation>::_M_realloc_insert<hlsl::DxilParameterAnnotation>(...)
#2 in SROA_Parameter_HLSL::flattenArgument(...) libdxcompiler.so+0x1d1d519
#3 in SROA_Parameter_HLSL::createFlattenedFunction(llvm::Function*) libdxcompiler.so+0x1d37679
#4 in SROA_Parameter_HLSL::runOnModule(llvm::Module&) libdxcompiler.so+0x1d463ce
SUMMARY: AddressSanitizer: heap-buffer-overflow (libdxcompiler.so+0x1d20fe4) in SROA_Parameter_HLSL::flattenArgument
The 176-byte region is the std::vector<DxilParameterAnnotation> that flattenArgument fills; with the empty element type it holds only the stream object.
Expected: the shader compiles to DXIL, or it is rejected with a diagnostic. Either way there should be no out-of-bounds read.
The same shader shape was also compiled with the DXC that Dawn builds (1.10.2609.0, 5de1dbca) with Chromium's hardened libc++, on Windows 11: the process ends with vector.h:414: libc++ Hardening assertion __n < size() failed: vector[] index out of bounds.
Environment
- DXC version
- Release 1.9.2609.5:
libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5) - Built from source at
b43c5651d744e606552b3274668a160be21db0f8(main, 2026-11-24):libdxcompiler.so: 1.11(1-b43c5651)(1.10.0.10001), with AddressSanitizer, once with assertions and once without. - The code quoted above is the same on current main (
2600ae89a615); I have not compiled that revision.
- Release 1.9.2609.5:
- Host Operating System
- Ubuntu 24.04.4 LTS, x86_64, kernel 6.8.
- The hardened-libc++ observation is from Windows 11 (10.0.26100).
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 926
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 45
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from microsoft/DirectXShaderCompiler
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
microsoft/DirectXShaderCompiler#9155 · 4 comments ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainers usually reply within 2 days
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLPossibly taken @rj123-nv claimed this 18 days ago. Openbug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9015 ·
Maintainers usually reply within 2 days
All issues in microsoft/DirectXShaderCompiler
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
arch-based bug niri
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
noctalia-dev/noctalia#5552 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
EchoTools/nevr-runtime#2912 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
ungive/discord-music-presence#1090 · 1 comment ·