From 15110e075fc76a309364140ad4eea0970ed17b9d Mon Sep 17 00:00:00 2001 From: papalqi <13328496+papalqi@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:28:29 +0800 Subject: [PATCH] demos: fix out of bounds read of instance data in D3D12_Draw_Zoo dae198b39 grew the instance buffer from 4096 to 8192 bytes, since one vertex buffer view binds it at an offset of 8 * sizeof(Vec4f) with a size of 4096, but the Vec4f instData[256] array it is filled from was left at 4096 bytes. The explicit .Size(8192) overrides the size taken from the array, so SetBufferData copies 8192 bytes from a 4096 byte stack array. When the read runs off the end of the stack the demo crashes with an access violation before it renders anything. Size the array to the buffer and let Data() take the size from it. --- util/test/demos/d3d12/d3d12_draw_zoo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/test/demos/d3d12/d3d12_draw_zoo.cpp b/util/test/demos/d3d12/d3d12_draw_zoo.cpp index 7a75a3944..472aea527 100644 --- a/util/test/demos/d3d12/d3d12_draw_zoo.cpp +++ b/util/test/demos/d3d12/d3d12_draw_zoo.cpp @@ -271,7 +271,7 @@ float4 main(v2f IN) : SV_Target0 ID3D12ResourcePtr vb = MakeBuffer().Data(vbData).Size(UINT(vbData.size() * sizeof(DefaultA2V))); - Vec4f instData[256] = {}; + Vec4f instData[512] = {}; for(int i = 0; i < ARRAY_COUNT(instData); i++) instData[i] = Vec4f(-100.0f, -100.0f, -100.0f, -100.0f); @@ -286,7 +286,7 @@ float4 main(v2f IN) : SV_Target0 instData[14] = Vec4f(0.5f, 0.9f, 0.1f, 0.5f); } - ID3D12ResourcePtr instvb = MakeBuffer().Data(instData).Size(8192); + ID3D12ResourcePtr instvb = MakeBuffer().Data(instData); std::vector idxData; idxData.resize(2048);