From 12d5c03fcc39cdcf5f7936baefdfcfb43bb0389f Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 30 Sep 2012 14:53:46 +0000 Subject: [PATCH] [GDI32] - Some fixes for CreateDIBitmap (Patch by Victor Martinez, modified by me) CORE-6420 #resolve - Fix warning on MSVC svn path=/trunk/; revision=57440 --- reactos/win32ss/gdi/gdi32/objects/bitmap.c | 41 +++++++++++++++++++++- reactos/win32ss/gdi/gdi32/objects/efloat.c | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/reactos/win32ss/gdi/gdi32/objects/bitmap.c b/reactos/win32ss/gdi/gdi32/objects/bitmap.c index 0de16584bc8..100ce227f23 100644 --- a/reactos/win32ss/gdi/gdi32/objects/bitmap.c +++ b/reactos/win32ss/gdi/gdi32/objects/bitmap.c @@ -449,14 +449,53 @@ CreateDIBitmap( HDC hDC, HBITMAP hBmp; NTSTATUS Status = STATUS_SUCCESS; - if (!Header) return 0; + /* Check for CBM_CREATDIB */ + if (Init & CBM_CREATDIB) + { + /* CBM_CREATDIB needs Data. */ + if (!Data) + { + return 0; + } + /* It only works with PAL or RGB */ + if (ColorUse > DIB_PAL_COLORS) + { + GdiSetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + } + + /* Header is required */ + if (!Header) + { + GdiSetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + /* Get the bitmap format and dimensions */ if (DIB_GetBitmapInfo(Header, &width, &height, &planes, &bpp, &compr, &dibsize) == -1) { GdiSetLastError(ERROR_INVALID_PARAMETER); return NULL; } + /* Check if the Compr is incompatible */ + if ((compr == BI_JPEG) || (compr == BI_PNG) || (compr == BI_BITFIELDS)) return 0; + + /* Only DIB_RGB_COLORS (0), DIB_PAL_COLORS (1) and 2 are valid. */ + if (ColorUse > DIB_PAL_COLORS + 1) + { + GdiSetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + /* Negative width is not allowed */ + if (width < 0) return 0; + + /* Top-down DIBs have a negative height. */ + height = abs(height); + // For Icm support. // GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr)) diff --git a/reactos/win32ss/gdi/gdi32/objects/efloat.c b/reactos/win32ss/gdi/gdi32/objects/efloat.c index 001472e76f6..d37ffedd841 100644 --- a/reactos/win32ss/gdi/gdi32/objects/efloat.c +++ b/reactos/win32ss/gdi/gdi32/objects/efloat.c @@ -27,7 +27,7 @@ EFtoF(EFLOAT_S * efp) Exp = efp->lExp; Sign = SIGN(Mant); - if (Sign) Mant = -Mant; + if (Sign) Mant = -(LONG)Mant; Mant >>= 7; Exp += (EXCESS-1);