Skip to content

Commit fce86aa

Browse files
mengskysamayuhan6665
authored andcommitted
fix(common): strmatcher match domain safety
1 parent cd1d000 commit fce86aa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

common/strmatcher/ac_automaton_matcher.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ func (ac *ACAutomaton) Match(s string) bool {
225225
// 2. the match string is through a fail edge. NOT FULL MATCH
226226
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
227227
for i := len(s) - 1; i >= 0; i-- {
228-
idx := char2Index[s[i]]
228+
chr := int(s[i])
229+
if chr >= len(char2Index) {
230+
return false
231+
}
232+
idx := char2Index[chr]
229233
fullMatch = fullMatch && ac.trie[node][idx].edgeType
230234
node = ac.trie[node][idx].nextNode
231235
switch ac.exists[node].matchType {

common/strmatcher/strmatcher_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,17 @@ func TestACAutomaton(t *testing.T) {
217217
pattern: "vvgoogle.com",
218218
res: true,
219219
},
220+
{
221+
pattern: "½",
222+
res: false,
223+
},
220224
}
221225
for _, test := range cases2Output {
222226
if m := ac.Match(test.pattern); m != test.res {
223227
t.Error("unexpected output: ", m, " for test case ", test)
224228
}
225229
}
226230
}
227-
228231
{
229232
cases3Input := []struct {
230233
pattern string

0 commit comments

Comments
 (0)