d3dx9: Handle invalid byte code in D3DXFindShaderComment().

This commit is contained in:
Rico Schüller 2013-01-07 21:57:07 +01:00 committed by Alexandre Julliard
parent ae9b07fdc0
commit bc4a4f5f3b
2 changed files with 31 additions and 5 deletions

View File

@ -40,6 +40,11 @@ HRESULT WINAPI D3DAssemble(LPCVOID data, SIZE_T datasize, LPCSTR filename,
UINT flags,
ID3DBlob **shader, ID3DBlob **error_messages);
static inline BOOL is_valid_bytecode(DWORD token)
{
return (token & 0xfffe0000) == 0xfffe0000;
}
const char * WINAPI D3DXGetPixelShaderProfile(struct IDirect3DDevice9 *device)
{
D3DCAPS9 caps;
@ -147,17 +152,17 @@ const char * WINAPI D3DXGetVertexShaderProfile(struct IDirect3DDevice9 *device)
return NULL;
}
HRESULT WINAPI D3DXFindShaderComment(CONST DWORD* byte_code, DWORD fourcc, LPCVOID* data, UINT* size)
HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const void **data, UINT *size)
{
CONST DWORD *ptr = byte_code;
const DWORD *ptr = byte_code;
TRACE("(%p, %x, %p, %p)\n", byte_code, fourcc, data, size);
TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code, fourcc, data, size);
if (data) *data = NULL;
if (size) *size = 0;
if (!byte_code)
return D3DERR_INVALIDCALL;
if (!byte_code) return D3DERR_INVALIDCALL;
if (!is_valid_bytecode(*byte_code)) return D3DXERR_INVALIDDATA;
while (*++ptr != D3DSIO_END)
{

View File

@ -20,6 +20,12 @@
#include "wine/test.h"
#include "d3dx9.h"
static const DWORD shader_zero[] = {0x0};
static const DWORD shader_invalid[] = {0xeeee0100};
static const DWORD shader_empty[] = {0xfffeffff, 0x0000ffff};
static const DWORD simple_vs[] = {
0xfffe0101, /* vs_1_1 */
0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
@ -330,6 +336,21 @@ static void test_find_shader_comment(void)
ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
ok(data == (LPCVOID)(shader_with_ctab + 6), "Got result %p, expected %p\n", data, shader_with_ctab + 6);
ok(size == 28, "Got result %d, expected 28\n", size);
hr = D3DXFindShaderComment(shader_zero, MAKEFOURCC('C','T','A','B'), &data, &size);
ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
ok(!data, "Got %p, expected NULL\n", data);
ok(!size, "Got %u, expected 0\n", size);
hr = D3DXFindShaderComment(shader_invalid, MAKEFOURCC('C','T','A','B'), &data, &size);
ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
ok(!data, "Got %p, expected NULL\n", data);
ok(!size, "Got %u, expected 0\n", size);
hr = D3DXFindShaderComment(shader_empty, MAKEFOURCC('C','T','A','B'), &data, &size);
ok(hr == S_FALSE, "Got result %x, expected %x (S_FALSE)\n", hr, S_FALSE);
ok(!data, "Got %p, expected NULL\n", data);
ok(!size, "Got %u, expected 0\n", size);
}
static void test_get_shader_constant_table_ex(void)