[PATCH 1/6] wined3d: Validate the initial texture data before initialising the texture.
Henri Verbeet
hverbeet at codeweavers.com
Tue Oct 23 03:48:37 CDT 2018
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
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)
{
--
2.11.0
More information about the wine-devel
mailing list