From 718f7fd4fd29b82194f33e721c7420e39d5209b0 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 23 Oct 2018 12:18:37 +0330 Subject: [PATCH] wined3d: Validate the initial texture data before initialising the texture. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/texture.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 15492cd86fe..ecbe94b2459 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -3568,8 +3568,10 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct UINT layer_count, UINT level_count, DWORD flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture) { + unsigned int sub_count = level_count * layer_count; const struct wined3d_texture_ops *texture_ops; struct wined3d_texture *object; + unsigned int i; HRESULT hr; TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, data %p, " @@ -3630,8 +3632,19 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct return WINED3DERR_INVALIDCALL; } - if (!(object = heap_alloc_zero(FIELD_OFFSET(struct wined3d_texture, - sub_resources[level_count * layer_count])))) + if (data) + { + for (i = 0; i < sub_count; ++i) + { + if (data[i].data) + continue; + + WARN("Invalid sub-resource data specified for sub-resource %u.\n", i); + return E_INVALIDARG; + } + } + + if (!(object = heap_alloc_zero(FIELD_OFFSET(struct wined3d_texture, sub_resources[sub_count])))) return E_OUTOFMEMORY; if (FAILED(hr = wined3d_texture_init(object, desc, layer_count, @@ -3646,21 +3659,8 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct * in this case. */ if (data) { - unsigned int sub_count = level_count * layer_count; unsigned int level, width, height, depth; struct wined3d_box box; - unsigned int i; - - for (i = 0; i < sub_count; ++i) - { - if (!data[i].data) - { - WARN("Invalid sub-resource data specified for sub-resource %u.\n", i); - wined3d_texture_cleanup_sync(object); - heap_free(object); - return E_INVALIDARG; - } - } for (i = 0; i < sub_count; ++i) {