diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-03-04 20:41:02 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-03-04 23:05:11 +0100 |
commit | be4f7ea3f6c8bddba3ca1ae3d9d9e67449bbc3cb (patch) | |
tree | 6ef1cb20dff6cb70cd2adc635c66d45024043d8c | |
parent | 0b2637dda47690da69f748119081151f41fe4133 (diff) |
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
-rw-r--r-- | include/svtools/transfer.hxx | 10 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun5.cxx | 7 | ||||
-rw-r--r-- | svtools/source/misc/transfer.cxx | 6 | ||||
-rw-r--r-- | sw/source/ui/dochdl/swdtflvr.cxx | 7 |
4 files changed, 25 insertions, 5 deletions
diff --git a/include/svtools/transfer.hxx b/include/svtools/transfer.hxx index 8980e88303f2..969312bc2f38 100644 --- a/include/svtools/transfer.hxx +++ b/include/svtools/transfer.hxx @@ -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 ); diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx index 3a4457931590..c4107ffc6ad4 100644 --- a/sc/source/ui/view/viewfun5.cxx +++ b/sc/source/ui/view/viewfun5.cxx @@ -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 ) diff --git a/svtools/source/misc/transfer.cxx b/svtools/source/misc/transfer.cxx index a7b63547c57f..def8b3d54ae0 100644 --- a/svtools/source/misc/transfer.cxx +++ b/svtools/source/misc/transfer.cxx @@ -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); } diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx index 085115cdf1fd..9d4acca9e51c 100644 --- a/sw/source/ui/dochdl/swdtflvr.cxx +++ b/sw/source/ui/dochdl/swdtflvr.cxx @@ -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 ) |