diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 849ab1496500..26f3c88a9098 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -866,6 +866,7 @@ private: // on the line, or null if there was no previous leaf frame. nsIFrame* mCommonAncestorWithLastFrame; // mMaxTextLength is an upper bound on the size of the text in all mapped frames + // The value PR_UINT32_MAX represents overflow; text will be discarded PRUint32 mMaxTextLength; PRPackedBool mDoubleByteText; PRPackedBool mBidiEnabled; @@ -1294,8 +1295,11 @@ void BuildTextRunsScanner::FlushFrames(PRBool aFlushLineBreaks, PRBool aSuppress } } else { nsAutoTArray buffer; - if (!buffer.AppendElements(mMaxTextLength*(mDoubleByteText ? 2 : 1))) + PRUint32 bufferSize = mMaxTextLength*(mDoubleByteText ? 2 : 1); + if (bufferSize < mMaxTextLength || bufferSize == PR_UINT32_MAX || + !buffer.AppendElements(bufferSize)) { return; + } textRun = BuildTextRunForFrames(buffer.Elements()); } } @@ -1339,8 +1343,14 @@ void BuildTextRunsScanner::FlushLineBreaks(gfxTextRun* aTrailingTextRun) void BuildTextRunsScanner::AccumulateRunInfo(nsTextFrame* aFrame) { - NS_ASSERTION(mMaxTextLength <= mMaxTextLength + aFrame->GetContentLength(), "integer overflow"); - mMaxTextLength += aFrame->GetContentLength(); + if (mMaxTextLength != PR_UINT32_MAX) { + NS_ASSERTION(mMaxTextLength < PR_UINT32_MAX - aFrame->GetContentLength(), "integer overflow"); + if (mMaxTextLength >= PR_UINT32_MAX - aFrame->GetContentLength()) { + mMaxTextLength = PR_UINT32_MAX; + } else { + mMaxTextLength += aFrame->GetContentLength(); + } + } mDoubleByteText |= aFrame->GetContent()->GetText()->Is2b(); mLastFrame = aFrame; mCommonAncestorWithLastFrame = aFrame->GetParent();