Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix float32 normalizeValue panic #6129

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix documentation links in README.md files. {pull}5710[5710]
- Fix logstash output debug message. {pull}5799{5799]
- Fix isolation of modules when merging local and global field settings. {issue}5795[5795]
- Fix panic when Events containing a float32 value are normalized. {pull}6129[6129]

*Auditbeat*

Expand Down
4 changes: 3 additions & 1 deletion libbeat/common/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ func normalizeValue(value interface{}, keys ...string) (interface{}, []error) {
case []int, []int8, []int16, []int32, []int64:
case uint, uint8, uint16, uint32, uint64:
case []uint, []uint8, []uint16, []uint32, []uint64:
case float32, float64:
case float64:
return Float(value.(float64)), nil
case float32:
return Float(value.(float32)), nil
case []float32, []float64:
case complex64, complex128:
case []complex64, []complex128:
Expand Down
17 changes: 17 additions & 0 deletions libbeat/common/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ func TestNormalizeValue(t *testing.T) {

assert.Equal(t, test.out, out, "Test case %v", i)
}

var floatTests = []struct {
in interface{}
out interface{}
}{
{float32(1), float64(1)},
{float64(1), float64(1)},
}

for i, test := range floatTests {
out, err := normalizeValue(test.in)
if err != nil {
t.Error(err)
continue
}
assert.InDelta(t, test.out, float64(out.(Float)), 0.000001, "(approximate) Test case %v", i)
}
}

func TestNormalizeMapError(t *testing.T) {
Expand Down