diff --git a/reactos/subsystems/win32/win32k/include/bitmaps.h b/reactos/subsystems/win32/win32k/include/bitmaps.h index c7736b847d4..d2948ded6c2 100644 --- a/reactos/subsystems/win32/win32k/include/bitmaps.h +++ b/reactos/subsystems/win32/win32k/include/bitmaps.h @@ -53,7 +53,7 @@ BOOL INTERNAL_CALL BITMAPOBJ_InitBitsLock(BITMAPOBJ *pBMObj); void INTERNAL_CALL BITMAPOBJ_CleanupBitsLock(BITMAPOBJ *pBMObj); INT FASTCALL BITMAPOBJ_GetWidthBytes (INT bmWidth, INT bpp); -INT FASTCALL BITMAPOBJ_GetRealBitsPixel(INT nBitsPixel); +UINT FASTCALL BITMAPOBJ_GetRealBitsPixel(UINT nBitsPixel); HBITMAP FASTCALL BITMAPOBJ_CopyBitmap (HBITMAP hBitmap); INT FASTCALL DIB_GetDIBWidthBytes (INT width, INT depth); int NTAPI DIB_GetDIBImageBytes (INT width, INT height, INT depth); diff --git a/reactos/subsystems/win32/win32k/objects/bitmaps.c b/reactos/subsystems/win32/win32k/objects/bitmaps.c index 95a040f6801..62ec2d9bece 100644 --- a/reactos/subsystems/win32/win32k/objects/bitmaps.c +++ b/reactos/subsystems/win32/win32k/objects/bitmaps.c @@ -47,18 +47,26 @@ IntGdiCreateBitmap( BitsPixel = BITMAPOBJ_GetRealBitsPixel(BitsPixel * Planes); /* Check parameters */ - if (BitsPixel == 0 || Width < 0) + if (BitsPixel == 0 || Width <= 0 || Width >= 0x8000000 || Height == 0) { DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", Width, Height, BitsPixel); SetLastWin32Error(ERROR_INVALID_PARAMETER); return 0; } - WidthBytes = BITMAPOBJ_GetWidthBytes(Width, Planes * BitsPixel); + WidthBytes = BITMAPOBJ_GetWidthBytes(Width, BitsPixel); - Size.cx = abs(Width); + Size.cx = Width; Size.cy = abs(Height); + /* Make sure that cjBits will not overflow */ + if ((ULONGLONG)WidthBytes * Size.cy >= 0x100000000ULL) + { + DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", Width, Height, BitsPixel); + SetLastWin32Error(ERROR_INVALID_PARAMETER); + return 0; + } + /* Create the bitmap object. */ hBitmap = IntCreateBitmap(Size, WidthBytes, BitmapFormat(BitsPixel, BI_RGB), @@ -166,18 +174,10 @@ IntCreateCompatibleBitmap( { HBITMAP Bmp; - Bmp = NULL; - - if ((Width >= 0x10000) || (Height >= 0x10000)) - { - DPRINT1("got bad width %d or height %d, please look for reason\n", Width, Height); - return NULL; - } - /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */ if (0 == Width || 0 == Height) { - Bmp = IntGdiCreateBitmap (1, 1, 1, 1, NULL); + Bmp = NtGdiGetStockObject(DEFAULT_BITMAP); } else { @@ -602,15 +602,11 @@ NtGdiSetPixel( /* Internal Functions */ -INT FASTCALL -BITMAPOBJ_GetRealBitsPixel(INT nBitsPixel) +UINT FASTCALL +BITMAPOBJ_GetRealBitsPixel(UINT nBitsPixel) { - if (nBitsPixel < 0) - return 0; if (nBitsPixel <= 1) return 1; - if (nBitsPixel <= 2) - return 2; if (nBitsPixel <= 4) return 4; if (nBitsPixel <= 8)