Commit 36e72761 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Added sanity checks on EMRCREATEDIBPATTERNBRUSHPT values.

Fix a memory leak.
parent 15c519a1
...@@ -1148,11 +1148,27 @@ BOOL WINAPI PlayEnhMetaFileRecord( ...@@ -1148,11 +1148,27 @@ BOOL WINAPI PlayEnhMetaFileRecord(
case EMR_CREATEDIBPATTERNBRUSHPT: case EMR_CREATEDIBPATTERNBRUSHPT:
{ {
PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr; PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
LPVOID lpPackedStruct;
/* check that offsets and data are contained within the record */
if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
(lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
{
ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
break;
}
/* This is a BITMAPINFO struct followed directly by bitmap bits */ /* This is a BITMAPINFO struct followed directly by bitmap bits */
LPVOID lpPackedStruct = HeapAlloc( GetProcessHeap(), lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
0, lpCreate->cbBmi + lpCreate->cbBits );
lpCreate->cbBmi + lpCreate->cbBits ); if(!lpPackedStruct)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
break;
}
/* Now pack this structure */ /* Now pack this structure */
memcpy( lpPackedStruct, memcpy( lpPackedStruct,
((BYTE*)lpCreate) + lpCreate->offBmi, ((BYTE*)lpCreate) + lpCreate->offBmi,
...@@ -1165,6 +1181,8 @@ BOOL WINAPI PlayEnhMetaFileRecord( ...@@ -1165,6 +1181,8 @@ BOOL WINAPI PlayEnhMetaFileRecord(
CreateDIBPatternBrushPt( lpPackedStruct, CreateDIBPatternBrushPt( lpPackedStruct,
(UINT)lpCreate->iUsage ); (UINT)lpCreate->iUsage );
HeapFree(GetProcessHeap(), 0, lpPackedStruct);
break; break;
} }
......
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