Kaydet (Commit) be4f7ea3 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

OLE preview: Limit the GDI metafile size to 100000 actions.

Excel can copy huge metafiles to the clipboard, with over 3 million of
actions, which are 1) unusable, and 2) crash LibreOffice because of their
size.

So let's just limit the size of metafiles to be under 100000 actions,
otherwise use the 'OLE' bitmap.

Change-Id: I6a50471e6fe6ab9417592c011bf78cad6247236b
üst 0b2637dd
......@@ -321,7 +321,15 @@ public:
sal_Bool GetBitmapEx( SotFormatStringId nFormat, BitmapEx& rBmp );
sal_Bool GetBitmapEx( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, BitmapEx& rBmp );
sal_Bool GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf );
/** Return as GDI metafile.
@param nMaxAction Allows you to limit the amount of actions; defaults to 0 which means no limit.
Whet you eg. Ctrl+a in Excel, you can get the entire sheet as
metafile, with over 3 million (!) actions; which is just too large for
any reasonable handling - and you need to set a limit.
*/
sal_Bool GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf, size_t nMaxActions = 0 );
sal_Bool GetGDIMetaFile( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, GDIMetaFile& rMtf );
sal_Bool GetGraphic( SotFormatStringId nFormat, Graphic& rGraphic );
......
......@@ -181,8 +181,13 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
Graphic aGraphic;
sal_uLong nGrFormat = 0;
if (aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
// limit the size of the preview metafile to 100000 actions
GDIMetaFile aMetafile;
if (aDataHelper.GetGDIMetaFile(FORMAT_GDIMETAFILE, aMetafile, 100000))
{
nGrFormat = SOT_FORMAT_GDIMETAFILE;
aGraphic = aMetafile;
}
// insert replacement image ( if there is one ) into the object helper
if ( nGrFormat )
......
......@@ -1777,10 +1777,12 @@ sal_Bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapE
sal_Bool TransferableDataHelper::GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf )
sal_Bool TransferableDataHelper::GetGDIMetaFile(SotFormatStringId nFormat, GDIMetaFile& rMtf, size_t nMaxActions)
{
DataFlavor aFlavor;
return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGDIMetaFile( aFlavor, rMtf ) );
return SotExchange::GetFormatDataFlavor(nFormat, aFlavor) &&
GetGDIMetaFile(aFlavor, rMtf) &&
(nMaxActions == 0 || rMtf.GetActionSize() < nMaxActions);
}
......
......@@ -1816,8 +1816,13 @@ bool SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
Graphic aGraphic;
sal_uLong nGrFormat = 0;
if( rData.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
// limit the size of the preview metafile to 100000 actions
GDIMetaFile aMetafile;
if (rData.GetGDIMetaFile(FORMAT_GDIMETAFILE, aMetafile, 100000))
{
nGrFormat = SOT_FORMAT_GDIMETAFILE;
aGraphic = aMetafile;
}
// insert replacement image ( if there is one ) into the object helper
if ( nGrFormat )
......
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