Kaydet (Commit) 2dd41042 authored tarafından Luboš Luňák's avatar Luboš Luňák Kaydeden (comit) Xisco Faulí

lazy image loading shouldn't read the entire .xls file (tdf#124828)

b1118883 changed msfilter to use
GraphicFilter::ImportUnloadedGraphic() to lazy-load images
from the document. However, that function in some cases simply
reads the entire rest of the passed SvStream, which in this case
is the entire .xls file. And the document from tdf#124828 is ~50MiB
and contains ~4000 images => 100+ GiB memory required.

Change-Id: I74926383204ec642eabb28b62e2cf2e1ff8054a9
Reviewed-on: https://gerrit.libreoffice.org/71136
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
(cherry picked from commit af84fc9d)
Reviewed-on: https://gerrit.libreoffice.org/71221Reviewed-by: 's avatarXisco Faulí <xiscofauli@libreoffice.org>
üst 771be5a3
...@@ -6553,7 +6553,11 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, tool ...@@ -6553,7 +6553,11 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, tool
else else
{ // and unleash our filter { // and unleash our filter
GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
Graphic aGraphic = rGF.ImportUnloadedGraphic(*pGrStream); // ImportUnloadedGraphic() may simply read the entire rest of the stream,
// which may be very large if the whole document is large. Limit the read
// size to the size of this record.
sal_uInt64 maxSize = pGrStream == &rBLIPStream ? nLength : 0;
Graphic aGraphic = rGF.ImportUnloadedGraphic(*pGrStream, maxSize);
if (aGraphic) if (aGraphic)
{ {
rData = aGraphic; rData = aGraphic;
......
...@@ -294,7 +294,8 @@ public: ...@@ -294,7 +294,8 @@ public:
css::uno::Sequence< css::beans::PropertyValue >* pFilterData, css::uno::Sequence< css::beans::PropertyValue >* pFilterData,
WmfExternal const *pExtHeader = nullptr ); WmfExternal const *pExtHeader = nullptr );
Graphic ImportUnloadedGraphic(SvStream& rIStream); // Setting sizeLimit limits how much will be read from the stream.
Graphic ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 sizeLimit = 0);
const FilterErrorEx& GetLastError() const { return *pErrorEx;} const FilterErrorEx& GetLastError() const { return *pErrorEx;}
void ResetLastError(); void ResetLastError();
......
...@@ -1428,7 +1428,7 @@ void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGra ...@@ -1428,7 +1428,7 @@ void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGra
} }
} }
Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream) Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 sizeLimit)
{ {
Graphic aGraphic; Graphic aGraphic;
sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW; sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
...@@ -1443,7 +1443,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream) ...@@ -1443,7 +1443,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream)
ErrCode nStatus = ImpTestOrFindFormat("", rIStream, nFormat); ErrCode nStatus = ImpTestOrFindFormat("", rIStream, nFormat);
rIStream.Seek(nStreamBegin); rIStream.Seek(nStreamBegin);
const sal_uInt32 nStreamLength(rIStream.remainingSize()); const sal_uInt32 nStreamLength( sizeLimit ? sizeLimit : rIStream.remainingSize());
OUString aFilterName = pConfig->GetImportFilterName(nFormat); OUString aFilterName = pConfig->GetImportFilterName(nFormat);
OUString aExternalFilterName = pConfig->GetExternalFilterName(nFormat, false); OUString aExternalFilterName = pConfig->GetExternalFilterName(nFormat, false);
......
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