Commit a952dd38 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

Fix null pointer crash in Windows native spellchecker

CL https://chromium-review.googlesource.com/c/chromium/src/+/1706574
introduced a crash by missing a null check in the case where the OS
fails to construct the native spellchecker object. This CL adds null
checks in 2 places:

1) Where the null pointer was being dereferenced, to future-proof the
   method where the crash was actually happening.
2) In the telemetry code path before attempting to use the native
   spellchecker, since there's no point trying to record native
   spellchecker data if the native spellchecker doesn't exist.

Bug: 987025
Change-Id: I80d289f9299d951a7951a321237a48399587b89a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715600Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Cr-Commit-Position: refs/heads/master@{#680545}
parent 1caf4246
...@@ -399,7 +399,11 @@ void WindowsSpellChecker::IgnoreWordForAllLanguagesInBackgroundThread( ...@@ -399,7 +399,11 @@ void WindowsSpellChecker::IgnoreWordForAllLanguagesInBackgroundThread(
bool WindowsSpellChecker::IsLanguageSupportedInBackgroundThread( bool WindowsSpellChecker::IsLanguageSupportedInBackgroundThread(
const std::string& current_language) { const std::string& current_language) {
DCHECK(!main_task_runner_->BelongsToCurrentThread()); DCHECK(!main_task_runner_->BelongsToCurrentThread());
DCHECK(IsSpellCheckerFactoryInitialized());
if (!IsSpellCheckerFactoryInitialized()) {
// The native spellchecker creation failed; no language is supported.
return false;
}
BOOL is_language_supported = (BOOL) false; BOOL is_language_supported = (BOOL) false;
std::wstring bcp47_language_tag = base::UTF8ToWide(current_language); std::wstring bcp47_language_tag = base::UTF8ToWide(current_language);
...@@ -428,6 +432,12 @@ void WindowsSpellChecker::RecordMissingLanguagePacksCountInBackgroundThread( ...@@ -428,6 +432,12 @@ void WindowsSpellChecker::RecordMissingLanguagePacksCountInBackgroundThread(
SpellCheckHostMetrics* metrics) { SpellCheckHostMetrics* metrics) {
DCHECK(!main_task_runner_->BelongsToCurrentThread()); DCHECK(!main_task_runner_->BelongsToCurrentThread());
DCHECK(metrics); DCHECK(metrics);
if (!IsSpellCheckerFactoryInitialized()) {
// The native spellchecker creation failed. Do not record any metrics.
return;
}
metrics->RecordMissingLanguagePacksCount( metrics->RecordMissingLanguagePacksCount(
std::count_if(spellcheck_locales.begin(), spellcheck_locales.end(), std::count_if(spellcheck_locales.begin(), spellcheck_locales.end(),
[this](const std::string& s) { [this](const std::string& s) {
......
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