From 5b6fcbf4a754a2699b3b865256848238f93113a2 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 8 Sep 2021 20:29:41 +0100 Subject: ofz: MemorySanitizer: use-of-uninitialized-value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sidestep the resize behaviour of SvMemoryStream by using an honest std::vector and make it use that buffer Change-Id: Ic5e405010ac076fc04e1ca8dc6dbb495162101ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121832 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- emfio/inc/wmfreader.hxx | 2 +- emfio/source/reader/wmfreader.cxx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'emfio') diff --git a/emfio/inc/wmfreader.hxx b/emfio/inc/wmfreader.hxx index a7dff2b94d85..f7788d53651c 100644 --- a/emfio/inc/wmfreader.hxx +++ b/emfio/inc/wmfreader.hxx @@ -35,7 +35,7 @@ namespace emfio sal_uInt32 mnRecSize; // embedded EMF data - std::unique_ptr mpEMFStream; + std::optional> mpEMFStream; // total number of comment records containing EMF data sal_uInt32 mnEMFRecCount; diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index a32c7f100e04..d71dbf485710 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -1315,7 +1315,7 @@ namespace emfio mpEMFStream.reset(); } else - mpEMFStream = std::make_unique(mnEMFSize, 0); + mpEMFStream = std::vector(); } else if( (mnEMFRecCount != nComRecCount ) || (mnEMFSize != nEMFTotalSize ) ) // add additional checks here { @@ -1343,7 +1343,9 @@ namespace emfio std::vector aBuf(nCurRecSize); sal_uInt32 nCount = mpInputStream->ReadBytes(aBuf.data(), nCurRecSize); if( nCount == nCurRecSize ) - mpEMFStream->WriteBytes(aBuf.data(), nCount); + { + mpEMFStream->insert(mpEMFStream->end(), aBuf.begin(), aBuf.end()); + } } } } @@ -1594,8 +1596,8 @@ namespace emfio if(mpEMFStream && mnEMFRecCount == mnEMFRec) { GDIMetaFile aMeta; - mpEMFStream->Seek( 0 ); - std::unique_ptr pEMFReader(std::make_unique( *mpEMFStream, aMeta )); + SvMemoryStream aStream(mpEMFStream->data(), mpEMFStream->size(), StreamMode::STD_READ); + std::unique_ptr pEMFReader(std::make_unique(aStream, aMeta)); pEMFReader->SetEnableEMFPlus(mbEnableEMFPlus); bEMFAvailable = pEMFReader->ReadEnhWMF(); pEMFReader.reset(); // destroy first!!! -- cgit