Bug 1777394 - Do not crash on inaccessible dictionary file. r=bholley

Differential Revision: https://phabricator.services.mozilla.com/D156278
This commit is contained in:
Jens Stutte 2022-09-05 11:29:45 +00:00
Родитель 2fc7fb7998
Коммит 404c76c5d8
2 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -42,13 +42,15 @@ RLBoxHunspell* RLBoxHunspell::Create(const nsCString& affpath,
const uint64_t defaultMaxSizeForSandbox =
wasm_rt_get_default_max_linear_memory_size();
// We first get the size of the dictionary
// We first get the size of the dictionary.
// This is actually the first read we try on dpath and it might fail for
// whatever filesystem reasons (invalid path, unaccessible, ...).
Result<int64_t, nsresult> dictSizeResult =
mozHunspellFileMgrHost::GetSize(dpath);
MOZ_RELEASE_ASSERT(dictSizeResult.isOk());
NS_ENSURE_TRUE(dictSizeResult.isOk(), nullptr);
int64_t dictSize = dictSizeResult.unwrap();
MOZ_RELEASE_ASSERT(dictSize >= 0);
NS_ENSURE_TRUE(dictSize >= 0, nullptr);
// Next, we compute the expected memory needed for hunspell spell checking.
// This will vary based on the size of the dictionary file, which varies by
@ -81,6 +83,7 @@ RLBoxHunspell* RLBoxHunspell::Create(const nsCString& affpath,
mozHunspellCallbacks::AllowFile(dpath);
}
// TODO Bug 1788857: Verify error handling in case of inaccessible file
return new RLBoxHunspell(std::move(sandbox), affpath, dpath);
}

Просмотреть файл

@ -419,6 +419,7 @@ nsresult mozHunspell::DictionaryData::LoadIfNecessary() {
RLBoxHunspell::Create(mAffixFileName, dictFileName));
if (!hunspell) {
mLoadFailed = true;
// TODO Bug 1788857: Verify error propagation in case of inaccessible file
return NS_ERROR_OUT_OF_MEMORY;
}
mHunspell = std::move(hunspell);