gdi32: Do not allow to create too large device dependent bitmaps like Windows does.
This commit is contained in:
parent
4111ea931c
commit
d5456de058
|
@ -136,13 +136,6 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
|
|||
|
||||
TRACE("(%p,%d,%d) =\n", hdc, width, height);
|
||||
|
||||
if ((width >= 0x10000) || (height >= 0x10000))
|
||||
{
|
||||
FIXME("got bad width %d or height %d, please look for reason\n",
|
||||
width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(dc = DC_GetDCPtr(hdc))) return 0;
|
||||
|
||||
if (GDIMAGIC( dc->header.wMagic ) != MEMORY_DC_MAGIC)
|
||||
|
@ -208,7 +201,6 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
|
|||
GDI_ReleaseObj(dc->hBitmap);
|
||||
}
|
||||
DC_ReleaseDCPtr( dc );
|
||||
}
|
||||
|
||||
TRACE("\t\t%p\n", hbmpRet);
|
||||
return hbmpRet;
|
||||
|
@ -242,6 +234,12 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (bmp->bmWidth > 0x7ffffff || bmp->bmHeight > 0x7ffffff)
|
||||
{
|
||||
SetLastError( ERROR_INVALID_PARAMETER );
|
||||
return 0;
|
||||
}
|
||||
|
||||
bm = *bmp;
|
||||
|
||||
if (!bm.bmWidth || !bm.bmHeight)
|
||||
|
@ -278,6 +276,12 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
|
|||
|
||||
/* Windows ignores the provided bm.bmWidthBytes */
|
||||
bm.bmWidthBytes = BITMAP_GetWidthBytes( bm.bmWidth, bm.bmBitsPixel );
|
||||
/* XP doesn't allow to create bitmaps larger than 128 Mb */
|
||||
if (bm.bmHeight * bm.bmWidthBytes > 128 * 1024 * 1024)
|
||||
{
|
||||
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create the BITMAPOBJ */
|
||||
bmpobj = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC,
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "windef.h"
|
||||
#include "winbase.h"
|
||||
#include "winerror.h"
|
||||
#include "wingdi.h"
|
||||
#include "winuser.h"
|
||||
#include "mmsystem.h"
|
||||
|
@ -966,6 +967,23 @@ static void test_bitmap(void)
|
|||
hdc = CreateCompatibleDC(0);
|
||||
assert(hdc != 0);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
|
||||
ok(hbmp != 0, "CreateBitmap should not fail\n");
|
||||
DeleteObject(hbmp);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
|
||||
ok(!hbmp, "CreateBitmap should fail\n");
|
||||
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
|
||||
"expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
|
||||
ok(!hbmp, "CreateBitmap should fail\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
|
||||
|
||||
hbmp = CreateBitmap(15, 15, 1, 1, NULL);
|
||||
assert(hbmp != NULL);
|
||||
|
||||
|
|
Loading…
Reference in New Issue