Heap-buffer-overflow in flattenArgument for an empty stream-output element type
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp の SROA_Parameter_HLSL::flattenArgument から始め、特に FlatAnnotationList[startArgIndex] へのアクセスと、空の struct パラメーターをスキップする分岐を確認してください。提供された GSOut が空のジオメトリシェーダーを dxc -T gs_6_0 -E main poc.hlsl -Fo poc.dxil で実行して再現し、その後、空でない対照シェーダーと比較してください。空要素のケースが範囲外読み取りを行わずにコンパイルされるか、診断を出力すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- C++
- スター
- 3.7k
- フォーク
- 926
- 平均マージ
- 3日 22時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/DirectXShaderCompiler のほかの issue
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
microsoft/DirectXShaderCompiler#9155 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9135 ·
メンテナーはふだん 2 日以内に返信
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSL対応中かも @rj123-nv が 18 日前に担当しました。 オープンbug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9087 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9086 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9015 ·
メンテナーはふだん 2 日以内に返信
microsoft/DirectXShaderCompiler の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
arch-based bug niri
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
noctalia-dev/noctalia#5552 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 5 日以内に返信