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

fix int wraparound + crash on export of fdo74018-2.docx to doc

nPoints is 16bit and accumulated value wraps around, so use
a 32bit nTotalPoints instead and move 16bit declarations to
use points to confirm no other wraparounds

Change-Id: If97ccb46ed8eb7f4305cdfe328ae83bc2b0c778c
üst a4b11f03
...@@ -2056,42 +2056,43 @@ bool EscherPropertyContainer::CreatePolygonProperties( ...@@ -2056,42 +2056,43 @@ bool EscherPropertyContainer::CreatePolygonProperties(
{ {
Polygon aPolygon; Polygon aPolygon;
sal_uInt16 i, j, k, nPoints, nBezPoints, nPolyCount = aPolyPolygon.Count(); sal_uInt16 nPolyCount = aPolyPolygon.Count();
sal_uInt32 nTotalPoints(0), nTotalBezPoints(0);
Rectangle aRect( aPolyPolygon.GetBoundRect() ); Rectangle aRect( aPolyPolygon.GetBoundRect() );
rGeoRect = ::com::sun::star::awt::Rectangle( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight() ); rGeoRect = ::com::sun::star::awt::Rectangle( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight() );
for ( nBezPoints = nPoints = i = 0; i < nPolyCount; i++ ) for (sal_uInt16 i = 0; i < nPolyCount; ++i)
{ {
k = aPolyPolygon[ i ].GetSize(); sal_uInt16 k = aPolyPolygon[ i ].GetSize();
nPoints = nPoints + k; nTotalPoints += k;
for ( j = 0; j < k; j++ ) for (sal_uInt16 j = 0; j < k; ++j)
{ {
if ( aPolyPolygon[ i ].GetFlags( j ) != POLY_CONTROL ) if ( aPolyPolygon[ i ].GetFlags( j ) != POLY_CONTROL )
nBezPoints++; nTotalBezPoints++;
} }
} }
sal_uInt32 nVerticesBufSize = ( nPoints << 2 ) + 6; sal_uInt32 nVerticesBufSize = ( nTotalPoints << 2 ) + 6;
sal_uInt8* pVerticesBuf = new sal_uInt8[ nVerticesBufSize ]; sal_uInt8* pVerticesBuf = new sal_uInt8[ nVerticesBufSize ];
sal_uInt32 nSegmentBufSize = ( ( nBezPoints << 2 ) + 8 ); sal_uInt32 nSegmentBufSize = ( ( nTotalBezPoints << 2 ) + 8 );
if ( nPolyCount > 1 ) if ( nPolyCount > 1 )
nSegmentBufSize += ( nPolyCount << 1 ); nSegmentBufSize += ( nPolyCount << 1 );
sal_uInt8* pSegmentBuf = new sal_uInt8[ nSegmentBufSize ]; sal_uInt8* pSegmentBuf = new sal_uInt8[ nSegmentBufSize ];
sal_uInt8* pPtr = pVerticesBuf; sal_uInt8* pPtr = pVerticesBuf;
*pPtr++ = (sal_uInt8)( nPoints ); // Little endian *pPtr++ = (sal_uInt8)( nTotalPoints ); // Little endian
*pPtr++ = (sal_uInt8)( nPoints >> 8 ); *pPtr++ = (sal_uInt8)( nTotalPoints >> 8 );
*pPtr++ = (sal_uInt8)( nPoints ); *pPtr++ = (sal_uInt8)( nTotalPoints );
*pPtr++ = (sal_uInt8)( nPoints >> 8 ); *pPtr++ = (sal_uInt8)( nTotalPoints >> 8 );
*pPtr++ = (sal_uInt8)0xf0; *pPtr++ = (sal_uInt8)0xf0;
*pPtr++ = (sal_uInt8)0xff; *pPtr++ = (sal_uInt8)0xff;
for ( j = 0; j < nPolyCount; j++ ) for (sal_uInt16 j = 0; j < nPolyCount; ++j)
{ {
aPolygon = aPolyPolygon[ j ]; aPolygon = aPolyPolygon[ j ];
nPoints = aPolygon.GetSize(); sal_uInt16 nPoints = aPolygon.GetSize();
for ( i = 0; i < nPoints; i++ ) // write points from polygon to buffer for (sal_uInt16 i = 0; i < nPoints; ++i) // write points from polygon to buffer
{ {
Point aPoint = aPolygon[ i ]; Point aPoint = aPolygon[ i ];
aPoint.X() -= rGeoRect.X; aPoint.X() -= rGeoRect.X;
...@@ -2112,13 +2113,13 @@ bool EscherPropertyContainer::CreatePolygonProperties( ...@@ -2112,13 +2113,13 @@ bool EscherPropertyContainer::CreatePolygonProperties(
*pPtr++ = (sal_uInt8)2; *pPtr++ = (sal_uInt8)2;
*pPtr++ = (sal_uInt8)0; *pPtr++ = (sal_uInt8)0;
for ( j = 0; j < nPolyCount; j++ ) for (sal_uInt16 j = 0; j < nPolyCount; ++j)
{ {
*pPtr++ = 0x0; // Polygon start *pPtr++ = 0x0; // Polygon start
*pPtr++ = 0x40; *pPtr++ = 0x40;
aPolygon = aPolyPolygon[ j ]; aPolygon = aPolyPolygon[ j ];
nPoints = aPolygon.GetSize(); sal_uInt16 nPoints = aPolygon.GetSize();
for ( i = 0; i < nPoints; i++ ) // write Polyflags to Buffer for (sal_uInt16 i = 0; i < nPoints; ++i) // write Polyflags to Buffer
{ {
*pPtr++ = 0; *pPtr++ = 0;
if ( bBezier ) if ( bBezier )
......
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