Module: wine Branch: master Commit: 5bdfd877a751fe5c99ede04eb25d41a481269bf2 URL: http://source.winehq.org/git/wine.git/?a=commit;h=5bdfd877a751fe5c99ede04eb2...
Author: Tony Wasserka tony.wasserka@freenet.de Date: Wed Jul 28 21:51:42 2010 +0200
d3dx9: Return D3DERR_INVALIDCALL in D3DXLoadSurfaceFromMemory if pDestRect is invalid.
---
dlls/d3dx9_36/surface.c | 7 ++++++- dlls/d3dx9_36/tests/surface.c | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index c39ec57..4bd7450 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -583,7 +583,8 @@ static void copy_simple_data(CONST BYTE *src, UINT srcpitch, POINT srcsize, C * Success: D3D_OK, if we successfully load the pixel data into our surface or * if pSrcMemory is NULL but the other parameters are valid * Failure: D3DERR_INVALIDCALL, if pDestSurface, SrcPitch or pSrcRect are NULL or - * if SrcFormat is an invalid format (other than D3DFMT_UNKNOWN) + * if SrcFormat is an invalid format (other than D3DFMT_UNKNOWN) or + * if DestRect is invalid * D3DXERR_INVALIDDATA, if we fail to lock pDestSurface * E_FAIL, if SrcFormat is D3DFMT_UNKNOWN or the dimensions of pSrcRect are invalid * @@ -631,8 +632,12 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(LPDIRECT3DSURFACE9 pDestSurface, destsize.x = surfdesc.Width; destsize.y = surfdesc.Height; } else { + if(pDestRect->left > pDestRect->right || pDestRect->right > surfdesc.Width) return D3DERR_INVALIDCALL; + if(pDestRect->top > pDestRect->bottom || pDestRect->bottom > surfdesc.Height) return D3DERR_INVALIDCALL; + if(pDestRect->left < 0 || pDestRect->top < 0) return D3DERR_INVALIDCALL; destsize.x = pDestRect->right - pDestRect->left; destsize.y = pDestRect->bottom - pDestRect->top; + if(destsize.x == 0 || destsize.y == 0) return D3D_OK; }
hr = IDirect3DSurface9_LockRect(pDestSurface, &lockrect, pDestRect, 0); diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 43ec02b..83895c0 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -217,7 +217,7 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) HRESULT hr; BOOL testdummy_ok, testbitmap_ok; IDirect3DSurface9 *surf, *newsurf; - RECT rect; + RECT rect, destrect; D3DLOCKED_RECT lockrect; const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 }; const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 }; @@ -330,6 +330,26 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0); ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
+ SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */ + hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); + + SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */ + hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); + + SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */ + hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); + + SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */ + hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); + + SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */ + hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); +
/* D3DXLoadSurfaceFromSurface */ hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);