Skip to content

Commit

Permalink
bug fix: Invalid search string converted to empty pattern to panic (#…
Browse files Browse the repository at this point in the history
…21275)

Invalid search string converted to empty pattern to panic

e.g. search string '+[[[' in natural language mode. After tokenization, it become empty pattern that cause panic.

Approved by: @heni02, @zhangxu19830126, @sukki37, @aressu1985
  • Loading branch information
cpegeric authored Jan 17, 2025
1 parent 2e17299 commit e5433df
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/common/fulltext/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ func ParsePatternInNLMode(pattern string) ([]*Pattern, error) {
}
}

if len(list) == 0 {
return nil, moerr.NewInternalErrorNoCtx("Invalid input search string. search string onverted to empty pattern")
}

// assign index
idx := int32(0)
for _, p := range list {
Expand Down
17 changes: 17 additions & 0 deletions pkg/common/fulltext/fulltext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ func TestPatternFail(t *testing.T) {
}
}

func TestPatternNLFail(t *testing.T) {

tests := []TestCase{
{
pattern: "+[[[",
},
{
pattern: "+''",
},
}

for _, c := range tests {
_, err := PatternToString(c.pattern, int64(tree.FULLTEXT_NL))
require.NotNil(t, err)
}
}

func TestFullTextNL(t *testing.T) {

pattern := "apple banana"
Expand Down
4 changes: 4 additions & 0 deletions test/distributed/cases/fulltext/fulltext.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ insert into src values (0, 'color is red', 't1'), (1, 'car is yellow', 'crazy ca
create fulltext index ftidx on src (body, title);
select * from src where match(body) against('red');
not supported: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet.
select * from src where match(body,title) against('+]]]');
internal error: Invalid input search string. search string onverted to empty pattern
select * from src where match(body,title) against('+I'm');
SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error at line 1 column 55 near "m');";
select match(body) against('red') from src;
not supported: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet.
alter table src add fulltext index ftidx2 (body);
Expand Down
2 changes: 2 additions & 0 deletions test/distributed/cases/fulltext/fulltext.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ create fulltext index ftidx on src (body, title);

-- check fulltext_match with index error
select * from src where match(body) against('red');
select * from src where match(body,title) against('+]]]');
select * from src where match(body,title) against('+I'm');
select match(body) against('red') from src;
Expand Down

0 comments on commit e5433df

Please sign in to comment.