d3dx9: Handle invalid byte code in D3DXFindShaderComment().
This commit is contained in:
parent
ae9b07fdc0
commit
bc4a4f5f3b
|
@ -40,6 +40,11 @@ HRESULT WINAPI D3DAssemble(LPCVOID data, SIZE_T datasize, LPCSTR filename,
|
||||||
UINT flags,
|
UINT flags,
|
||||||
ID3DBlob **shader, ID3DBlob **error_messages);
|
ID3DBlob **shader, ID3DBlob **error_messages);
|
||||||
|
|
||||||
|
static inline BOOL is_valid_bytecode(DWORD token)
|
||||||
|
{
|
||||||
|
return (token & 0xfffe0000) == 0xfffe0000;
|
||||||
|
}
|
||||||
|
|
||||||
const char * WINAPI D3DXGetPixelShaderProfile(struct IDirect3DDevice9 *device)
|
const char * WINAPI D3DXGetPixelShaderProfile(struct IDirect3DDevice9 *device)
|
||||||
{
|
{
|
||||||
D3DCAPS9 caps;
|
D3DCAPS9 caps;
|
||||||
|
@ -147,17 +152,17 @@ const char * WINAPI D3DXGetVertexShaderProfile(struct IDirect3DDevice9 *device)
|
||||||
return NULL;
|
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 (data) *data = NULL;
|
||||||
if (size) *size = 0;
|
if (size) *size = 0;
|
||||||
|
|
||||||
if (!byte_code)
|
if (!byte_code) return D3DERR_INVALIDCALL;
|
||||||
return D3DERR_INVALIDCALL;
|
if (!is_valid_bytecode(*byte_code)) return D3DXERR_INVALIDDATA;
|
||||||
|
|
||||||
while (*++ptr != D3DSIO_END)
|
while (*++ptr != D3DSIO_END)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,12 @@
|
||||||
#include "wine/test.h"
|
#include "wine/test.h"
|
||||||
#include "d3dx9.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[] = {
|
static const DWORD simple_vs[] = {
|
||||||
0xfffe0101, /* vs_1_1 */
|
0xfffe0101, /* vs_1_1 */
|
||||||
0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
|
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(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(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);
|
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)
|
static void test_get_shader_constant_table_ex(void)
|
||||||
|
|
Loading…
Reference in New Issue