bug 607160 - check text length computations. r=roc a=blocking2.0

This commit is contained in:
Jonathan Kew 2010-11-25 15:36:53 +00:00
Родитель 54a163c875
Коммит c9ec94c809
1 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -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<PRUint8,BIG_TEXT_NODE_SIZE> 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();