forked from mirrors/gecko-dev
Bug 1861254 - Safely bail out of LocaleAtomFromPath if passed a bad hyphenation-file path. r=layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D192934
This commit is contained in:
parent
95f0e10b39
commit
d523a6de1b
1 changed files with 14 additions and 7 deletions
|
|
@ -203,8 +203,9 @@ void nsHyphenationManager::LoadPatternList() {
|
||||||
// Extract the locale code we'll use to identify a given hyphenation resource
|
// Extract the locale code we'll use to identify a given hyphenation resource
|
||||||
// from the path name as found in omnijar or on disk.
|
// from the path name as found in omnijar or on disk.
|
||||||
static already_AddRefed<nsAtom> LocaleAtomFromPath(const nsCString& aPath) {
|
static already_AddRefed<nsAtom> LocaleAtomFromPath(const nsCString& aPath) {
|
||||||
MOZ_ASSERT(StringEndsWith(aPath, ".hyf"_ns) ||
|
if (!StringEndsWith(aPath, ".hyf"_ns) && !StringEndsWith(aPath, ".dic"_ns)) {
|
||||||
StringEndsWith(aPath, ".dic"_ns));
|
return nullptr;
|
||||||
|
}
|
||||||
nsCString locale(aPath);
|
nsCString locale(aPath);
|
||||||
locale.Truncate(locale.Length() - 4); // strip ".hyf" or ".dic"
|
locale.Truncate(locale.Length() - 4); // strip ".hyf" or ".dic"
|
||||||
locale.Cut(0, locale.RFindChar('/') + 1); // strip directory
|
locale.Cut(0, locale.RFindChar('/') + 1); // strip directory
|
||||||
|
|
@ -212,11 +213,7 @@ static already_AddRefed<nsAtom> LocaleAtomFromPath(const nsCString& aPath) {
|
||||||
if (StringBeginsWith(locale, "hyph_"_ns)) {
|
if (StringBeginsWith(locale, "hyph_"_ns)) {
|
||||||
locale.Cut(0, 5);
|
locale.Cut(0, 5);
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < locale.Length(); ++i) {
|
locale.ReplaceChar('_', '-');
|
||||||
if (locale[i] == '_') {
|
|
||||||
locale.Replace(i, 1, '-');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_Atomize(locale);
|
return NS_Atomize(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,6 +251,9 @@ void nsHyphenationManager::LoadPatternListFromOmnijar(Omnijar::Type aType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(locale);
|
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(locale);
|
||||||
|
if (!localeAtom) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
mPatternFiles.InsertOrUpdate(localeAtom, uri);
|
mPatternFiles.InsertOrUpdate(localeAtom, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -289,6 +289,9 @@ void nsHyphenationManager::LoadPatternListFromDir(nsIFile* aDir) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(path);
|
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(path);
|
||||||
|
if (!localeAtom) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
nsresult rv = NS_NewFileURI(getter_AddRefs(uri), file);
|
nsresult rv = NS_NewFileURI(getter_AddRefs(uri), file);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
|
@ -345,6 +348,10 @@ void nsHyphenationManager::ShareHyphDictToProcess(
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(path);
|
RefPtr<nsAtom> localeAtom = LocaleAtomFromPath(path);
|
||||||
|
if (!localeAtom) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("bad path");
|
||||||
|
return;
|
||||||
|
}
|
||||||
RefPtr<nsHyphenator> hyph = GetHyphenator(localeAtom);
|
RefPtr<nsHyphenator> hyph = GetHyphenator(localeAtom);
|
||||||
if (!hyph) {
|
if (!hyph) {
|
||||||
MOZ_ASSERT_UNREACHABLE("failed to find hyphenator");
|
MOZ_ASSERT_UNREACHABLE("failed to find hyphenator");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue