You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
writeMapHash can panic when iterating through nested maps as hw.keysBuf is overwritten every iteration. If a nested map key is not alphabetically last of all the keys in the map and it has at least one more key than its index in the parent map it'll cause the next iteration of the parent keys to try and find a child key instead.
Steps to Reproduce
I created this test in hash_test.go that replicates the issue
funcTestMapHashPanic(t*testing.T) {
m:=pcommon.NewMap()
m.PutInt("a", 1)
m.PutInt("c", 1)
m.PutInt("d", 1)
m.PutInt("e", 1)
// nestedMap is alphabetically second in parent mapnestedMap:=m.PutEmptyMap("b")
// nestedMap is index 1 in parent when keys are sorted so we need at least 3 keys in this to ensure the next iteration of parent tries to find a key at "a3"nestedMap.PutInt("a1", 1)
nestedMap.PutInt("a2", 1)
nestedMap.PutInt("a3", 1)
assert.NotPanics(t, func() { MapHash(m) })
}
OS: macOS 13.2.1
Compiler(if manually compiled): go 1.20.1
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
I think the keyset that's iterated through likely needs to be stored in a variable that's local to the writeMapHash function. Every nested map will overwrite that keyset for it's parent.
The text was updated successfully, but these errors were encountered:
Component(s)
pkg/pdatautil
What happened?
Description
writeMapHash can panic when iterating through nested maps as
hw.keysBuf
is overwritten every iteration. If a nested map key is not alphabetically last of all the keys in the map and it has at least one more key than its index in the parent map it'll cause the next iteration of the parent keys to try and find a child key instead.Steps to Reproduce
I created this test in
hash_test.go
that replicates the issueExpected Result
No Panic
Actual Result
Panic due to invalid key access
Panic stack from test:
Collector version
v0.72.0
Environment information
Environment
OS: macOS 13.2.1
Compiler(if manually compiled): go 1.20.1
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
I think the keyset that's iterated through likely needs to be stored in a variable that's local to the
writeMapHash
function. Every nested map will overwrite that keyset for it's parent.The text was updated successfully, but these errors were encountered: