=?UTF-8?Q?Rico=20Sch=C3=BCller=20?=: d3dx9: Handle invalid byte code in D3DXFindShaderComment().
Alexandre Julliard
julliard at winehq.org
Tue Jan 8 13:58:43 CST 2013
Module: wine
Branch: master
Commit: bc4a4f5f3b1583d076d13d119e45dac1717494d0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=bc4a4f5f3b1583d076d13d119e45dac1717494d0
Author: Rico Schüller <kgbricola at web.de>
Date: Mon Jan 7 21:57:07 2013 +0100
d3dx9: Handle invalid byte code in D3DXFindShaderComment().
---
dlls/d3dx9_36/shader.c | 15 ++++++++++-----
dlls/d3dx9_36/tests/shader.c | 21 +++++++++++++++++++++
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c
index 9137a98..9269237 100644
--- a/dlls/d3dx9_36/shader.c
+++ b/dlls/d3dx9_36/shader.c
@@ -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)
{
diff --git a/dlls/d3dx9_36/tests/shader.c b/dlls/d3dx9_36/tests/shader.c
index 223bebf..8ec98ba 100644
--- a/dlls/d3dx9_36/tests/shader.c
+++ b/dlls/d3dx9_36/tests/shader.c
@@ -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)
More information about the wine-cvs
mailing list