Skip to content

Commit a299130

Browse files
committed
fix potential character truncation inside SafeSegment().
1 parent de5c52f commit a299130

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

scintilla/src/Document.cxx

+8
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,14 @@ size_t Document::SafeSegment(const char *text, size_t lengthSegment, EncodingFam
12301230
if (ccPrev >= CharacterClass::punctuation && encodingFamily != EncodingFamily::eightBit) {
12311231
// for UTF-8 go back two code points to detect grapheme cluster boundary.
12321232
lastPunctuationBreak = DiscardLastCombinedCharacter(text, lastPunctuationBreak, lastPunctuationBreak + UTF8MaxBytes);
1233+
if (lastPunctuationBreak == lengthSegment) {
1234+
// discard trail bytes in last truncated character around lengthEachSubdivision
1235+
it = text + lengthSegment;
1236+
while (UTF8IsTrailByte(*it)) {
1237+
--it;
1238+
}
1239+
lastPunctuationBreak = it - text;
1240+
}
12331241
}
12341242
return lastPunctuationBreak;
12351243
}

0 commit comments

Comments
 (0)