Skip to content

Commit

Permalink
fix(bttest): Reject empty regex row filters (#6520)
Browse files Browse the repository at this point in the history
This fixes GitHub issue #6519; see that issue for further commentary.

Co-authored-by: Eric Schmidt <[email protected]>
  • Loading branch information
adamroyjones and telpirion authored Oct 24, 2022
1 parent c2bfae3 commit 68caf4b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,12 @@ func filterRow(f *btpb.RowFilter, r *row) (bool, error) {
}
return filterRow(f.Condition.FalseFilter, r)
case *btpb.RowFilter_RowKeyRegexFilter:
if len(f.RowKeyRegexFilter) == 0 {
return false, status.Errorf(codes.InvalidArgument, "Error in field 'row_key_regex_filter' : argument must not be empty")
}
rx, err := newRegexp(f.RowKeyRegexFilter)
if err != nil {
return false, status.Errorf(codes.InvalidArgument, "Error in field 'rowkey_regex_filter' : %v", err)
return false, status.Errorf(codes.InvalidArgument, "Error in field 'row_key_regex_filter' : %v", err)
}
if !rx.MatchString(r.key) {
return false, nil
Expand Down
41 changes: 41 additions & 0 deletions bigtable/bttest/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,47 @@ func TestReadRowsError(t *testing.T) {
}
}

func TestReadRowsErrorOnEmptyRegex(t *testing.T) {
ctx := context.Background()
s := &server{
tables: make(map[string]*table),
}
newTbl := btapb.Table{
ColumnFamilies: map[string]*btapb.ColumnFamily{
"cf0": {GcRule: &btapb.GcRule{Rule: &btapb.GcRule_MaxNumVersions{MaxNumVersions: 1}}},
},
}
tblInfo, err := s.CreateTable(ctx, &btapb.CreateTableRequest{Parent: "cluster", TableId: "t", Table: &newTbl})
if err != nil {
t.Fatalf("Creating table: %v", err)
}
mreq := &btpb.MutateRowRequest{
TableName: tblInfo.Name,
RowKey: []byte("row"),
Mutations: []*btpb.Mutation{{
Mutation: &btpb.Mutation_SetCell_{SetCell: &btpb.Mutation_SetCell{
FamilyName: "cf0",
ColumnQualifier: []byte("col"),
TimestampMicros: 1000,
Value: []byte{},
}},
}},
}
if _, err := s.MutateRow(ctx, mreq); err != nil {
t.Fatalf("Populating table: %v", err)
}

mock := &MockReadRowsServer{}
req := &btpb.ReadRowsRequest{
TableName: tblInfo.Name, Filter: &btpb.RowFilter{
Filter: &btpb.RowFilter_RowKeyRegexFilter{RowKeyRegexFilter: []byte("")},
}, // Empty regexes should be rejected.
}
if err = s.ReadRows(req, mock); err == nil {
t.Fatal("ReadRows got no error, want error")
}
}

func TestReadRowsAfterDeletion(t *testing.T) {
ctx := context.Background()
s := &server{
Expand Down

0 comments on commit 68caf4b

Please sign in to comment.