Module: wine Branch: master Commit: 208d38688ae0b101ff5398d660ca408bd77bc985 URL: http://source.winehq.org/git/wine.git/?a=commit;h=208d38688ae0b101ff5398d660...
Author: Stefan Dösinger stefandoesinger@gmx.at Date: Fri Jun 8 19:04:13 2007 +0200
ddraw: Check for incorrect rectangles to DDrawSurface::Blt.
---
dlls/ddraw/surface.c | 24 +++++++++++++++++++++ dlls/ddraw/tests/dsurface.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 9608aef..39ed549 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -753,7 +753,31 @@ IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface, return DDERR_INVALIDPARAMS; }
+ /* Sizes can change, therefore hold the lock when testing the rectangles */ EnterCriticalSection(&ddraw_cs); + if(DestRect) + { + if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right || + DestRect->right > This->surface_desc.dwWidth || + DestRect->bottom > This->surface_desc.dwHeight) + { + WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n"); + LeaveCriticalSection(&ddraw_cs); + return DDERR_INVALIDRECT; + } + } + if(Src && SrcRect) + { + if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right || + SrcRect->right > Src->surface_desc.dwWidth || + SrcRect->bottom > Src->surface_desc.dwHeight) + { + WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n"); + LeaveCriticalSection(&ddraw_cs); + return DDERR_INVALIDRECT; + } + } + if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) { WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n"); LeaveCriticalSection(&ddraw_cs); diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index a02c1d3..a21a76d 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -2208,6 +2208,7 @@ static void BltParamTest(void) IDirectDrawSurface *surface1 = NULL, *surface2 = NULL; DDSURFACEDESC desc; HRESULT hr; + DDBLTFX BltFx; RECT valid = {10, 10, 20, 20}; RECT invalid1 = {20, 10, 10, 20}; RECT invalid2 = {20, 20, 20, 20}; @@ -2255,6 +2256,54 @@ static void BltParamTest(void) hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0); ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
+ /* Blt(non-fast) tests */ + memset(&BltFx, 0, sizeof(BltFx)); + BltFx.dwSize = sizeof(BltFx); + BltFx.dwFillColor = 0xaabbccdd; + + hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx); + ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr); + + /* Valid on surface 1 */ + hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx); + ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr); + + /* Works - stretched blit */ + hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL); + ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL); + ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr); + + /* Invalid dest rects in sourced blits */ + hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr); + + /* Invalid src rects */ + hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr); + hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL); + ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr); + IDirectDrawSurface_Release(surface1); IDirectDrawSurface_Release(surface2); }