зеркало из https://github.com/mozilla/gecko-dev.git
Bug 488854 - In HTML5 parser Insert REPLACEMENT CHARACTER gracefully when Unicode converter returns failure
This commit is contained in:
Родитель
f6e5e19ce1
Коммит
7aa8302d18
|
@ -1133,6 +1133,8 @@ nsHtml5Parser::WriteStreamBytes(const PRUint8* aFromSegment,
|
||||||
PRInt32 byteCount = aCount - totalByteCount;
|
PRInt32 byteCount = aCount - totalByteCount;
|
||||||
PRInt32 utf16Count = NS_HTML5_PARSER_READ_BUFFER_SIZE - end;
|
PRInt32 utf16Count = NS_HTML5_PARSER_READ_BUFFER_SIZE - end;
|
||||||
|
|
||||||
|
NS_ASSERTION(utf16Count, "Trying to convert into a buffer with no free space!");
|
||||||
|
|
||||||
nsresult convResult = mUnicodeDecoder->Convert((const char*)aFromSegment, &byteCount, mLastBuffer->getBuffer() + end, &utf16Count);
|
nsresult convResult = mUnicodeDecoder->Convert((const char*)aFromSegment, &byteCount, mLastBuffer->getBuffer() + end, &utf16Count);
|
||||||
|
|
||||||
mLastBuffer->setEnd(end + utf16Count);
|
mLastBuffer->setEnd(end + utf16Count);
|
||||||
|
@ -1141,9 +1143,22 @@ nsHtml5Parser::WriteStreamBytes(const PRUint8* aFromSegment,
|
||||||
|
|
||||||
NS_ASSERTION((mLastBuffer->getEnd() <= NS_HTML5_PARSER_READ_BUFFER_SIZE), "The Unicode decoder wrote too much data.");
|
NS_ASSERTION((mLastBuffer->getEnd() <= NS_HTML5_PARSER_READ_BUFFER_SIZE), "The Unicode decoder wrote too much data.");
|
||||||
|
|
||||||
if (convResult == NS_PARTIAL_MORE_OUTPUT) {
|
if (NS_FAILED(convResult)) {
|
||||||
|
++totalByteCount;
|
||||||
|
++aFromSegment;
|
||||||
|
mLastBuffer->getBuffer()[end] = 0xFFFD;
|
||||||
|
mLastBuffer->setEnd(end + 1);
|
||||||
|
if (mLastBuffer->getEnd() == NS_HTML5_PARSER_READ_BUFFER_SIZE) {
|
||||||
mLastBuffer = (mLastBuffer->next = new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE));
|
mLastBuffer = (mLastBuffer->next = new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE));
|
||||||
NS_ASSERTION(((PRUint32)totalByteCount < aCount), "The Unicode has consumed too many bytes.");
|
}
|
||||||
|
mUnicodeDecoder->Reset();
|
||||||
|
if (totalByteCount == aCount) {
|
||||||
|
*aWriteCount = totalByteCount;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
} else if (convResult == NS_PARTIAL_MORE_OUTPUT) {
|
||||||
|
mLastBuffer = (mLastBuffer->next = new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE));
|
||||||
|
NS_ASSERTION(((PRUint32)totalByteCount < aCount), "The Unicode decoder has consumed too many bytes.");
|
||||||
} else {
|
} else {
|
||||||
NS_ASSERTION(((PRUint32)totalByteCount == aCount), "The Unicode decoder consumed the wrong number of bytes.");
|
NS_ASSERTION(((PRUint32)totalByteCount == aCount), "The Unicode decoder consumed the wrong number of bytes.");
|
||||||
*aWriteCount = totalByteCount;
|
*aWriteCount = totalByteCount;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче