Kaydet (Commit) a62507eb authored tarafından Mohammed Abdul Azeem's avatar Mohammed Abdul Azeem

tdf#108821 - fix for overflow of variables on opening huge files

This should fix the issue, as well as restrict available
to return only non-negative values.

Change-Id: I198e226e945b9bd79dec32b1686c20e2a8dfaf3e
Reviewed-on: https://gerrit.libreoffice.org/39665Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 11652be4
......@@ -145,7 +145,7 @@ sal_Int32 SAL_CALL XBufferedThreadedStream::readBytes( Sequence< sal_Int8 >& rDa
if( !hasBytes() )
return 0;
const sal_Int32 nAvailableSize = std::min<sal_Int32>( nBytesToRead, remainingSize() );
const sal_Int32 nAvailableSize = static_cast< sal_Int32 > ( std::min< sal_Int64 >( nBytesToRead, remainingSize() ) );
rData.realloc( nAvailableSize );
sal_Int32 i = 0, nPendingBytes = nAvailableSize;
......@@ -188,7 +188,7 @@ sal_Int32 SAL_CALL XBufferedThreadedStream::available()
if( !hasBytes() )
return 0;
return remainingSize();
return static_cast< sal_Int32 > ( std::min< sal_Int64 >( SAL_MAX_INT32, remainingSize() ) );
}
void SAL_CALL XBufferedThreadedStream::closeInput()
......
......@@ -44,7 +44,7 @@ private:
static const size_t nBufferSize = 32 * 1024;
const Buffer& getNextBlock();
size_t remainingSize() const { return mnStreamSize - mnPos; }
sal_Int64 remainingSize() const { return mnStreamSize - mnPos; }
bool hasBytes() const { return mnPos < mnStreamSize; }
bool canProduce() const
......
......@@ -310,7 +310,7 @@ void SAL_CALL XUnbufferedStream::skipBytes( sal_Int32 nBytesToSkip )
sal_Int32 SAL_CALL XUnbufferedStream::available( )
{
//available size must include the prepended header in case of wrapped raw stream
return static_cast < sal_Int32 > ( mnZipSize + mnHeaderToRead - mnMyCurrent );
return static_cast< sal_Int32 > ( std::min< sal_Int64 >( SAL_MAX_INT32, (mnZipSize + mnHeaderToRead - mnMyCurrent) ) );
}
void SAL_CALL XUnbufferedStream::closeInput( )
......
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