Fix GDI_PAL_COLORS crash.

Glenn Wurster gwurster at scs.carleton.ca
Tue Apr 5 21:17:17 CDT 2005


> > GDI_PAL_COLORS is composed of 16 bit indexes, we only got the first
> > 256 colours.  Instead of making a copy of possibly 65535 different
> > palette entries in the logical palette, get a pointer and build up the
> > dib colours as needed.  Yes, the % is how windows works.  Yes,
> > conformance tests are in the queue of patches to be submitted.
> 
> GDI_GetObjPtr/GDI_ReleaseObj are the DLL separation hacks and will be
> removed eventually from GDI32 exports. You need to make a copy of all
> palette entries anyway. Perhaps the following code is a better solution:

I've rewritten to not use the GDI_GetObjPtr and GDI_ReleaseObj.  New
Patch is attached.  Thanks for the comments.

ChangeLog:
  * Fix array index crash in buidling GDI palette from Logical Palette.

Author:
  * Glenn Wurster (gwurster at scs.carleton.ca)

Index: dlls/x11drv/dib.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/dib.c,v
retrieving revision 1.27
diff -u -r1.27 dib.c
--- dlls/x11drv/dib.c	31 Mar 2005 19:13:03 -0000	1.27
+++ dlls/x11drv/dib.c	6 Apr 2005 02:03:04 -0000
@@ -418,18 +418,24 @@
     else
     {
         HPALETTE hpal = GetCurrentObject(physDev->hdc, OBJ_PAL);
-        PALETTEENTRY pal_ents[256];
+        PALETTEENTRY * pal_ents;
         WORD *index = (WORD*) ((LPBYTE) info + (WORD) info->bmiHeader.biSize);
+        int logcolors, entry;
 
-        GetPaletteEntries(hpal, 0, 256, pal_ents);
+        logcolors = GetPaletteEntries( hpal, 0, 0, NULL );
+        pal_ents = HeapAlloc(GetProcessHeap(), 0, logcolors * sizeof(*pal_ents));
+        logcolors = GetPaletteEntries( hpal, 0, logcolors, pal_ents );
 
         for(i = 0; i < colors; i++, index++)
         {
-            colorTable[i].rgbRed = pal_ents[*index].peRed;
-            colorTable[i].rgbGreen = pal_ents[*index].peGreen;
-            colorTable[i].rgbBlue = pal_ents[*index].peBlue;
+            entry = *index % logcolors;
+            colorTable[i].rgbRed = pal_ents[entry].peRed;
+            colorTable[i].rgbGreen = pal_ents[entry].peGreen;
+            colorTable[i].rgbBlue = pal_ents[entry].peBlue;
             colorTable[i].rgbReserved = 0;
         }
+
+        HeapFree(GetProcessHeap(), 0, pal_ents);
     }
     return colorTable;
 }



More information about the wine-patches mailing list