Description
Describe the bug
The RedisSearch Module will trap into a dead cycle in Wildcard_MatchChar when the input pattern and str are in a special schema.
To Reproduce
Steps to reproduce the behavior:
- add an json object:
json.set test/3 $ '{"comment": "456a\\*456"}'
- add an index on key with 'test/' prefix:
ft.create index:test ON JSON PREFIX 1 test/ SCHEMA $.comment as comment TEXT
- do search on the index:
ft.search index:test "@comment:w'*abc123*'" DIALECT 2 VERBATIM
If the value which is searched is like '...a*...' and the pattern is like '*a....'(the character 'a' can also be other characters), the redis will be trapped into dead loop.
Expected behavior
a normal search. no dead loop
Screenshots
(redis-cli is blocked and I interrupt it)
Environment (please complete the following information):
- OS: Centos7.9
- x86_64
- v2.6.9(I try this in the newest version, it also exist)
Additional context
When use gdb to watch what happened in the module, I find it trapped in Wildcard_MatchChar function.
The reason of this bug is here.
if ((str_end != str_itr) && (c == *str_itr || c == '?'))
When compare c(a character in patern) with target str, it will be wrong if there is a '*' character in target str.