Stefan Dösinger : ddraw: Test for incorrect surface desc sizes in GetSurfaceDesc.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Jun 20 09:13:44 CDT 2007


Module: wine
Branch: master
Commit: bf23e5f3f738e80c9cc9873dbfbb6f4d5c33bec8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=bf23e5f3f738e80c9cc9873dbfbb6f4d5c33bec8

Author: Stefan Dösinger <stefandoesinger at gmx.at>
Date:   Fri Jun  8 17:22:16 2007 +0200

ddraw: Test for incorrect surface desc sizes in GetSurfaceDesc.

---

 dlls/ddraw/surface.c        |    7 ++---
 dlls/ddraw/surface_thunks.c |   30 +++++++++++++++++++--
 dlls/ddraw/tests/dsurface.c |   61 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 43c8448..934999c 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -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);
diff --git a/dlls/ddraw/surface_thunks.c b/dlls/ddraw/surface_thunks.c
index 299e4f6..d8ce9ba 100644
--- a/dlls/ddraw/surface_thunks.c
+++ b/dlls/ddraw/surface_thunks.c
@@ -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
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 449e49f..55d7cbd 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -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();
 }




More information about the wine-cvs mailing list