From 758cdfa02dce6d8facf9e6a0a7f09bcbb9cacb1b Mon Sep 17 00:00:00 2001 From: Matteo Bruni Date: Tue, 12 Mar 2019 21:25:09 +0100 Subject: [PATCH] d3d9: Validate vertex stride in Draw[Indexed]PrimitiveUP(). Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46713 Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d9/device.c | 12 +++++++++++- dlls/d3d9/tests/device.c | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 5d59fd570ce..5844d2cdaca 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2915,9 +2915,14 @@ static HRESULT WINAPI d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n", iface, primitive_type, primitive_count, data, stride); + if (!stride) + { + WARN("stride is 0, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } if (!primitive_count) { - WARN("primitive_count is 0, returning D3D_OK\n"); + WARN("primitive_count is 0, returning D3D_OK.\n"); return D3D_OK; } @@ -3026,6 +3031,11 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *ifa iface, primitive_type, min_vertex_idx, vertex_count, primitive_count, index_data, index_format, vertex_data, vertex_stride); + if (!vertex_stride) + { + WARN("vertex_stride is 0, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } if (!primitive_count) { WARN("primitive_count is 0, returning D3D_OK.\n"); diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 76d19b91a23..d119b639d32 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -2981,6 +2981,11 @@ static void test_draw_primitive(void) hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2); ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, 0); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, quad, 0); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, sizeof(*quad)); ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr); @@ -3009,6 +3014,13 @@ static void test_draw_primitive(void) ok(current_ib == index_buffer, "Unexpected index buffer %p.\n", current_ib); IDirect3DIndexBuffer9_Release(current_ib); + hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 2, + indices, D3DFMT_INDEX16, quad, 0); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 0, + indices, D3DFMT_INDEX16, quad, 0); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 2, indices, D3DFMT_INDEX16, quad, sizeof(*quad)); ok(SUCCEEDED(hr), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr);