From bcdaaf62d41728eb757ff2b9cb95c2df2791e2f4 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 16 Feb 2018 09:20:12 +0000 Subject: Resolves: tdf#115750 SvStream::WriteStream was broken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and didn't stop copying at the size limit arg Change-Id: I8f1be0310160f5158d2f64c62d6b2c09c0157930 Reviewed-on: https://gerrit.libreoffice.org/49838 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- tools/source/stream/stream.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 3a9f767880dd..5d6d3e58336b 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -1186,13 +1186,12 @@ sal_uInt64 SvStream::WriteStream( SvStream& rStream, sal_uInt64 nSize ) sal_uInt32 nCount; sal_uInt64 nWriteSize = nSize; - do { - if ( nSize >= nCurBufLen ) - nWriteSize -= nCurBufLen; - else - nCurBufLen = nWriteSize; - nCount = rStream.ReadBytes( pBuf.get(), nCurBufLen ); + do + { + nCurBufLen = std::min(nCurBufLen, nWriteSize); + nCount = rStream.ReadBytes(pBuf.get(), nCurBufLen); WriteBytes( pBuf.get(), nCount ); + nWriteSize -= nCount; } while( nWriteSize && nCount == nCurBufLen ); -- cgit