d3d11: Validate array size for cube textures.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-02-10 12:26:52 +01:00 committed by Alexandre Julliard
parent 5ac8be243d
commit 7ee0118471
3 changed files with 29 additions and 17 deletions

View File

@ -1218,11 +1218,11 @@ static void test_create_texture2d(void)
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,

View File

@ -1647,11 +1647,11 @@ static void test_create_texture2d(void)
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
FALSE, TRUE},
FALSE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
TRUE, FALSE},
{DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,

View File

@ -456,6 +456,25 @@ static BOOL is_gdi_compatible_texture(const D3D11_TEXTURE2D_DESC *desc)
return TRUE;
}
static BOOL validate_texture2d_desc(const D3D11_TEXTURE2D_DESC *desc)
{
if (desc->MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
&& desc->ArraySize < 6)
{
WARN("Invalid array size %u for cube texture.\n", desc->ArraySize);
return FALSE;
}
if (desc->MiscFlags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE
&& !is_gdi_compatible_texture(desc))
{
WARN("Incompatible description used to create GDI compatible texture.\n");
return FALSE;
}
return TRUE;
}
static HRESULT d3d_texture2d_init(struct d3d_texture2d *texture, struct d3d_device *device,
const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
{
@ -464,6 +483,9 @@ static HRESULT d3d_texture2d_init(struct d3d_texture2d *texture, struct d3d_devi
DWORD flags = 0;
HRESULT hr;
if (!validate_texture2d_desc(desc))
return E_INVALIDARG;
texture->ID3D11Texture2D_iface.lpVtbl = &d3d11_texture2d_vtbl;
texture->ID3D10Texture2D_iface.lpVtbl = &d3d10_texture2d_vtbl;
texture->refcount = 1;
@ -488,17 +510,7 @@ static HRESULT d3d_texture2d_init(struct d3d_texture2d *texture, struct d3d_devi
levels = desc->MipLevels ? desc->MipLevels : wined3d_log2i(max(desc->Width, desc->Height)) + 1;
if (desc->MiscFlags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
{
if (is_gdi_compatible_texture(desc))
flags |= WINED3D_TEXTURE_CREATE_GET_DC;
else
{
WARN("Incompatible description used to create GDI compatible texture.\n");
wined3d_private_store_cleanup(&texture->private_store);
wined3d_mutex_unlock();
return E_INVALIDARG;
}
}
flags |= WINED3D_TEXTURE_CREATE_GET_DC;
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc,
desc->ArraySize, levels, flags, (struct wined3d_sub_resource_data *)data,