Commit 62454ae7 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Validate "data" in wined3d_texture_upload_data().

parent e5e05b97
...@@ -164,6 +164,7 @@ static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL ...@@ -164,6 +164,7 @@ static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL
static void test_create_texture2d(void) static void test_create_texture2d(void)
{ {
ULONG refcount, expected_refcount; ULONG refcount, expected_refcount;
D3D10_SUBRESOURCE_DATA data = {0};
ID3D10Device *device, *tmp; ID3D10Device *device, *tmp;
D3D10_TEXTURE2D_DESC desc; D3D10_TEXTURE2D_DESC desc;
ID3D10Texture2D *texture; ID3D10Texture2D *texture;
...@@ -188,6 +189,9 @@ static void test_create_texture2d(void) ...@@ -188,6 +189,9 @@ static void test_create_texture2d(void)
desc.CPUAccessFlags = 0; desc.CPUAccessFlags = 0;
desc.MiscFlags = 0; desc.MiscFlags = 0;
hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
expected_refcount = get_refcount((IUnknown *)device) + 1; expected_refcount = get_refcount((IUnknown *)device) + 1;
hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture); hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
...@@ -255,6 +259,7 @@ static void test_create_texture2d(void) ...@@ -255,6 +259,7 @@ static void test_create_texture2d(void)
static void test_create_texture3d(void) static void test_create_texture3d(void)
{ {
ULONG refcount, expected_refcount; ULONG refcount, expected_refcount;
D3D10_SUBRESOURCE_DATA data = {0};
ID3D10Device *device, *tmp; ID3D10Device *device, *tmp;
D3D10_TEXTURE3D_DESC desc; D3D10_TEXTURE3D_DESC desc;
ID3D10Texture3D *texture; ID3D10Texture3D *texture;
...@@ -277,6 +282,9 @@ static void test_create_texture3d(void) ...@@ -277,6 +282,9 @@ static void test_create_texture3d(void)
desc.CPUAccessFlags = 0; desc.CPUAccessFlags = 0;
desc.MiscFlags = 0; desc.MiscFlags = 0;
hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
expected_refcount = get_refcount((IUnknown *)device) + 1; expected_refcount = get_refcount((IUnknown *)device) + 1;
hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture); hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr); ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
......
...@@ -727,12 +727,22 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, ...@@ -727,12 +727,22 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture,
return WINED3D_OK; return WINED3D_OK;
} }
static void wined3d_texture_upload_data(struct wined3d_texture *texture, const struct wined3d_sub_resource_data *data) static HRESULT wined3d_texture_upload_data(struct wined3d_texture *texture,
const struct wined3d_sub_resource_data *data)
{ {
unsigned int sub_count = texture->level_count * texture->layer_count; unsigned int sub_count = texture->level_count * texture->layer_count;
struct wined3d_context *context; struct wined3d_context *context;
unsigned int i; 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);
return E_INVALIDARG;
}
}
context = context_acquire(texture->resource.device, NULL); context = context_acquire(texture->resource.device, NULL);
wined3d_texture_prepare_texture(texture, context, FALSE); wined3d_texture_prepare_texture(texture, context, FALSE);
...@@ -748,6 +758,8 @@ static void wined3d_texture_upload_data(struct wined3d_texture *texture, const s ...@@ -748,6 +758,8 @@ static void wined3d_texture_upload_data(struct wined3d_texture *texture, const s
} }
context_release(context); context_release(context);
return WINED3D_OK;
} }
static void texture2d_sub_resource_load(struct wined3d_resource *sub_resource, static void texture2d_sub_resource_load(struct wined3d_resource *sub_resource,
...@@ -1444,8 +1456,12 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct ...@@ -1444,8 +1456,12 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
/* FIXME: We'd like to avoid ever allocating system memory for the texture /* FIXME: We'd like to avoid ever allocating system memory for the texture
* in this case. */ * in this case. */
if (data) if (data && FAILED(hr = wined3d_texture_upload_data(object, data)))
wined3d_texture_upload_data(object, data); {
wined3d_texture_cleanup(object);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
TRACE("Created texture %p.\n", object); TRACE("Created texture %p.\n", object);
*texture = object; *texture = object;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment