Kaydet (Commit) 6d4f97b0 authored tarafından Caolán McNamara's avatar Caolán McNamara

limit access to dx array to min of input len and len of array

i.e. the sal_Int32 nDXLen = std::min<sal_Int32>(nLen, aOldDX.size()); line
and its usage

Change-Id: Ib0100d2de210a45b340c3a7de6c6dcf2a07443d0
üst bc397ac8
...@@ -1425,7 +1425,7 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1425,7 +1425,7 @@ bool EnhWMFReader::ReadEnhWMF()
sal_Int32 nLeft, nTop, nRight, nBottom, ptlReferenceX, ptlReferenceY, nGfxMode, nXScale, nYScale; sal_Int32 nLeft, nTop, nRight, nBottom, ptlReferenceX, ptlReferenceY, nGfxMode, nXScale, nYScale;
sal_uInt32 nCurPos, nOffString, nOptions, offDx; sal_uInt32 nCurPos, nOffString, nOptions, offDx;
sal_Int32 nLen; sal_Int32 nLen;
long* pDX = NULL; std::vector<long> aDX;
nCurPos = pWMF->Tell() - 8; nCurPos = pWMF->Tell() - 8;
...@@ -1451,13 +1451,12 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1451,13 +1451,12 @@ bool EnhWMFReader::ReadEnhWMF()
pWMF->Seek( nCurPos + offDx ); pWMF->Seek( nCurPos + offDx );
if ( ( nLen * sizeof(sal_uInt32) ) <= ( nEndPos - pWMF->Tell() ) ) if ( ( nLen * sizeof(sal_uInt32) ) <= ( nEndPos - pWMF->Tell() ) )
{ {
pDX = new long[ nLen ]; aDX.resize(nLen);
sal_Int32 i; for (sal_Int32 i = 0; i < nLen; ++i)
sal_Int32 val;
for ( i = 0; i < nLen; i++ )
{ {
pWMF->ReadInt32( val ); sal_Int32 val(0);
pDX[ i ] = val; pWMF->ReadInt32(val);
aDX[i] = val;
} }
} }
} }
...@@ -1469,23 +1468,22 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1469,23 +1468,22 @@ bool EnhWMFReader::ReadEnhWMF()
{ {
std::unique_ptr<sal_Char[]> pBuf(new sal_Char[ nLen ]); std::unique_ptr<sal_Char[]> pBuf(new sal_Char[ nLen ]);
pWMF->Read( pBuf.get(), nLen ); pWMF->Read( pBuf.get(), nLen );
aText = OUString( pBuf.get(), (sal_uInt16)nLen, pOut->GetCharSet() ); aText = OUString(pBuf.get(), nLen, pOut->GetCharSet());
pBuf.reset(); pBuf.reset();
if ( aText.getLength() != nLen ) if ( aText.getLength() != nLen )
{ {
sal_uInt16 i, j; std::vector<long> aOldDX(aText.getLength());
long* pOldDx = pDX; aOldDX.swap(aDX);
pDX = new long[ aText.getLength() ]; sal_Int32 nDXLen = std::min<sal_Int32>(nLen, aOldDX.size());
for ( i = 0, j = 0; i < aText.getLength(); i++ ) for (sal_Int32 i = 0, j = 0; i < aText.getLength(); ++i)
{ {
sal_Unicode cUniChar = aText[i]; sal_Unicode cUniChar = aText[i];
OString aCharacter(&cUniChar, 1, pOut->GetCharSet()); OString aCharacter(&cUniChar, 1, pOut->GetCharSet());
pDX[ i ] = 0; aDX[i] = 0;
for (sal_Int32 k = 0; ( k < aCharacter.getLength() ) && ( j < nLen ) && ( i < aText.getLength() ); ++k) for (sal_Int32 k = 0; ( k < aCharacter.getLength() ) && ( j < nDXLen ) && ( i < aText.getLength() ); ++k)
pDX[ i ] += pOldDx[ j++ ]; aDX[ i ] += aOldDX[j++];
} }
delete[] pOldDx;
} }
} }
} }
...@@ -1507,9 +1505,8 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1507,9 +1505,8 @@ bool EnhWMFReader::ReadEnhWMF()
aText = OUString(pBuf.get(), nLen); aText = OUString(pBuf.get(), nLen);
} }
} }
pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode ); pOut->DrawText(aPos, aText, aDX.data(), bRecordPath, nGfxMode);
} }
delete[] pDX;
} }
break; break;
......
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