[PATCH] msvfw32: Fix copying of a BITMAPINFO structure (Valgrind).

Sven Baars sven.wine at gmail.com
Sun Jun 2 09:21:38 CDT 2019


Signed-off-by: Sven Baars <sven.wine at gmail.com>
---
 dlls/msvfw32/msvideo_main.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/dlls/msvfw32/msvideo_main.c b/dlls/msvfw32/msvideo_main.c
index fe140b279a..346dbade43 100644
--- a/dlls/msvfw32/msvideo_main.c
+++ b/dlls/msvfw32/msvideo_main.c
@@ -1506,6 +1506,28 @@ void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc)
     clear_compvars(pc);
 }
 
+static BITMAPINFO *copy_bitmapinfo(const BITMAPINFO *src)
+{
+    int num_colors;
+    unsigned int size;
+    BITMAPINFO *dst;
+
+    if (src->bmiHeader.biClrUsed)
+        num_colors = min(src->bmiHeader.biClrUsed, 256);
+    else
+        num_colors = src->bmiHeader.biBitCount > 8 ? 0 : 1 << src->bmiHeader.biBitCount;
+
+    size = FIELD_OFFSET(BITMAPINFO, bmiColors[num_colors]);
+    if (src->bmiHeader.biCompression == BI_BITFIELDS)
+        size += 3 * sizeof(DWORD);
+
+    if (!(dst = heap_alloc(size)))
+        return NULL;
+
+    memcpy(dst, src, size);
+    return dst;
+}
+
 /***********************************************************************
  *      ICSeqCompressFrameStart [MSVFW32.@]
  */
@@ -1517,11 +1539,9 @@ BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn)
     DWORD ret;
     ICCOMPRESS* icComp;
 
-    if (!(pc->lpbiIn = heap_alloc(sizeof(BITMAPINFO))))
+    if (!(pc->lpbiIn = copy_bitmapinfo(lpbiIn)))
         return FALSE;
 
-    *pc->lpbiIn = *lpbiIn;
-
     if (!(pc->lpState = heap_alloc(sizeof(ICCOMPRESS) + sizeof(*icComp->lpckid) + sizeof(*icComp->lpdwFlags))))
         goto error;
 
-- 
2.17.1




More information about the wine-devel mailing list