aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2018-10-04 16:23:36 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2018-10-04 16:23:36 +1000
commit8cefe7a5183c83040782b5d3611d2f0ca4037b29 (patch)
tree0ac7372a08d19743cec1729f4a8f22c3a944b15d /cocoa
parenta46572b4a243173c9152ccb1252ad46b5d2179ea (diff)
downloadscintilla-mirror-8cefe7a5183c83040782b5d3611d2f0ca4037b29.tar.gz
Fix crash when particular patterns of invalid UTF-8 led to failure to create a
CFStringRef. Performs more stringent validation on input text.
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/PlatCocoa.mm5
1 files changed, 4 insertions, 1 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 4789f7528..a74c805a4 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -164,13 +164,15 @@ public:
ScreenLineLayout::ScreenLineLayout(const IScreenLine *screenLine) : text(screenLine->Text()) {
const UInt8 *puiBuffer = reinterpret_cast<const UInt8 *>(text.data());
+ std::string_view sv = text;
// Start with an empty mutable attributed string and add each character to it.
CFMutableAttributedStringRef mas = CFAttributedStringCreateMutable(NULL, 0);
for (size_t bp=0; bp<text.length();) {
const unsigned char uch = text[bp];
- const unsigned int byteCount = UTF8BytesOfLead[uch];
+ const int utf8Status = UTF8Classify(sv);
+ const unsigned int byteCount = utf8Status & UTF8MaskWidth;
XYPOSITION repWidth = screenLine->RepresentationWidth(bp);
if (uch == '\t') {
// Find the size up to the tab
@@ -207,6 +209,7 @@ ScreenLineLayout::ScreenLineLayout(const IScreenLine *screenLine) : text(screenL
CFRangeMake(CFAttributedStringGetLength(mas), 0),
as);
bp += byteCount;
+ sv.remove_prefix(byteCount);
CFRelease(as);
}