Commit 7367cae2 authored by Mustafa Emre Acer's avatar Mustafa Emre Acer Committed by Commit Bot

Fix crash in IdnSpoofChecker with certain characters

IdnSpoofChecker incorrectly assumed that a skeleton string shouldn't contain any dots. This isn't true, skeletons of some characters such as Extended Arabic-Indic Digit Zero (۰) is indeed a dot.

Remove this assumption and add a test case.

Bug: 877045
Change-Id: I6e73c4d2b850f614b8a685f5068d9cd1028f1b24
Reviewed-on: https://chromium-review.googlesource.com/c/1284058Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600528}
parent fcaf2e59
......@@ -88,7 +88,8 @@ IDNSpoofChecker::HuffmanTrieParams g_trie_params{
std::string LookupMatchInTopDomains(const std::string& skeleton) {
DCHECK(!skeleton.empty());
DCHECK_NE(skeleton.back(), '.');
// There are no other guarantees about a skeleton string such as not including
// a dot. Skeleton of certain characters are dots (e.g. "۰" (U+06F0)).
TopDomainPreloadDecoder preload_decoder(
g_trie_params.huffman_tree, g_trie_params.huffman_tree_size,
g_trie_params.trie, g_trie_params.trie_bits,
......@@ -366,6 +367,7 @@ bool IDNSpoofChecker::SafeToDisplayAsUnicode(base::StringPiece16 label,
}
std::string IDNSpoofChecker::GetSimilarTopDomain(base::StringPiece16 hostname) {
DCHECK(!hostname.empty());
for (const std::string& skeleton : GetSkeletons(hostname)) {
DCHECK(!skeleton.empty());
std::string matching_top_domain = LookupMatchInTopDomains(skeleton);
......
......@@ -956,6 +956,10 @@ const IDNTestCase idn_cases[] = {
{"xn--kx8a.com", L"\xa661.com", false},
// Cyrillic Ext C: ᲂ.com (Narrow o)
{"xn--43f.com", L"\x1c82.com", false},
// The skeleton of Extended Arabic-Indic Digit Zero (۰) is a dot. Check that
// this is handled correctly (crbug/877045).
{"xn--dmb", L"\x06f0", true},
};
struct AdjustOffsetCase {
......
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