summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-03-31 09:54:15 +0100
committerCaolán McNamara <caolanm@redhat.com>2021-04-05 15:26:42 +0200
commitb356facc76ae31f82d2d0a68af152680cc003929 (patch)
treeac21f2ecfed401b39270461c641da0bc67690fb7
parent995b3186fa2126d1b299052a90a75cf32d5bfa26 (diff)
cid#1474256 silence Untrusted loop bound
Change-Id: Ibcd59331f16f348209e9b043694cd721a94210c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113575 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/source/filter/excel/xistream.cxx14
1 files changed, 8 insertions, 6 deletions
diff --git a/sc/source/filter/excel/xistream.cxx b/sc/source/filter/excel/xistream.cxx
index e1126aaf2950..df5500cc376d 100644
--- a/sc/source/filter/excel/xistream.cxx
+++ b/sc/source/filter/excel/xistream.cxx
@@ -746,19 +746,21 @@ std::size_t XclImpStream::Read( void* pData, std::size_t nBytes )
std::size_t XclImpStream::CopyToStream( SvStream& rOutStrm, std::size_t nBytes )
{
std::size_t nRet = 0;
- if( mbValid && (nBytes > 0) )
+ if (mbValid && nBytes)
{
const std::size_t nMaxBuffer = 4096;
- std::unique_ptr<sal_uInt8[]> pnBuffer(new sal_uInt8[ ::std::min( nBytes, nMaxBuffer ) ]);
+ std::vector<sal_uInt8> aBuffer(o3tl::sanitizing_min(nBytes, nMaxBuffer));
std::size_t nBytesLeft = nBytes;
- while( mbValid && (nBytesLeft > 0) )
+ while (mbValid)
{
- std::size_t nReadSize = ::std::min( nBytesLeft, nMaxBuffer );
- nRet += Read( pnBuffer.get(), nReadSize );
+ if (!nBytesLeft)
+ break;
+ std::size_t nReadSize = o3tl::sanitizing_min(nBytesLeft, nMaxBuffer);
+ nRet += Read(aBuffer.data(), nReadSize);
// writing more bytes than read results in invalid memory access
SAL_WARN_IF(nRet != nReadSize, "sc", "read less bytes than requested");
- rOutStrm.WriteBytes(pnBuffer.get(), nReadSize);
+ rOutStrm.WriteBytes(aBuffer.data(), nReadSize);
nBytesLeft -= nReadSize;
}
}