Skip to content

Commit 68caf4b

Browse files
fix(bttest): Reject empty regex row filters (#6520)
This fixes GitHub issue #6519; see that issue for further commentary. Co-authored-by: Eric Schmidt <[email protected]>
1 parent c2bfae3 commit 68caf4b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

bigtable/bttest/inmem.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,12 @@ func filterRow(f *btpb.RowFilter, r *row) (bool, error) {
632632
}
633633
return filterRow(f.Condition.FalseFilter, r)
634634
case *btpb.RowFilter_RowKeyRegexFilter:
635+
if len(f.RowKeyRegexFilter) == 0 {
636+
return false, status.Errorf(codes.InvalidArgument, "Error in field 'row_key_regex_filter' : argument must not be empty")
637+
}
635638
rx, err := newRegexp(f.RowKeyRegexFilter)
636639
if err != nil {
637-
return false, status.Errorf(codes.InvalidArgument, "Error in field 'rowkey_regex_filter' : %v", err)
640+
return false, status.Errorf(codes.InvalidArgument, "Error in field 'row_key_regex_filter' : %v", err)
638641
}
639642
if !rx.MatchString(r.key) {
640643
return false, nil

bigtable/bttest/inmem_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,47 @@ func TestReadRowsError(t *testing.T) {
747747
}
748748
}
749749

750+
func TestReadRowsErrorOnEmptyRegex(t *testing.T) {
751+
ctx := context.Background()
752+
s := &server{
753+
tables: make(map[string]*table),
754+
}
755+
newTbl := btapb.Table{
756+
ColumnFamilies: map[string]*btapb.ColumnFamily{
757+
"cf0": {GcRule: &btapb.GcRule{Rule: &btapb.GcRule_MaxNumVersions{MaxNumVersions: 1}}},
758+
},
759+
}
760+
tblInfo, err := s.CreateTable(ctx, &btapb.CreateTableRequest{Parent: "cluster", TableId: "t", Table: &newTbl})
761+
if err != nil {
762+
t.Fatalf("Creating table: %v", err)
763+
}
764+
mreq := &btpb.MutateRowRequest{
765+
TableName: tblInfo.Name,
766+
RowKey: []byte("row"),
767+
Mutations: []*btpb.Mutation{{
768+
Mutation: &btpb.Mutation_SetCell_{SetCell: &btpb.Mutation_SetCell{
769+
FamilyName: "cf0",
770+
ColumnQualifier: []byte("col"),
771+
TimestampMicros: 1000,
772+
Value: []byte{},
773+
}},
774+
}},
775+
}
776+
if _, err := s.MutateRow(ctx, mreq); err != nil {
777+
t.Fatalf("Populating table: %v", err)
778+
}
779+
780+
mock := &MockReadRowsServer{}
781+
req := &btpb.ReadRowsRequest{
782+
TableName: tblInfo.Name, Filter: &btpb.RowFilter{
783+
Filter: &btpb.RowFilter_RowKeyRegexFilter{RowKeyRegexFilter: []byte("")},
784+
}, // Empty regexes should be rejected.
785+
}
786+
if err = s.ReadRows(req, mock); err == nil {
787+
t.Fatal("ReadRows got no error, want error")
788+
}
789+
}
790+
750791
func TestReadRowsAfterDeletion(t *testing.T) {
751792
ctx := context.Background()
752793
s := &server{

0 commit comments

Comments
 (0)