gdi32: Add a check for overflow in DIB dimensions.
This commit is contained in:
parent
08e82d4686
commit
69abf20fcd
|
@ -128,6 +128,11 @@ static BOOL is_valid_dib_format( const BITMAPINFOHEADER *info, BOOL allow_compre
|
|||
|
||||
if (!info->biPlanes) return FALSE;
|
||||
|
||||
/* check for size overflow */
|
||||
if (!info->biBitCount) return FALSE;
|
||||
if (UINT_MAX / info->biBitCount < info->biWidth) return FALSE;
|
||||
if (UINT_MAX / get_dib_stride( info->biWidth, info->biBitCount ) < abs( info->biHeight )) return FALSE;
|
||||
|
||||
switch (info->biBitCount)
|
||||
{
|
||||
case 1:
|
||||
|
|
|
@ -1207,6 +1207,49 @@ static void test_dib_formats(void)
|
|||
ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+2);
|
||||
ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+2\n" );
|
||||
|
||||
bi->bmiHeader.biWidth = 0x4000;
|
||||
bi->bmiHeader.biHeight = 0x4000;
|
||||
bi->bmiHeader.biBitCount = 1;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib != NULL, "CreateDIBSection failed with large size\n" );
|
||||
DeleteObject( hdib );
|
||||
|
||||
bi->bmiHeader.biWidth = 0x8001;
|
||||
bi->bmiHeader.biHeight = 0x8001;
|
||||
bi->bmiHeader.biBitCount = 32;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
|
||||
|
||||
bi->bmiHeader.biWidth = 1;
|
||||
bi->bmiHeader.biHeight = 0x40000001;
|
||||
bi->bmiHeader.biBitCount = 32;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
|
||||
|
||||
bi->bmiHeader.biWidth = 2;
|
||||
bi->bmiHeader.biHeight = 0x40000001;
|
||||
bi->bmiHeader.biBitCount = 16;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
|
||||
|
||||
bi->bmiHeader.biWidth = 0x40000001;
|
||||
bi->bmiHeader.biHeight = 1;
|
||||
bi->bmiHeader.biBitCount = 32;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
|
||||
|
||||
bi->bmiHeader.biWidth = 0x40000001;
|
||||
bi->bmiHeader.biHeight = 4;
|
||||
bi->bmiHeader.biBitCount = 8;
|
||||
bi->bmiHeader.biCompression = BI_RGB;
|
||||
hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
|
||||
|
||||
DeleteDC( memdc );
|
||||
DeleteObject( hbmp );
|
||||
ReleaseDC( 0, hdc );
|
||||
|
|
Loading…
Reference in New Issue