From a458153098d6f66ee0c6f990f31b3646ad171bbb Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Sat, 16 Feb 2019 16:16:12 +0100 Subject: [PATCH] trie: fix error in node decoding (#19111) --- trie/encoding.go | 3 +++ trie/trie_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/trie/encoding.go b/trie/encoding.go index 5f120de638..1955a3e664 100644 --- a/trie/encoding.go +++ b/trie/encoding.go @@ -52,6 +52,9 @@ func hexToCompact(hex []byte) []byte { } func compactToHex(compact []byte) []byte { + if len(compact) == 0 { + return compact + } base := keybytesToHex(compact) // delete terminator flag if base[0] < 2 { diff --git a/trie/trie_test.go b/trie/trie_test.go index f9d6029c99..4d84aa96cf 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -614,3 +614,16 @@ func updateString(trie *Trie, k, v string) { func deleteString(trie *Trie, k string) { 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) + } +}