Kaydet (Commit) ae92c740 authored tarafından Caolán McNamara's avatar Caolán McNamara Kaydeden (comit) Andras Timar

clip strings to max available size

Change-Id: Icc1378c9c27b9b6d229bcffc6a63017f82be70d4
(cherry picked from commit 580d3837)
Reviewed-on: https://gerrit.libreoffice.org/18100Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst dd31bd14
...@@ -73,7 +73,7 @@ static sal_Int32 lcl_getMaxSafeStrLen(sal_uInt32 nSize) ...@@ -73,7 +73,7 @@ static sal_Int32 lcl_getMaxSafeStrLen(sal_uInt32 nSize)
bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign )
{ {
sal_uInt32 i, nItemSize, nType, nItemPos; sal_uInt32 nType, nItemPos;
bool bRetValue = false; bool bRetValue = false;
nItemPos = Tell(); nItemPos = Tell();
...@@ -86,8 +86,8 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) ...@@ -86,8 +86,8 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign )
else else
nType = nStringType & VT_TYPEMASK; nType = nStringType & VT_TYPEMASK;
nItemSize = 0; // Initialize in case stream fails. sal_uInt32 nItemSize(0); // Initialize in case stream fails.
ReadUInt32( nItemSize ); ReadUInt32(nItemSize);
switch( nType ) switch( nType )
{ {
...@@ -95,6 +95,12 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) ...@@ -95,6 +95,12 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign )
{ {
if ( nItemSize ) if ( nItemSize )
{ {
auto nMaxSizePossible = remainingSize();
if (nItemSize > nMaxSizePossible)
{
SAL_WARN("sd.filter", "String of Len " << nItemSize << " claimed, only " << nMaxSizePossible << " possible");
nItemSize = nMaxSizePossible;
}
try try
{ {
sal_Char* pString = new sal_Char[ nItemSize ]; sal_Char* pString = new sal_Char[ nItemSize ];
...@@ -104,7 +110,7 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) ...@@ -104,7 +110,7 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign )
if ( nItemSize > 1 ) if ( nItemSize > 1 )
{ {
sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString); sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString);
for ( i = 0; i < nItemSize; i++ ) for (sal_uInt32 i = 0; i < nItemSize; ++i)
ReadUInt16( pWString[ i ] ); ReadUInt16( pWString[ i ] );
rString = OUString(pWString, lcl_getMaxSafeStrLen(nItemSize)); rString = OUString(pWString, lcl_getMaxSafeStrLen(nItemSize));
} }
...@@ -140,12 +146,19 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) ...@@ -140,12 +146,19 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign )
{ {
if ( nItemSize ) if ( nItemSize )
{ {
auto nMaxSizePossible = remainingSize() / sizeof(sal_Unicode);
if (nItemSize > nMaxSizePossible)
{
SAL_WARN("sd.filter", "String of Len " << nItemSize << " claimed, only " << nMaxSizePossible << " possible");
nItemSize = nMaxSizePossible;
}
try try
{ {
sal_Unicode* pString = new sal_Unicode[ nItemSize ]; sal_Unicode* pString = new sal_Unicode[ nItemSize ];
for ( i = 0; i < nItemSize; i++ ) for (sal_uInt32 i = 0; i < nItemSize; ++i)
ReadUInt16( pString[ i ] ); ReadUInt16( pString[ i ] );
if ( pString[ i - 1 ] == 0 ) if ( pString[ nItemSize - 1 ] == 0 )
{ {
if ( (sal_uInt16)nItemSize > 1 ) if ( (sal_uInt16)nItemSize > 1 )
rString = OUString(pString, lcl_getMaxSafeStrLen(nItemSize)); rString = OUString(pString, lcl_getMaxSafeStrLen(nItemSize));
......
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