Skip to content

Commit

Permalink
fix potential character truncation inside SafeSegment().
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Feb 25, 2025
1 parent de5c52f commit a299130
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scintilla/src/Document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,14 @@ size_t Document::SafeSegment(const char *text, size_t lengthSegment, EncodingFam
if (ccPrev >= CharacterClass::punctuation && encodingFamily != EncodingFamily::eightBit) {
// for UTF-8 go back two code points to detect grapheme cluster boundary.
lastPunctuationBreak = DiscardLastCombinedCharacter(text, lastPunctuationBreak, lastPunctuationBreak + UTF8MaxBytes);
if (lastPunctuationBreak == lengthSegment) {
// discard trail bytes in last truncated character around lengthEachSubdivision
it = text + lengthSegment;
while (UTF8IsTrailByte(*it)) {
--it;
}
lastPunctuationBreak = it - text;
}
}
return lastPunctuationBreak;
}
Expand Down

0 comments on commit a299130

Please sign in to comment.