Skip to content

Commit 5d63c0d

Browse files
authored
bug fix: Invalid search string converted to empty pattern to panic (#21241)
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: @aressu1985, @sukki37
1 parent 1392f1f commit 5d63c0d

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

pkg/fulltext/fulltext.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ func ParsePatternInNLMode(pattern string) ([]*Pattern, error) {
826826
}
827827
}
828828

829+
if len(list) == 0 {
830+
return nil, moerr.NewInternalErrorNoCtx("Invalid input search string. search string onverted to empty pattern")
831+
}
832+
829833
// assign index
830834
idx := int32(0)
831835
for _, p := range list {

pkg/fulltext/fulltext_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@ func TestPatternFail(t *testing.T) {
195195
}
196196
}
197197

198+
func TestPatternNLFail(t *testing.T) {
199+
200+
tests := []TestCase{
201+
{
202+
pattern: "+[[[",
203+
},
204+
{
205+
pattern: "+''",
206+
},
207+
}
208+
209+
for _, c := range tests {
210+
_, err := PatternToString(c.pattern, int64(tree.FULLTEXT_NL))
211+
require.NotNil(t, err)
212+
}
213+
}
214+
198215
func TestFullTextNL(t *testing.T) {
199216

200217
pattern := "apple banana"

test/distributed/cases/fulltext/fulltext.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ insert into src values (0, 'color is red', 't1'), (1, 'car is yellow', 'crazy ca
1111
create fulltext index ftidx on src (body, title);
1212
select * from src where match(body) against('red');
1313
not supported: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet.
14+
select * from src where match(body,title) against('+]]]');
15+
internal error: Invalid input search string. search string onverted to empty pattern
16+
select * from src where match(body,title) against('+I'm');
17+
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');";
1418
select match(body) against('red') from src;
1519
not supported: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet.
1620
alter table src add fulltext index ftidx2 (body);

test/distributed/cases/fulltext/fulltext.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ create fulltext index ftidx on src (body, title);
1717

1818
-- check fulltext_match with index error
1919
select * from src where match(body) against('red');
20+
select * from src where match(body,title) against('+]]]');
21+
select * from src where match(body,title) against('+I'm');
2022
2123
select match(body) against('red') from src;
2224

0 commit comments

Comments
 (0)