From baeefc095809d87b3d2a45007c3e78e4da74f770 Mon Sep 17 00:00:00 2001 From: Jehan Date: Tue, 13 Dec 2022 23:28:40 +0100 Subject: [PATCH] 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. --- src/nsMBCSGroupProber.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nsMBCSGroupProber.cpp b/src/nsMBCSGroupProber.cpp index 8388832..8318cbd 100644 --- a/src/nsMBCSGroupProber.cpp +++ b/src/nsMBCSGroupProber.cpp @@ -327,8 +327,19 @@ nsProbingState nsMBCSGroupProber::HandleData(const char* aBuf, PRUint32 aLen, else { for (PRUint32 i = 0; i < NUM_OF_PROBERS; 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]; + } + } } }