mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[USER32]
- Fix a stupid buffer overflow I introduced in r64967. - Take BITMAPCOREINFO into account when loading a cursor from file. svn path=/trunk/; revision=64990
This commit is contained in:
parent
147bfd92e5
commit
34a323186d
1 changed files with 15 additions and 8 deletions
|
@ -254,7 +254,7 @@ create_alpha_bitmap(
|
||||||
HDC hdc = NULL, hdcScreen;
|
HDC hdc = NULL, hdcScreen;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
void *bits = NULL;
|
void *bits = NULL;
|
||||||
int i;
|
size_t size;
|
||||||
|
|
||||||
hdcScreen = CreateDCW(DISPLAYW, NULL, NULL, NULL);
|
hdcScreen = CreateDCW(DISPLAYW, NULL, NULL, NULL);
|
||||||
if (!hdcScreen)
|
if (!hdcScreen)
|
||||||
|
@ -271,11 +271,15 @@ create_alpha_bitmap(
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
BITMAPINFO *info = NULL;
|
BITMAPINFO *info = NULL;
|
||||||
|
|
||||||
|
TRACE("Creating alpha bitmap from existing bitmap.\n");
|
||||||
|
|
||||||
if (!GetObjectW( color, sizeof(bm), &bm ))
|
if (!GetObjectW( color, sizeof(bm), &bm ))
|
||||||
goto done;
|
goto done;
|
||||||
if (bm.bmBitsPixel != 32)
|
if (bm.bmBitsPixel != 32)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
size = get_dib_image_size(bm.bmWidth, bm.bmHeight, 32);
|
||||||
|
|
||||||
info = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
|
info = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
|
||||||
if(!info)
|
if(!info)
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -285,13 +289,13 @@ create_alpha_bitmap(
|
||||||
info->bmiHeader.biPlanes = 1;
|
info->bmiHeader.biPlanes = 1;
|
||||||
info->bmiHeader.biBitCount = 32;
|
info->bmiHeader.biBitCount = 32;
|
||||||
info->bmiHeader.biCompression = BI_RGB;
|
info->bmiHeader.biCompression = BI_RGB;
|
||||||
info->bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
|
info->bmiHeader.biSizeImage = size;
|
||||||
info->bmiHeader.biXPelsPerMeter = 0;
|
info->bmiHeader.biXPelsPerMeter = 0;
|
||||||
info->bmiHeader.biYPelsPerMeter = 0;
|
info->bmiHeader.biYPelsPerMeter = 0;
|
||||||
info->bmiHeader.biClrUsed = 0;
|
info->bmiHeader.biClrUsed = 0;
|
||||||
info->bmiHeader.biClrImportant = 0;
|
info->bmiHeader.biClrImportant = 0;
|
||||||
|
|
||||||
bits = HeapAlloc(GetProcessHeap(), 0, info->bmiHeader.biSizeImage);
|
bits = HeapAlloc(GetProcessHeap(), 0, size);
|
||||||
if(!bits)
|
if(!bits)
|
||||||
{
|
{
|
||||||
HeapFree(GetProcessHeap(), 0, info);
|
HeapFree(GetProcessHeap(), 0, info);
|
||||||
|
@ -309,7 +313,7 @@ create_alpha_bitmap(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pre-multiply by alpha */
|
/* pre-multiply by alpha */
|
||||||
for (i = 0, ptr = bits; i < width * height; i++, ptr += 4)
|
for (ptr = bits; ptr < ((BYTE*)bits + size); ptr += 4)
|
||||||
{
|
{
|
||||||
unsigned int alpha = ptr[3];
|
unsigned int alpha = ptr[3];
|
||||||
ptr[0] = (ptr[0] * alpha) / 255;
|
ptr[0] = (ptr[0] * alpha) / 255;
|
||||||
|
@ -321,15 +325,15 @@ create_alpha_bitmap(
|
||||||
alpha = CreateDIBitmap(hdc, NULL, CBM_INIT | 2, bits, info, DIB_RGB_COLORS);
|
alpha = CreateDIBitmap(hdc, NULL, CBM_INIT | 2, bits, info, DIB_RGB_COLORS);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, info);
|
HeapFree(GetProcessHeap(), 0, info);
|
||||||
HeapFree(GetProcessHeap(), 0, bits);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WORD bpp;
|
WORD bpp;
|
||||||
DWORD compr;
|
DWORD compr;
|
||||||
int size;
|
|
||||||
LONG orig_width, orig_height;
|
LONG orig_width, orig_height;
|
||||||
|
|
||||||
|
TRACE("Creating alpha bitmap from bitmap info.\n");
|
||||||
|
|
||||||
if(!bmi_has_alpha(src_info, color_bits))
|
if(!bmi_has_alpha(src_info, color_bits))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -344,7 +348,7 @@ create_alpha_bitmap(
|
||||||
goto done;
|
goto done;
|
||||||
CopyMemory(bits, color_bits, size);
|
CopyMemory(bits, color_bits, size);
|
||||||
/* pre-multiply by alpha */
|
/* pre-multiply by alpha */
|
||||||
for (i = 0, ptr = bits; i < width * height; i++, ptr += 4)
|
for (ptr = bits; ptr < ((BYTE*)bits + size); ptr += 4)
|
||||||
{
|
{
|
||||||
unsigned int alpha = ptr[3];
|
unsigned int alpha = ptr[3];
|
||||||
ptr[0] = (ptr[0] * alpha) / 255;
|
ptr[0] = (ptr[0] * alpha) / 255;
|
||||||
|
@ -497,6 +501,9 @@ get_best_icon_file_entry(
|
||||||
/* Let's assume there's always one plane */
|
/* Let's assume there's always one plane */
|
||||||
fakeEntry->wPlanes = 1;
|
fakeEntry->wPlanes = 1;
|
||||||
/* We must get the bitcount from the BITMAPINFOHEADER itself */
|
/* We must get the bitcount from the BITMAPINFOHEADER itself */
|
||||||
|
if (((BITMAPINFOHEADER *)((char *)dir + entry->dwDIBOffset))->biSize == sizeof(BITMAPCOREHEADER))
|
||||||
|
fakeEntry->wBitCount = ((BITMAPCOREHEADER *)((char *)dir + entry->dwDIBOffset))->bcBitCount;
|
||||||
|
else
|
||||||
fakeEntry->wBitCount = ((BITMAPINFOHEADER *)((char *)dir + entry->dwDIBOffset))->biBitCount;
|
fakeEntry->wBitCount = ((BITMAPINFOHEADER *)((char *)dir + entry->dwDIBOffset))->biBitCount;
|
||||||
fakeEntry->dwBytesInRes = entry->dwDIBSize;
|
fakeEntry->dwBytesInRes = entry->dwDIBSize;
|
||||||
fakeEntry->wResId = i + 1;
|
fakeEntry->wResId = i + 1;
|
||||||
|
|
Loading…
Reference in a new issue