Browse Source

comment

pull/7185/head
chrislu 1 month ago
parent
commit
bdf43f53e9
  1. 2
      weed/query/engine/aggregations.go
  2. 3
      weed/query/engine/string_functions.go

2
weed/query/engine/aggregations.go

@ -360,6 +360,7 @@ func (e *SQLEngine) executeAggregationQueryWithPlan(ctx context.Context, hybridS
if limit64 > int64(math.MaxInt) || limit64 < 0 { if limit64 > int64(math.MaxInt) || limit64 < 0 {
return nil, fmt.Errorf("LIMIT value %d is out of range", limit64) return nil, fmt.Errorf("LIMIT value %d is out of range", limit64)
} }
// Safe conversion after bounds check
limit = int(limit64) limit = int(limit64)
} }
} }
@ -370,6 +371,7 @@ func (e *SQLEngine) executeAggregationQueryWithPlan(ctx context.Context, hybridS
if offset64 > int64(math.MaxInt) || offset64 < 0 { if offset64 > int64(math.MaxInt) || offset64 < 0 {
return nil, fmt.Errorf("OFFSET value %d is out of range", offset64) return nil, fmt.Errorf("OFFSET value %d is out of range", offset64)
} }
// Safe conversion after bounds check
offset = int(offset64) offset = int(offset64)
} }
} }

3
weed/query/engine/string_functions.go

@ -151,6 +151,7 @@ func (e *SQLEngine) Substring(value *schema_pb.Value, start *schema_pb.Value, le
// If length is out-of-bounds for int, take substring from startIdx to end // If length is out-of-bounds for int, take substring from startIdx to end
result = str[startIdx:] result = str[startIdx:]
} else { } else {
// Safe conversion after bounds check
endIdx := startIdx + int(lengthVal) endIdx := startIdx + int(lengthVal)
if endIdx > len(str) { if endIdx > len(str) {
endIdx = len(str) endIdx = len(str)
@ -283,6 +284,7 @@ func (e *SQLEngine) Left(value *schema_pb.Value, length *schema_pb.Value) (*sche
}, nil }, nil
} }
// Safe conversion after bounds check
return &schema_pb.Value{ return &schema_pb.Value{
Kind: &schema_pb.Value_StringValue{StringValue: str[:int(lengthVal)]}, Kind: &schema_pb.Value_StringValue{StringValue: str[:int(lengthVal)]},
}, nil }, nil
@ -322,6 +324,7 @@ func (e *SQLEngine) Right(value *schema_pb.Value, length *schema_pb.Value) (*sch
}, nil }, nil
} }
// Safe conversion after bounds check
startPos := len(str) - int(lengthVal) startPos := len(str) - int(lengthVal)
return &schema_pb.Value{ return &schema_pb.Value{
Kind: &schema_pb.Value_StringValue{StringValue: str[startPos:]}, Kind: &schema_pb.Value_StringValue{StringValue: str[startPos:]},

Loading…
Cancel
Save