Commit 208d3868 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

ddraw: Check for incorrect rectangles to DDrawSurface::Blt.

parent e019cebd
...@@ -753,7 +753,31 @@ IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface, ...@@ -753,7 +753,31 @@ IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
/* Sizes can change, therefore hold the lock when testing the rectangles */
EnterCriticalSection(&ddraw_cs); 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))) { if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n"); WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
......
...@@ -2208,6 +2208,7 @@ static void BltParamTest(void) ...@@ -2208,6 +2208,7 @@ static void BltParamTest(void)
IDirectDrawSurface *surface1 = NULL, *surface2 = NULL; IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
DDSURFACEDESC desc; DDSURFACEDESC desc;
HRESULT hr; HRESULT hr;
DDBLTFX BltFx;
RECT valid = {10, 10, 20, 20}; RECT valid = {10, 10, 20, 20};
RECT invalid1 = {20, 10, 10, 20}; RECT invalid1 = {20, 10, 10, 20};
RECT invalid2 = {20, 20, 20, 20}; RECT invalid2 = {20, 20, 20, 20};
...@@ -2255,6 +2256,54 @@ static void BltParamTest(void) ...@@ -2255,6 +2256,54 @@ static void BltParamTest(void)
hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0); hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr); 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(surface1);
IDirectDrawSurface_Release(surface2); IDirectDrawSurface_Release(surface2);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment