diff options
author | Jehan <jehan@girinstud.io> | 2023-07-17 20:09:10 +0200 |
---|---|---|
committer | Jehan <jehan@girinstud.io> | 2023-07-17 20:09:10 +0200 |
commit | ab1d2f1120297af6537f2a0d09dca589d4c3ea3b (patch) | |
tree | 18345db4aebfe39c7d43e3c2e031af18efbf3cf4 | |
parent | 9910941387a4cad0d9f0360df2ccf6721fab8e2d (diff) |
src: handle long sequences of characters.
Actually my previous commit was not handling all cases, though it was
taking care of the buffer overflow triggered by the provided byte
sequence. Yet I believe it was still possible to craft special input
sequences too long for codePointBuffer.
This additional commit would handle these other cases by processing the
input in manageable sub-strings.
-rw-r--r-- | src/nsMBCSGroupProber.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/nsMBCSGroupProber.cpp b/src/nsMBCSGroupProber.cpp index d822a5a..79cacd4 100644 --- a/src/nsMBCSGroupProber.cpp +++ b/src/nsMBCSGroupProber.cpp @@ -310,17 +310,28 @@ nsProbingState nsMBCSGroupProber::HandleData(const char* aBuf, PRUint32 aLen, } if (codePointBuffer[i]) - st = mProbers[i]->HandleData(aBuf + start, sequenceLength, - &(codePointBuffer[i]), &(codePointBufferIdx[i])); + { + while (sequenceLength > 0) + { + int subLength = (sequenceLength > codePointBufferSize[i]) ? codePointBufferSize[i] : sequenceLength; + + st = mProbers[i]->HandleData(aBuf + start, subLength, + &(codePointBuffer[i]), &(codePointBufferIdx[i])); + + if (codePointBufferIdx[i] > 0) + { + for (PRUint32 j = 0; j < NUM_OF_LANGUAGES; j++) + langDetectors[i][j]->HandleData(codePointBuffer[i], codePointBufferIdx[i]); + codePointBufferIdx[i] = 0; + } + + sequenceLength -= subLength; + } + } else - st = mProbers[i]->HandleData(aBuf + start, sequenceLength, NULL, NULL); - - if (codePointBufferIdx[i] > 0 && codePointBuffer[i]) - { - for (PRUint32 j = 0; j < NUM_OF_LANGUAGES; j++) - langDetectors[i][j]->HandleData(codePointBuffer[i], codePointBufferIdx[i]); - codePointBufferIdx[i] = 0; - } + { + st = mProbers[i]->HandleData(aBuf + start, sequenceLength, NULL, NULL); + } if (st == eFoundIt) { |