Unverified Commit 4f85c2b8 authored by Martin Holst Swende's avatar Martin Holst Swende Committed by GitHub

trie: fix error in node decoding (#19111)

parent 5b8ae788
...@@ -52,6 +52,9 @@ func hexToCompact(hex []byte) []byte { ...@@ -52,6 +52,9 @@ func hexToCompact(hex []byte) []byte {
} }
func compactToHex(compact []byte) []byte { func compactToHex(compact []byte) []byte {
if len(compact) == 0 {
return compact
}
base := keybytesToHex(compact) base := keybytesToHex(compact)
// delete terminator flag // delete terminator flag
if base[0] < 2 { if base[0] < 2 {
......
...@@ -614,3 +614,16 @@ func updateString(trie *Trie, k, v string) { ...@@ -614,3 +614,16 @@ func updateString(trie *Trie, k, v string) {
func deleteString(trie *Trie, k string) { func deleteString(trie *Trie, k string) {
trie.Delete([]byte(k)) trie.Delete([]byte(k))
} }
func TestDecodeNode(t *testing.T) {
t.Parallel()
var (
hash = make([]byte, 20)
elems = make([]byte, 20)
)
for i := 0; i < 5000000; i++ {
rand.Read(hash)
rand.Read(elems)
decodeNode(hash, elems, 1)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment