diff options
author | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 09:22:59 +0000 |
---|---|---|
committer | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 09:22:59 +0000 |
commit | 9b82807d71e39011893718429aceabd9df5055b0 (patch) | |
tree | 4b29e98975c3511cb58eca5637fff80c03b4c1c3 /chrome/renderer/spellchecker | |
parent | 4cf04bb7b4082903880aaa85d4a7d63803fa36d5 (diff) | |
download | chromium_src-9b82807d71e39011893718429aceabd9df5055b0.zip chromium_src-9b82807d71e39011893718429aceabd9df5055b0.tar.gz chromium_src-9b82807d71e39011893718429aceabd9df5055b0.tar.bz2 |
Handle null char in the middle of text in custom spellcheck dictionary engine
The code in custom spellcheck dictionary erroneously assumes that null char
terminates the string. Other code does not make this assumption, however, and
passes misspelling offsets to custom spellcheck dictionary that are past the
position of the null char. This causes an exception. The fix is to not use the
null char as string terminator in custom spellcheck dictionary engine. This is
accomplished by switching from a string16(char16* buffer) to a string16(char*
buffer, int length) constructor.
TEST=CustomDictionaryTest.HandleNullCharacters
BUG=258550
Review URL: https://chromiumcodereview.appspot.com/18497015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker')
-rw-r--r-- | chrome/renderer/spellchecker/custom_dictionary_engine.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc | 5 |
2 files changed, 8 insertions, 7 deletions
diff --git a/chrome/renderer/spellchecker/custom_dictionary_engine.cc b/chrome/renderer/spellchecker/custom_dictionary_engine.cc index a6dca91..e289172 100644 --- a/chrome/renderer/spellchecker/custom_dictionary_engine.cc +++ b/chrome/renderer/spellchecker/custom_dictionary_engine.cc @@ -45,14 +45,10 @@ bool CustomDictionaryEngine::SpellCheckWord( int misspelling_start, int misspelling_len) { DCHECK(text); - string16 text16(text); - // The text to be checked is empty on OSX(async) right now. // TODO(groby): Fix as part of async hook-up. (http://crbug.com/178241) - if (text16.empty()) - return false; - DCHECK(text16.length() >= size_t(misspelling_start + misspelling_len)); - return misspelling_start >= 0 && + return + misspelling_start >= 0 && misspelling_len > 0 && - dictionary_.count(text16.substr(misspelling_start, misspelling_len)) > 0; + dictionary_.count(string16(text + misspelling_start, misspelling_len)); } diff --git a/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc b/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc index 3a6ea8a..1420463 100644 --- a/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc +++ b/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc @@ -21,3 +21,8 @@ TEST(CustomDictionaryTest, Basic) { engine.Init(custom_words); EXPECT_TRUE(engine.SpellCheckWord(ASCIIToUTF16("helllo").c_str(), 0, 6)); } + +TEST(CustomDictionaryTest, HandleNullCharacters) { + char16 data[4] = {'a', 0, 'b', 'c'}; + EXPECT_FALSE(CustomDictionaryEngine().SpellCheckWord(data, 1, 1)); +} |