src: process pending language data when we are going to pass buffer size.

We were experiencing segmentation fault when processing long texts
because we were ending up trying to access out-of-range data (from
codePointBuffer). Verify when this will happen and process data to reset
the index before adding more code points.
This commit is contained in:
Jehan 2022-12-13 23:28:40 +01:00
parent b5b75b81ce
commit baeefc0958

View File

@ -327,8 +327,19 @@ nsProbingState nsMBCSGroupProber::HandleData(const char* aBuf, PRUint32 aLen,
else else
{ {
for (PRUint32 i = 0; i < NUM_OF_PROBERS; i++) for (PRUint32 i = 0; i < NUM_OF_PROBERS; i++)
{
if (codePointBuffer[i]) if (codePointBuffer[i])
{
if (codePointBufferIdx[i] == codePointBufferSize[i] - 1)
{
for (PRUint32 j = 0; j < NUM_OF_LANGUAGES; j++)
langDetectors[i][j]->HandleData(codePointBuffer[i], codePointBufferIdx[i]);
codePointBufferIdx[i] = 0;
}
codePointBuffer[i][(codePointBufferIdx[i])++] = aBuf[pos]; codePointBuffer[i][(codePointBufferIdx[i])++] = aBuf[pos];
}
}
} }
} }