CreateDIBSection takes a CONST pointer to BITMAPINFO according to Platform SDK headers

Dmitry Timoshkov dmitry at baikal.ru
Fri Mar 12 09:00:55 CST 2004


Hello,

this bug triggered the following message when an app was trying to create
a DIB section from a bitmap header stored in read-only resources:

fixme:seh:check_resource_write Broken app is writing to the resource data, enabling work-around

I wish it would better crash.

Seems like these days biClrUsed is correctly handled by x11drv DIB code,
and biClrImportant is not used at all.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    CreateDIBSection takes a CONST pointer to BITMAPINFO according to
    Platform SDK headers.

diff -u cvs/hq/wine/dlls/ddraw/dsurface/dib.c wine/dlls/ddraw/dsurface/dib.c
--- cvs/hq/wine/dlls/ddraw/dsurface/dib.c	2004-03-07 17:24:46.000000000 +0800
+++ wine/dlls/ddraw/dsurface/dib.c	2004-03-12 22:34:50.000000000 +0800
@@ -36,7 +36,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
 /* FIXME */
-extern HBITMAP DIB_CreateDIBSection( HDC hdc, BITMAPINFO *bmi, UINT usage, LPVOID *bits,
+extern HBITMAP DIB_CreateDIBSection( HDC hdc, const BITMAPINFO *bmi, UINT usage, VOID **bits,
                                      HANDLE section, DWORD offset, DWORD ovr_pitch );
 
 static ICOM_VTABLE(IDirectDrawSurface7) DIB_IDirectDrawSurface7_VTable;
diff -u cvs/hq/wine/dlls/gdi/gdi_private.h wine/dlls/gdi/gdi_private.h
--- cvs/hq/wine/dlls/gdi/gdi_private.h	2004-03-07 17:24:47.000000000 +0800
+++ wine/dlls/gdi/gdi_private.h	2004-03-12 22:11:06.000000000 +0800
@@ -62,7 +62,7 @@ typedef struct tagDC_FUNCS
     BOOL     (*pCloseFigure)(PHYSDEV);
     BOOL     (*pCreateBitmap)(PHYSDEV,HBITMAP);
     BOOL     (*pCreateDC)(HDC,PHYSDEV *,LPCWSTR,LPCWSTR,LPCWSTR,const DEVMODEW*);
-    HBITMAP  (*pCreateDIBSection)(PHYSDEV,BITMAPINFO *,UINT,LPVOID *,HANDLE,DWORD,DWORD);
+    HBITMAP  (*pCreateDIBSection)(PHYSDEV,const BITMAPINFO *,UINT,VOID **,HANDLE,DWORD,DWORD);
     BOOL     (*pDeleteBitmap)(HBITMAP);
     BOOL     (*pDeleteDC)(PHYSDEV);
     BOOL     (*pDeleteObject)(PHYSDEV,HGDIOBJ);
diff -u cvs/hq/wine/dlls/x11drv/dib.c wine/dlls/x11drv/dib.c
--- cvs/hq/wine/dlls/x11drv/dib.c	2004-03-07 17:24:51.000000000 +0800
+++ wine/dlls/x11drv/dib.c	2004-03-12 22:23:18.000000000 +0800
@@ -4505,8 +4505,8 @@ static XImage *X11DRV_XShmCreateImage( i
  *           X11DRV_DIB_CreateDIBSection
  */
 HBITMAP X11DRV_DIB_CreateDIBSection(
-  X11DRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage,
-  LPVOID *bits, HANDLE section,
+  X11DRV_PDEVICE *physDev, const BITMAPINFO *bmi, UINT usage,
+  VOID **bits, HANDLE section,
   DWORD offset, DWORD ovr_pitch)
 {
   HBITMAP res = 0;
@@ -4516,7 +4516,7 @@ HBITMAP X11DRV_DIB_CreateDIBSection(
   int nColorMap;
 
   /* Fill BITMAP32 structure with DIB data */
-  BITMAPINFOHEADER *bi = &bmi->bmiHeader;
+  const BITMAPINFOHEADER *bi = &bmi->bmiHeader;
   INT effHeight, totalSize;
   BITMAP bm;
   LPVOID mapBits = NULL;
diff -u cvs/hq/wine/dlls/x11drv/x11drv.h wine/dlls/x11drv/x11drv.h
--- cvs/hq/wine/dlls/x11drv/x11drv.h	2004-03-07 17:24:51.000000000 +0800
+++ wine/dlls/x11drv/x11drv.h	2004-03-12 22:08:33.000000000 +0800
@@ -287,8 +287,8 @@ extern INT X11DRV_CoerceDIBSection2(HBIT
 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
 
-extern HBITMAP X11DRV_DIB_CreateDIBSection(X11DRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage,
-					   LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
+extern HBITMAP X11DRV_DIB_CreateDIBSection(X11DRV_PDEVICE *physDev, const BITMAPINFO *bmi, UINT usage,
+                                           VOID **bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
 extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
 extern INT X11DRV_DIB_Coerce(struct tagBITMAPOBJ *,INT,BOOL);
 extern INT X11DRV_DIB_Lock(struct tagBITMAPOBJ *,INT,BOOL);
diff -u cvs/hq/wine/include/wine/wingdi16.h wine/include/wine/wingdi16.h
--- cvs/hq/wine/include/wine/wingdi16.h	2004-01-16 17:47:28.000000000 +0800
+++ wine/include/wine/wingdi16.h	2004-03-12 22:24:26.000000000 +0800
@@ -409,7 +409,7 @@ HDC16       WINAPI CreateDC16(LPCSTR,LPC
 HBITMAP16   WINAPI CreateDIBitmap16(HDC16,const BITMAPINFOHEADER*,DWORD,
                                     LPCVOID,const BITMAPINFO*,UINT16);
 HBRUSH16    WINAPI CreateDIBPatternBrush16(HGLOBAL16,UINT16);
-HBITMAP16   WINAPI CreateDIBSection16 (HDC16, BITMAPINFO *, UINT16,
+HBITMAP16   WINAPI CreateDIBSection16 (HDC16, const BITMAPINFO *, UINT16,
 				       SEGPTR *, HANDLE, DWORD offset);
 HBITMAP16   WINAPI CreateDiscardableBitmap16(HDC16,INT16,INT16);
 HRGN16      WINAPI CreateEllipticRgn16(INT16,INT16,INT16,INT16);
diff -u cvs/hq/wine/include/wingdi.h wine/include/wingdi.h
--- cvs/hq/wine/include/wingdi.h	2004-02-05 15:53:39.000000000 +0800
+++ wine/include/wingdi.h	2004-03-12 22:25:20.000000000 +0800
@@ -3167,8 +3167,8 @@ HBITMAP   WINAPI CreateDIBitmap(HDC,cons
                                     LPCVOID,const BITMAPINFO*,UINT);
 HBRUSH    WINAPI CreateDIBPatternBrush(HGLOBAL,UINT);
 HBRUSH    WINAPI CreateDIBPatternBrushPt(const void*,UINT);
-HBITMAP   WINAPI CreateDIBSection (HDC, BITMAPINFO *, UINT,
-				       LPVOID *, HANDLE, DWORD offset);
+HBITMAP   WINAPI CreateDIBSection(HDC, CONST BITMAPINFO *, UINT,
+                                  VOID **, HANDLE, DWORD offset);
 HBITMAP   WINAPI CreateDiscardableBitmap(HDC,INT,INT);
 HRGN      WINAPI CreateEllipticRgn(INT,INT,INT,INT);
 HRGN      WINAPI CreateEllipticRgnIndirect(const RECT *);
diff -u cvs/hq/wine/objects/dib.c wine/objects/dib.c
--- cvs/hq/wine/objects/dib.c	2004-03-07 17:24:52.000000000 +0800
+++ wine/objects/dib.c	2004-03-12 22:41:58.000000000 +0800
@@ -841,7 +841,7 @@ HBITMAP WINAPI CreateDIBitmap( HDC hdc, 
 /***********************************************************************
  *           CreateDIBSection    (GDI.489)
  */
-HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage,
+HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, const BITMAPINFO *bmi, UINT16 usage,
                                      SEGPTR *bits16, HANDLE section, DWORD offset)
 {
     LPVOID bits32;
@@ -853,7 +853,7 @@ HBITMAP16 WINAPI CreateDIBSection16 (HDC
         BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC);
         if (bmp && bmp->dib && bits32)
         {
-            BITMAPINFOHEADER *bi = &bmi->bmiHeader;
+            const BITMAPINFOHEADER *bi = &bmi->bmiHeader;
             INT height = bi->biHeight >= 0 ? bi->biHeight : -bi->biHeight;
             INT width_bytes = DIB_GetDIBWidthBytes(bi->biWidth, bi->biBitCount);
             INT size  = (bi->biSizeImage && bi->biCompression != BI_RGB) ?
@@ -881,8 +881,8 @@ HBITMAP16 WINAPI CreateDIBSection16 (HDC
 /***********************************************************************
  *           DIB_CreateDIBSection
  */
-HBITMAP DIB_CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage,
-			     LPVOID *bits, HANDLE section,
+HBITMAP DIB_CreateDIBSection(HDC hdc, const BITMAPINFO *bmi, UINT usage,
+			     VOID **bits, HANDLE section,
 			     DWORD offset, DWORD ovr_pitch)
 {
     HBITMAP hbitmap = 0;
@@ -896,12 +896,6 @@ HBITMAP DIB_CreateDIBSection(HDC hdc, BI
         bDesktopDC = TRUE;
     }
 
-    /* Windows ignores the supplied values of biClrUsed and biClrImportant thus: */
-    if (bmi->bmiHeader.biBitCount >= 1 && bmi->bmiHeader.biBitCount <= 8)
-        bmi->bmiHeader.biClrUsed = bmi->bmiHeader.biClrImportant = 1L << bmi->bmiHeader.biBitCount;
-    else
-        bmi->bmiHeader.biClrUsed = bmi->bmiHeader.biClrImportant = 0;
-
     if ((dc = DC_GetDCPtr( hdc )))
     {
         if(dc->funcs->pCreateDIBSection)
@@ -918,8 +912,8 @@ HBITMAP DIB_CreateDIBSection(HDC hdc, BI
 /***********************************************************************
  *           CreateDIBSection    (GDI32.@)
  */
-HBITMAP WINAPI CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage,
-				LPVOID *bits, HANDLE section,
+HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage,
+				VOID **bits, HANDLE section,
 				DWORD offset)
 {
     return DIB_CreateDIBSection(hdc, bmi, usage, bits, section, offset, 0);






More information about the wine-patches mailing list