Skip to content

[BUG] trapped into a dead cycle in Wildcard_MatchChar #5895

Open
@1000happiness

Description

@1000happiness

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:

  1. add an json object:json.set test/3 $ '{"comment": "456a\\*456"}'
  2. add an index on key with 'test/' prefix: ft.create index:test ON JSON PREFIX 1 test/ SCHEMA $.comment as comment TEXT
  3. 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
Image
(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 == '?'))

Image

When compare c(a character in patern) with target str, it will be wrong if there is a '*' character in target str.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions