Skip to content

Commit

Permalink
Merge pull request #8034 from dsouzae/br_validate_points
Browse files Browse the repository at this point in the history
Validate points on input
  • Loading branch information
e-dard authored Apr 26, 2018
2 parents b326db5 + 95c5ddc commit a446134
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ func (c *client) Write(bp BatchPoints) error {
var b bytes.Buffer

for _, p := range bp.Points() {
if p == nil {
continue
}
if _, err := b.WriteString(p.pt.PrecisionString(bp.Precision())); err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion models/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ func unescapeStringField(in string) string {
}

// NewPoint returns a new point with the given measurement name, tags, fields and timestamp. If
// an unsupported field value (NaN) or out of range time is passed, this function returns an error.
// an unsupported field value (NaN, or +/-Inf) or out of range time is passed, this function
// returns an error.
func NewPoint(name string, tags Tags, fields Fields, t time.Time) (Point, error) {
key, err := pointKey(name, tags, fields, t)
if err != nil {
Expand Down Expand Up @@ -1330,11 +1331,17 @@ func pointKey(measurement string, tags Tags, fields Fields, t time.Time) ([]byte
switch value := value.(type) {
case float64:
// Ensure the caller validates and handles invalid field values
if math.IsInf(value, 0) {
return nil, fmt.Errorf("+/-Inf is an unsupported value for field %s", key)
}
if math.IsNaN(value) {
return nil, fmt.Errorf("NaN is an unsupported value for field %s", key)
}
case float32:
// Ensure the caller validates and handles invalid field values
if math.IsInf(float64(value), 0) {
return nil, fmt.Errorf("+/-Inf is an unsupported value for field %s", key)
}
if math.IsNaN(float64(value)) {
return nil, fmt.Errorf("NaN is an unsupported value for field %s", key)
}
Expand Down

0 comments on commit a446134

Please sign in to comment.