[PATCH 1/2] user32: make DIB_GetBitmapInfo checks stricter

Wolfram Sang wolfram at the-dreams.de
Tue Feb 22 01:39:26 CST 2011


Commit 3a263a871c3fadfdcbf5ec113e31033a1f12fe54 (user32: Fix handling of bitmap
header size for V4/V5 bitmaps) weakened the check for a valid bitmap header too
much. Reapply the sanity checks.

Also, turn the error (which it is not) into a warning, correct the type and
print the size at a more meaningful location.

Signed-off-by: Wolfram Sang <wolfram at the-dreams.de>
---
 dlls/user32/cursoricon.c       |    6 ++++--
 dlls/user32/tests/cursoricon.c |    3 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index d014711..715e12b 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -374,7 +374,9 @@ static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
         *compr  = 0;
         return 0;
     }
-    else if (header->biSize >= sizeof(BITMAPINFOHEADER))
+    else if (header->biSize == sizeof(BITMAPINFOHEADER) ||
+             header->biSize == sizeof(BITMAPV4HEADER) ||
+             header->biSize == sizeof(BITMAPV5HEADER))
     {
         *width  = header->biWidth;
         *height = header->biHeight;
@@ -382,7 +384,7 @@ static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
         *compr  = header->biCompression;
         return 1;
     }
-    ERR("(%d): unknown/wrong size for header\n", header->biSize );
+    WARN("unknown/wrong size (%u) for header\n", header->biSize);
     return -1;
 }
 
diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c
index cba5704..1cf6160 100644
--- a/dlls/user32/tests/cursoricon.c
+++ b/dlls/user32/tests/cursoricon.c
@@ -988,6 +988,9 @@ static void test_LoadImage(void)
     bmpimage[0x18]++; /* biWidth > 65535 */
     test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
     bmpimage[0x18]--;
+    bmpimage[0x11]++; /* biSize > 2^24 */
+    test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
+    bmpimage[0x11]--;
 }
 
 static void test_CreateIconFromResource(void)
-- 
1.7.2.3




More information about the wine-patches mailing list