ddraw: Test for incorrect surface desc sizes in GetSurfaceDesc.

This commit is contained in:
Stefan Dösinger 2007-06-08 17:22:16 +02:00 committed by Alexandre Julliard
parent 60901b7542
commit bf23e5f3f7
3 changed files with 91 additions and 7 deletions

View File

@ -1592,11 +1592,10 @@ IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
if(!DDSD)
return DDERR_INVALIDPARAMS;
if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
(DDSD->dwSize > sizeof(DDSURFACEDESC2)))
if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
{
ERR("Impossible/Strange struct size %d.\n",DDSD->dwSize);
return DDERR_GENERIC;
WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);

View File

@ -20,6 +20,7 @@
#include "wine/port.h"
#include "wine/debug.h"
#include <stdarg.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
@ -41,6 +42,7 @@
(pdds))
WINE_DEFAULT_DEBUG_CHANNEL(ddraw_thunk);
WINE_DECLARE_DEBUG_CHANNEL(ddraw);
static HRESULT WINAPI
IDirectDrawSurface3Impl_QueryInterface(LPDIRECTDRAWSURFACE3 This, REFIID iid,
@ -299,11 +301,33 @@ IDirectDrawSurface3Impl_GetPixelFormat(LPDIRECTDRAWSURFACE3 This,
}
static HRESULT WINAPI
IDirectDrawSurface3Impl_GetSurfaceDesc(LPDIRECTDRAWSURFACE3 This,
IDirectDrawSurface3Impl_GetSurfaceDesc(LPDIRECTDRAWSURFACE3 iface,
LPDDSURFACEDESC pDDSD)
{
return IDirectDrawSurface7_GetSurfaceDesc(CONVERT(This),
(LPDDSURFACEDESC2)pDDSD);
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface3, iface);
TRACE_(ddraw)("(%p)->(%p)\n",This,pDDSD);
if(!pDDSD)
return DDERR_INVALIDPARAMS;
if (pDDSD->dwSize != sizeof(DDSURFACEDESC))
{
WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",pDDSD->dwSize);
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
DD_STRUCT_COPY_BYSIZE(pDDSD,(DDSURFACEDESC *) &This->surface_desc);
TRACE("Returning surface desc:\n");
if (TRACE_ON(ddraw))
{
/* DDRAW_dump_surface_desc handles the smaller size */
DDRAW_dump_surface_desc((DDSURFACEDESC2 *) pDDSD);
}
LeaveCriticalSection(&ddraw_cs);
return DD_OK;
}
static HRESULT WINAPI

View File

@ -2259,6 +2259,66 @@ static void BltParamTest(void)
IDirectDrawSurface_Release(surface2);
}
static void StructSizeTest(void)
{
IDirectDrawSurface *surface1;
IDirectDrawSurface7 *surface7;
union {
DDSURFACEDESC desc1;
DDSURFACEDESC2 desc2;
char blob[1024]; /* To get a buch of writeable memory */
} desc;
DDSURFACEDESC create;
HRESULT hr;
memset(&desc, 0, sizeof(desc));
memset(&create, 0, sizeof(create));
memset(&create, 0, sizeof(create));
create.dwSize = sizeof(create);
create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
create.dwHeight = 128;
create.dwWidth = 128;
hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
desc.desc1.dwSize = sizeof(DDSURFACEDESC);
hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
desc.desc2.dwSize = 0;
hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
IDirectDrawSurface7_Release(surface7);
IDirectDrawSurface_Release(surface1);
}
START_TEST(dsurface)
{
if (!CreateDirectDraw())
@ -2279,5 +2339,6 @@ START_TEST(dsurface)
SizeTest();
PrivateDataTest();
BltParamTest();
StructSizeTest();
ReleaseDirectDraw();
}