Skip to content

Commit 397d269

Browse files
Cancel ModifyVertexBuffer if vertex buffer has unexpected data layout. This prevents UB from overwriting memory
1 parent 4ba079c commit 397d269

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

PluginSource/source/RenderingPlugin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ static void ModifyVertexBuffer()
262262
return;
263263
int vertexStride = int(bufferSize / vertexCount);
264264

265+
// Unity should return us a buffer that is the size of `vertexCount * sizeof(MeshVertex)`
266+
// If that's not the case then we should quit to avoid unexpected results.
267+
// This can happen if https://docs.unity3d.com/ScriptReference/Mesh.GetNativeVertexBufferPtr.html returns
268+
// a pointer to a buffer with an unexpected layout.
269+
if (static_cast<unsigned int>(vertexStride) != sizeof(MeshVertex))
270+
return;
271+
265272
const float t = g_Time * 3.0f;
266273

267274
char* bufferPtr = (char*)bufferDataPtr;

0 commit comments

Comments
 (0)