libs/vkd3d-shader: Validate DXBC data size.

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 2018-04-11 13:21:41 +02:00 committed by Alexandre Julliard
parent 69e6382880
commit 6a1b3a3fb5
2 changed files with 10 additions and 3 deletions

View File

@ -1808,7 +1808,7 @@ static const char *shader_get_string(const char *data, size_t data_size, DWORD o
return data + offset;
}
static int parse_dxbc(const char *data, SIZE_T data_size,
static int parse_dxbc(const char *data, size_t data_size,
int (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
{
const char *ptr = data;
@ -1819,6 +1819,12 @@ static int parse_dxbc(const char *data, SIZE_T data_size,
DWORD version;
DWORD tag;
if (data_size < VKD3D_DXBC_HEADER_SIZE)
{
WARN("Invalid data size %zu.\n", data_size);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
read_dword(&ptr, &tag);
TRACE("tag: %#x.\n", tag);
@ -1856,7 +1862,7 @@ static int parse_dxbc(const char *data, SIZE_T data_size,
if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size))
{
WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size);
WARN("Invalid chunk offset %#x (data size %zu).\n", chunk_offset, data_size);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
@ -1867,7 +1873,7 @@ static int parse_dxbc(const char *data, SIZE_T data_size,
if (!require_space(chunk_ptr - data, 1, chunk_size, data_size))
{
WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n",
WARN("Invalid chunk size %#x (data size %zu, chunk offset %#x).\n",
chunk_size, data_size, chunk_offset);
return VKD3D_ERROR_INVALID_ARGUMENT;
}

View File

@ -858,5 +858,6 @@ static inline unsigned int vkd3d_swizzle_get_component(DWORD swizzle,
}
#define VKD3D_DXBC_MAX_SOURCE_COUNT 6
#define VKD3D_DXBC_HEADER_SIZE (8 * sizeof(uint32_t))
#endif /* __VKD3D_SHADER_PRIVATE_H */