Commit 05f15c88 authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Avoid access past end of classification

Although unlikely, it's possible that AutocompleteMatch::
InlineTailPrefix() could access past the end of its classification.
Check for this and avoid it. Also adds unit test.

Bug: 1013103
Change-Id: Iccb23643c06ca952567a99bfa7cbe7cdeb335d3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869117Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Kevin Bailey <krb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707554}
parent 64827569
......@@ -1078,8 +1078,9 @@ void AutocompleteMatch::InlineTailPrefix(const base::string16& common_prefix) {
contents = ellipsis + contents;
// If the first class is not already NONE, prepend a NONE class for the new
// ellipsis.
if (contents_class[0].offset == 0 &&
contents_class[0].style != ACMatchClassification::NONE) {
if (contents_class.empty() ||
(contents_class[0].offset == 0 &&
contents_class[0].style != ACMatchClassification::NONE)) {
contents_class.insert(contents_class.begin(),
{0, ACMatchClassification::NONE});
}
......
......@@ -137,6 +137,11 @@ TEST(AutocompleteMatchTest, InlineTailPrefix) {
// should prepend ellipsis, and offset remainder
{{0, ACMatchClassification::NONE}, {2, ACMatchClassification::MATCH}},
{{0, ACMatchClassification::NONE}, {6, ACMatchClassification::MATCH}}},
{"90123456",
"... 90123456",
// should prepend ellipsis
{},
{{0, ACMatchClassification::NONE}}},
};
for (const auto& test_case : cases) {
AutocompleteMatch match;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment