summaryrefslogtreecommitdiff
path: root/sot
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-08-29 00:29:35 +0200
committerMichael Stahl <mstahl@redhat.com>2015-08-31 16:37:17 +0200
commit6a223b9acf8571e098cc6f74edcd3060d3fcfe27 (patch)
treef8925169573ccec98414ad64c6daaa6c21bc6a10 /sot
parent0c191e2b757555b147ebab1688e72acde28062a1 (diff)
sot: don't leak uninitialized memory into temp file
Both valgrind and drmemory complain about this in SdExportTest::testSwappedOutImageExport() via SfxOleThumbnailProperty::ImplSave(). Syscall param pwrite64(buf) points to uninitialised byte(s) UNINITIALIZED READ: reading 0x0455b1b4-0x0455b1c8 20 byte(s) within... It appears that the stream writes out everything up to the seek position anyway (otherwise the size check wouldn't work, with sparse files) so make sure it's all zeroed. Also fix SvMemoryStream::ReAllocateMemory() to zero it. Change-Id: Id86dfa65ef6f7d1bba4810f121e01473c5fcf4c7
Diffstat (limited to 'sot')
-rw-r--r--sot/source/sdstor/stgstrms.cxx15
1 files changed, 12 insertions, 3 deletions
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index ecd987fffa2b..c913bebc9e0e 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -1188,9 +1188,9 @@ void StgTmpStrm::SetSize(sal_uInt64 n)
SvFileStream* s = new SvFileStream( aName, STREAM_READWRITE );
sal_uLong nCur = Tell();
sal_uLong i = nEndOfData;
+ std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]);
if( i )
{
- std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]);
Seek( 0L );
while( i )
{
@@ -1207,8 +1207,17 @@ void StgTmpStrm::SetSize(sal_uInt64 n)
// We have to write one byte at the end of the file
// if the file is bigger than the memstream to see
// if it fits on disk
- s->Seek( n - 1 );
- s->Write( &i, 1 );
+ s->Seek(nEndOfData);
+ memset(p.get(), 0x00, 4096);
+ i = n - nEndOfData;
+ while (i)
+ {
+ sal_uLong const nb = (i > 4096) ? 4096 : i;
+ if (s->Write(p.get(), nb) == nb)
+ i -= nb;
+ else
+ break; // error
+ }
s->Flush();
if( s->GetError() != SVSTREAM_OK )
i = 1;