From 34310d44792b334d4995b1830c4137d9b764eba8 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Oct 2011 00:43:05 +0200 Subject: [PATCH] gdi32: Add a check for null bitfields in SetDIBits. --- dlls/gdi32/dib.c | 9 +++++++++ dlls/gdi32/tests/bitmap.c | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c index 56efda7aff8..20041adf659 100644 --- a/dlls/gdi32/dib.c +++ b/dlls/gdi32/dib.c @@ -519,6 +519,15 @@ INT WINAPI SetDIBits( HDC hdc, HBITMAP hbitmap, UINT startscan, SetLastError( ERROR_INVALID_PARAMETER ); return 0; } + if (src_info->bmiHeader.biCompression == BI_BITFIELDS) + { + DWORD *masks = (DWORD *)src_info->bmiColors; + if (!masks[0] || !masks[1] || !masks[2]) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + } src_bits.ptr = (void *)bits; src_bits.is_copy = FALSE; diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c index eaf96a55c9d..e069fa83dff 100644 --- a/dlls/gdi32/tests/bitmap.c +++ b/dlls/gdi32/tests/bitmap.c @@ -976,7 +976,7 @@ static void test_dib_formats(void) hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0); ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" ); ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS); - todo_wine ok( !ret, "SetDIBits succeeded with null bitfields\n" ); + ok( !ret, "SetDIBits succeeded with null bitfields\n" ); /* other functions don't check */ hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS ); ok( hdib != NULL, "CreateDIBitmap failed with null bitfields\n" ); @@ -984,7 +984,7 @@ static void test_dib_formats(void) ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS ); ok( ret, "SetDIBitsToDevice failed with null bitfields\n" ); ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY ); - ok( ret, "StretchDIBits failed with null bitfields\n" ); + todo_wine ok( ret, "StretchDIBits failed with null bitfields\n" ); ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS); ok( ret, "GetDIBits failed with null bitfields\n" ); bi->bmiHeader.biPlanes = 1; @@ -1004,7 +1004,7 @@ static void test_dib_formats(void) hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0); ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" ); ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS); - todo_wine ok( !ret, "SetDIBits succeeded with null bitfields\n" ); + ok( !ret, "SetDIBits succeeded with null bitfields\n" ); /* garbage is ok though */ *(DWORD *)&bi->bmiColors[0] = 0x55;