Skip to content

Commit 83fdfdc

Browse files
author
Dan Laine
committed
reduce diff
1 parent 6b6b3d8 commit 83fdfdc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

x/merkledb/codec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (c *codecImpl) encodeDBNode(n *dbNode) []byte {
9898
estimatedLen = estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren
9999
buf = bytes.NewBuffer(make([]byte, 0, estimatedLen))
100100
)
101+
101102
c.encodeMaybeByteSlice(buf, n.value)
102103
c.encodeUint(buf, uint64(numChildren))
103104
// Note we insert children in order of increasing index

x/merkledb/codec_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ func FuzzCodecInt(f *testing.F) {
7171
)
7272
}
7373

74+
func FuzzCodecKey(f *testing.F) {
75+
f.Fuzz(
76+
func(
77+
t *testing.T,
78+
b []byte,
79+
) {
80+
require := require.New(t)
81+
codec := codec.(*codecImpl)
82+
reader := bytes.NewReader(b)
83+
startLen := reader.Len()
84+
got, err := codec.decodeKey(reader)
85+
if err != nil {
86+
t.SkipNow()
87+
}
88+
endLen := reader.Len()
89+
numRead := startLen - endLen
90+
91+
// Encoding [got] should be the same as [b].
92+
var buf bytes.Buffer
93+
codec.encodeKey(&buf, got)
94+
bufBytes := buf.Bytes()
95+
require.Len(bufBytes, numRead)
96+
require.Equal(b[:numRead], bufBytes)
97+
},
98+
)
99+
}
100+
74101
func FuzzCodecDBNodeCanonical(f *testing.F) {
75102
f.Fuzz(
76103
func(

0 commit comments

Comments
 (0)