Bug 174351: Encoding errors aren't treated as fatal XML errors. r=smontagu, sr=peterv

This commit is contained in:
Makoto Kato
2009-02-16 04:22:47 -08:00
parent 9e359d0fbe
commit 5cacf362f2
15 changed files with 255 additions and 34 deletions

View File

@@ -49,7 +49,8 @@ nsresult nsUnicodeDecodeHelper::ConvertByTable(
PRInt32 * aDestLength,
uScanClassID aScanClass,
uShiftInTable * aShiftInTable,
uMappingTable * aMappingTable)
uMappingTable * aMappingTable,
PRBool aErrorSignal)
{
const char * src = aSrc;
PRInt32 srcLen = *aSrcLength;
@@ -82,6 +83,10 @@ nsresult nsUnicodeDecodeHelper::ConvertByTable(
// somehow some table miss the 0x00 - 0x20 part
*dest = med;
} else {
if (aErrorSignal) {
res = NS_ERROR_ILLEGAL_INPUT;
break;
}
// Unicode replacement value for unmappable chars
*dest = 0xfffd;
}
@@ -107,7 +112,8 @@ nsresult nsUnicodeDecodeHelper::ConvertByMultiTable(
PRInt32 aTableCount,
const uRange * aRangeArray,
uScanClassID * aScanClassArray,
uMappingTable ** aMappingTable)
uMappingTable ** aMappingTable,
PRBool aErrorSignal)
{
PRUint8 * src = (PRUint8 *)aSrc;
PRInt32 srcLen = *aSrcLength;
@@ -143,7 +149,8 @@ nsresult nsUnicodeDecodeHelper::ConvertByMultiTable(
if(passRangeCheck && (! passScan))
{
res = NS_OK_UDEC_MOREINPUT;
if (res != NS_ERROR_ILLEGAL_INPUT)
res = NS_OK_UDEC_MOREINPUT;
break;
}
if(! done)
@@ -182,7 +189,15 @@ nsresult nsUnicodeDecodeHelper::ConvertByMultiTable(
}
}
// treat it as NSBR if bcr == 1 and it is 0xa0
*dest = ((1==bcr)&&(*src == (PRUint8)0xa0 )) ? 0x00a0 : 0xfffd;
if ((1==bcr)&&(*src == (PRUint8)0xa0 )) {
*dest = 0x00a0;
} else {
if (aErrorSignal) {
res = NS_ERROR_ILLEGAL_INPUT;
break;
}
*dest = 0xfffd;
}
}
}
@@ -204,7 +219,8 @@ nsresult nsUnicodeDecodeHelper::ConvertByFastTable(
PRUnichar * aDest,
PRInt32 * aDestLength,
const PRUnichar * aFastTable,
PRInt32 aTableSize)
PRInt32 aTableSize,
PRBool aErrorSignal)
{
PRUint8 * src = (PRUint8 *)aSrc;
PRUint8 * srcEnd = src;
@@ -219,7 +235,14 @@ nsresult nsUnicodeDecodeHelper::ConvertByFastTable(
res = NS_OK;
}
for (; src<srcEnd;) *dest++ = aFastTable[*src++];
for (; src<srcEnd;) {
*dest = aFastTable[*src++];
if (*dest == 0xfffd && aErrorSignal) {
res = NS_ERROR_ILLEGAL_INPUT;
break;
}
dest++;
}
*aSrcLength = src - (PRUint8 *)aSrc;
*aDestLength = dest - aDest;