Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

s3vectors: reject empty boolean-operator lists and sub-objects in filters (#12220)

Chris Lu9d5929a73f22
diff --git a/weed/s3api/s3vectors/handlers.go b/weed/s3api/s3vectors/handlers.go
index 160d7f9652..c5ad9b6135 100644
--- a/weed/s3api/s3vectors/handlers.go
+++ b/weed/s3api/s3vectors/handlers.go
@@ -1532,6 +1532,9 @@ func filterExpr(filter map[string]interface{}) (string, error) {
if !ok {
return "", fmt.Errorf("%s expects a list", key)
}
+ if len(sub) == 0 {
+ return "", fmt.Errorf("%s expects a non-empty list", key)
+ }
exprs := make([]string, 0, len(sub))
for _, item := range sub {
m, ok := item.(map[string]interface{})
@@ -1542,6 +1545,9 @@ func filterExpr(filter map[string]interface{}) (string, error) {
if err != nil {
return "", err
}
+ if e == "" {
+ return "", fmt.Errorf("%s expects non-empty objects", key)
+ }
exprs = append(exprs, e)
}
joiner := " AND "
@@ -1684,6 +1690,9 @@ func fieldClause(field string, cond interface{}) (string, error) {
return "", fmt.Errorf("unsupported operator %s", op)
}
}
+ if len(parts) == 0 {
+ return "", fmt.Errorf("%s expects at least one operator", field)
+ }
return strings.Join(parts, " AND "), nil
default:
lit, err := sqlLiteral(cond)
diff --git a/weed/s3api/s3vectors/handlers_test.go b/weed/s3api/s3vectors/handlers_test.go
index 47fed5f131..e50efa8f9c 100644
--- a/weed/s3api/s3vectors/handlers_test.go
+++ b/weed/s3api/s3vectors/handlers_test.go
@@ -336,12 +336,19 @@ func TestTranslateFilter(t *testing.T) {
}
for name, filter := range map[string]map[string]interface{}{
- "unknown operator": {"k": map[string]interface{}{"$bogus": "v"}},
- "exists non-bool": {"k": map[string]interface{}{"$exists": "yes"}},
- "range non-number": {"k": map[string]interface{}{"$gt": "v"}},
- "in non-list": {"k": map[string]interface{}{"$in": "v"}},
- "top-level bad op": {"$bogus": []interface{}{}},
- "nested bad member": {"$and": []interface{}{"x"}},
+ "unknown operator": {"k": map[string]interface{}{"$bogus": "v"}},
+ "exists non-bool": {"k": map[string]interface{}{"$exists": "yes"}},
+ "range non-number": {"k": map[string]interface{}{"$gt": "v"}},
+ "in non-list": {"k": map[string]interface{}{"$in": "v"}},
+ "top-level bad op": {"$bogus": []interface{}{}},
+ "nested bad member": {"$and": []interface{}{"x"}},
+ "empty and list": {"$and": []interface{}{}},
+ "empty or list": {"$or": []interface{}{}},
+ "empty sub-object": {"$and": []interface{}{map[string]interface{}{}}},
+ "empty operators": {"k": map[string]interface{}{}},
+ "empty among fields": {"k": map[string]interface{}{}, "j": "1"},
+ "empty under and": {"$and": []interface{}{map[string]interface{}{
+ "k": map[string]interface{}{}, "j": map[string]interface{}{}}}},
} {
if _, err := translateFilter(filter); err == nil {
t.Fatalf("%s should fail", name)