Skip to content

Commit

Permalink
wip(amino): demo bug with TypeInfo.String
Browse files Browse the repository at this point in the history
Add a test that demonstrates a bug when the underlying type represented
by TypeInfo has fields of the same type: TypeInfo.String() triggers a
stack overflow because the codec reuses the same TypeInfo instance when
affecting the master TypeInfo.Fields.

This happens when cdc.fullnameToTypeInfo is printed (in case of error
for instance see codec.go:535), causing all registered TypeInfo to be
printed too, which calls their String method.

Example of type that can triggers this issue:
tm2/pkg/crypto/merkle.SimpleProofNode.
  • Loading branch information
tbruyelle committed Sep 28, 2023
1 parent 5a7d005 commit 89839da
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tm2/pkg/amino/typeinfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package amino

import (
"reflect"
"testing"
)

func TestTypeInfoString(t *testing.T) {
type T struct {
N string
T *T
}
typeInfo := gcdc.newTypeInfoUnregisteredWLocked(reflect.TypeOf(T{}))
_ = typeInfo.String()
}

0 comments on commit 89839da

Please sign in to comment.