Commit 7f7dd82c authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Sanitize the DIB information for DIB pattern brushes.

parent 6bf6575c
...@@ -53,21 +53,6 @@ static const struct gdi_obj_funcs brush_funcs = ...@@ -53,21 +53,6 @@ static const struct gdi_obj_funcs brush_funcs =
BRUSH_DeleteObject /* pDeleteObject */ BRUSH_DeleteObject /* pDeleteObject */
}; };
static void *dib_copy(const BITMAPINFO *info, UINT coloruse)
{
BITMAPINFO *newInfo;
INT size;
if (info->bmiHeader.biCompression != BI_RGB && info->bmiHeader.biCompression != BI_BITFIELDS)
size = info->bmiHeader.biSizeImage;
else
size = get_dib_image_size(info);
size += bitmap_info_size( info, coloruse );
if ((newInfo = HeapAlloc( GetProcessHeap(), 0, size ))) memcpy( newInfo, info, size );
return newInfo;
}
/*********************************************************************** /***********************************************************************
* CreateBrushIndirect (GDI32.@) * CreateBrushIndirect (GDI32.@)
...@@ -117,8 +102,8 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush ) ...@@ -117,8 +102,8 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
case BS_DIBPATTERNPT: case BS_DIBPATTERNPT:
ptr->logbrush.lbStyle = BS_DIBPATTERN; ptr->logbrush.lbStyle = BS_DIBPATTERN;
ptr->logbrush.lbHatch = (ULONG_PTR)dib_copy( (BITMAPINFO *) ptr->logbrush.lbHatch, ptr->logbrush.lbHatch = (ULONG_PTR)copy_packed_dib( (BITMAPINFO *) ptr->logbrush.lbHatch,
ptr->logbrush.lbColor); ptr->logbrush.lbColor );
if (!ptr->logbrush.lbHatch) goto error; if (!ptr->logbrush.lbHatch) goto error;
break; break;
...@@ -129,7 +114,7 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush ) ...@@ -129,7 +114,7 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
ptr->logbrush.lbStyle = BS_DIBPATTERN; ptr->logbrush.lbStyle = BS_DIBPATTERN;
if (!(bmi = GlobalLock( h ))) goto error; if (!(bmi = GlobalLock( h ))) goto error;
ptr->logbrush.lbHatch = (ULONG_PTR)dib_copy( bmi, ptr->logbrush.lbColor); ptr->logbrush.lbHatch = (ULONG_PTR)copy_packed_dib( bmi, ptr->logbrush.lbColor );
GlobalUnlock( h ); GlobalUnlock( h );
if (!ptr->logbrush.lbHatch) goto error; if (!ptr->logbrush.lbHatch) goto error;
break; break;
......
...@@ -1113,6 +1113,23 @@ void get_ddb_bitmapinfo( BITMAPOBJ *bmp, BITMAPINFO *info ) ...@@ -1113,6 +1113,23 @@ void get_ddb_bitmapinfo( BITMAPOBJ *bmp, BITMAPINFO *info )
if (info->bmiHeader.biBitCount <= 8) fill_default_color_table( info ); if (info->bmiHeader.biBitCount <= 8) fill_default_color_table( info );
} }
BITMAPINFO *copy_packed_dib( const BITMAPINFO *src_info, UINT usage )
{
char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
BITMAPINFO *ret, *info = (BITMAPINFO *)buffer;
int info_size, image_size;
if (!bitmapinfo_from_user_bitmapinfo( info, src_info, usage, FALSE )) return NULL;
info_size = bitmap_info_size( info, usage );
image_size = get_dib_image_size( info );
if ((ret = HeapAlloc( GetProcessHeap(), 0, info_size + image_size )))
{
memcpy( ret, info, info_size );
memcpy( (char *)ret + info_size, (char *)src_info + bitmap_info_size(src_info,usage), image_size );
}
return ret;
}
/****************************************************************************** /******************************************************************************
* GetDIBits [GDI32.@] * GetDIBits [GDI32.@]
......
...@@ -230,6 +230,7 @@ extern DWORD stretch_bits( const BITMAPINFO *src_info, struct bitblt_coords *src ...@@ -230,6 +230,7 @@ extern DWORD stretch_bits( const BITMAPINFO *src_info, struct bitblt_coords *src
/* bitmap.c */ /* bitmap.c */
extern void get_ddb_bitmapinfo( BITMAPOBJ *bmp, BITMAPINFO *info ) DECLSPEC_HIDDEN; extern void get_ddb_bitmapinfo( BITMAPOBJ *bmp, BITMAPINFO *info ) DECLSPEC_HIDDEN;
extern BITMAPINFO *copy_packed_dib( const BITMAPINFO *src_info, UINT usage ) DECLSPEC_HIDDEN;
extern BOOL get_bitmap_image( HBITMAP hbitmap, BITMAPINFO *info, struct gdi_image_bits *bits ) DECLSPEC_HIDDEN; extern BOOL get_bitmap_image( HBITMAP hbitmap, BITMAPINFO *info, struct gdi_image_bits *bits ) DECLSPEC_HIDDEN;
extern HBITMAP BITMAP_CopyBitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN; extern HBITMAP BITMAP_CopyBitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN;
extern BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, PHYSDEV physdev ) DECLSPEC_HIDDEN; extern BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, PHYSDEV physdev ) DECLSPEC_HIDDEN;
......
...@@ -192,6 +192,16 @@ static void test_pattern_brush(void) ...@@ -192,6 +192,16 @@ static void test_pattern_brush(void)
ret = GlobalFlags( mem ); ret = GlobalFlags( mem );
ok( ret == 2, "wrong flags %x\n", ret ); ok( ret == 2, "wrong flags %x\n", ret );
info->bmiHeader.biBitCount = 8;
info->bmiHeader.biCompression = BI_RLE8;
brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );
info->bmiHeader.biBitCount = 4;
info->bmiHeader.biCompression = BI_RLE4;
brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );
br.lbStyle = BS_DIBPATTERN8X8; br.lbStyle = BS_DIBPATTERN8X8;
br.lbColor = DIB_RGB_COLORS; br.lbColor = DIB_RGB_COLORS;
br.lbHatch = (ULONG_PTR)mem; br.lbHatch = (ULONG_PTR)mem;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment