Skip to content

Commit

Permalink
Bug 1777394 - Do not crash on inaccessible dictionary file. r=bholley
Browse files Browse the repository at this point in the history
  • Loading branch information
jensstutte committed Sep 5, 2022
1 parent 2fc7fb7 commit 404c76c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions extensions/spellcheck/hunspell/glue/RLBoxHunspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions extensions/spellcheck/hunspell/glue/mozHunspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 404c76c

Please sign in to comment.