From 89839da06d973a7b2b6592f43bb9c814e094ee6b Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Thu, 28 Sep 2023 18:43:28 +0200 Subject: [PATCH] wip(amino): demo bug with TypeInfo.String 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. --- tm2/pkg/amino/typeinfo_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tm2/pkg/amino/typeinfo_test.go diff --git a/tm2/pkg/amino/typeinfo_test.go b/tm2/pkg/amino/typeinfo_test.go new file mode 100644 index 00000000000..ea9766e5de4 --- /dev/null +++ b/tm2/pkg/amino/typeinfo_test.go @@ -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() +}