fix: check store keys length before accessing (#9639)
* check store keys length before accessing * check store keys length in all modules * add changelog * refactoring * address review comments * remove commented lines * small fixes * address review comments * fix failing tests * add godocs
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package kv
|
||||
|
||||
import "fmt"
|
||||
|
||||
// AssertKeyAtLeastLength panics when store key length is less than the given length.
|
||||
func AssertKeyAtLeastLength(bz []byte, length int) {
|
||||
if len(bz) < length {
|
||||
panic(fmt.Sprintf("expected key of length at least %d, got %d", length, len(bz)))
|
||||
}
|
||||
}
|
||||
|
||||
// AssertKeyLength panics when store key length is not equal to the given length.
|
||||
func AssertKeyLength(bz []byte, length int) {
|
||||
if len(bz) != length {
|
||||
panic(fmt.Sprintf("unexpected key length; got: %d, expected: %d", len(bz), length))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user