msrle32: Use the correct number of colors when biClrUsed = 0

Bruno Jesus 00cpxxx at gmail.com
Wed Mar 9 08:02:27 CST 2016


First change ensure the color palette is copied to the output and the
second change ensures the color palette is correctly populated.
Without this change wine will not populate the palette and will use
memory garbage for colors.

Fixes part of bug https://bugs.winehq.org/show_bug.cgi?id=22533

Signed-off-by: Bruno Jesus <00cpxxx at gmail.com>
-------------- next part --------------
diff --git a/dlls/msrle32/msrle32.c b/dlls/msrle32/msrle32.c
index 2682812..10d37b4 100644
--- a/dlls/msrle32/msrle32.c
+++ b/dlls/msrle32/msrle32.c
@@ -1553,6 +1553,7 @@ static LRESULT DecompressGetFormat(CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn,
 				   LPBITMAPINFOHEADER lpbiOut)
 {
   DWORD size;
+  int colors;
 
   TRACE("(%p,%p,%p)\n",pi,lpbiIn,lpbiOut);
 
@@ -1567,8 +1568,13 @@ static LRESULT DecompressGetFormat(CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn,
 
   size = lpbiIn->biSize;
 
-  if (lpbiIn->biBitCount <= 8)
-    size += lpbiIn->biClrUsed * sizeof(RGBQUAD);
+  if (lpbiIn->biBitCount <= 8) {
+    if (lpbiIn->biClrUsed == 0)
+      colors = 1 << lpbiIn->biBitCount;
+    else
+      colors = lpbiIn->biClrUsed;
+  }
+  size += colors * sizeof(RGBQUAD);
 
   if (lpbiOut != NULL) {
     memcpy(lpbiOut, lpbiIn, size);
@@ -1647,27 +1653,33 @@ static LRESULT DecompressBegin(CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn,
 
   if (lpbiIn->biCompression != BI_RGB)
   {
+    int colors;
+
+    if (lpbiIn->biClrUsed == 0)
+      colors = 1 << lpbiIn->biBitCount;
+    else
+      colors = lpbiIn->biClrUsed;
+
     rgbIn  = (const RGBQUAD*)((const BYTE*)lpbiIn  + lpbiIn->biSize);
     rgbOut = (const RGBQUAD*)((const BYTE*)lpbiOut + lpbiOut->biSize);
 
     switch (lpbiOut->biBitCount) {
     case 4:
     case 8:
-      pi->palette_map = LocalAlloc(LPTR, lpbiIn->biClrUsed);
+      pi->palette_map = LocalAlloc(LPTR, colors);
       if (pi->palette_map == NULL)
         return ICERR_MEMORY;
 
-      for (i = 0; i < lpbiIn->biClrUsed; i++) {
-        pi->palette_map[i] = MSRLE32_GetNearestPaletteIndex(lpbiOut->biClrUsed, rgbOut, rgbIn[i]);
-      }
+      for (i = 0; i < colors; i++)
+        pi->palette_map[i] = MSRLE32_GetNearestPaletteIndex(colors, rgbOut, rgbIn[i]);
       break;
     case 15:
     case 16:
-      pi->palette_map = LocalAlloc(LPTR, lpbiIn->biClrUsed * 2);
+      pi->palette_map = LocalAlloc(LPTR, colors * 2);
       if (pi->palette_map == NULL)
         return ICERR_MEMORY;
 
-      for (i = 0; i < lpbiIn->biClrUsed; i++) {
+      for (i = 0; i < colors; i++) {
         WORD color;
 
         if (lpbiOut->biBitCount == 15)
@@ -1683,10 +1695,10 @@ static LRESULT DecompressBegin(CodecInfo *pi, LPCBITMAPINFOHEADER lpbiIn,
       break;
     case 24:
     case 32:
-      pi->palette_map = LocalAlloc(LPTR, lpbiIn->biClrUsed * sizeof(RGBQUAD));
+      pi->palette_map = LocalAlloc(LPTR, colors * sizeof(RGBQUAD));
       if (pi->palette_map == NULL)
         return ICERR_MEMORY;
-      memcpy(pi->palette_map, rgbIn, lpbiIn->biClrUsed * sizeof(RGBQUAD));
+      memcpy(pi->palette_map, rgbIn, colors * sizeof(RGBQUAD));
       break;
     };
   }


More information about the wine-patches mailing list