Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2691163003: Fix handling of malformed surrogate pairs for break-all (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/TextRunConstructor.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/LayoutText.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutText.cpp b/third_party/WebKit/Source/core/layout/LayoutText.cpp
index 3f4d6a8f309e0e4d0f095ced53f3f17713755d5c..12415aa3be29ac9034085cf500fd898259b0232c 100644
--- a/third_party/WebKit/Source/core/layout/LayoutText.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutText.cpp
@@ -24,6 +24,7 @@
#include "core/layout/LayoutText.h"
+#include <algorithm>
#include "core/dom/AXObjectCache.h"
#include "core/dom/Text.h"
#include "core/editing/VisiblePosition.h"
@@ -1013,6 +1014,13 @@ static float minWordFragmentWidthForBreakAll(LayoutText* layoutText,
} else {
fragmentLength = U16_LENGTH(layoutText->codepointAt(i));
}
+
+ // Ensure that malformed surrogate pairs don't cause us to read
+ // past the end of the string.
+ int textLength = layoutText->textLength();
+ if (i + fragmentLength > textLength)
+ fragmentLength = std::max(textLength - i, 0);
+
// The correct behavior is to measure width without re-shaping, but we
// reshape each fragment here because a) the current line breaker does not
// support it, b) getCharacterRange() can reshape if the text is too long
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/TextRunConstructor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698