From 8249a7f8a3b20d2073b41990cb60d9cd847a576f Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Thu, 28 Sep 2023 18:43:28 +0200 Subject: [PATCH 1/2] 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() +} From a32def1e637e4d5f2becef6a110910a3658db88c Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 4 Oct 2023 13:53:18 +0200 Subject: [PATCH 2/2] remove useless field --- tm2/pkg/amino/typeinfo_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tm2/pkg/amino/typeinfo_test.go b/tm2/pkg/amino/typeinfo_test.go index ea9766e5de4..b685c624557 100644 --- a/tm2/pkg/amino/typeinfo_test.go +++ b/tm2/pkg/amino/typeinfo_test.go @@ -7,7 +7,6 @@ import ( func TestTypeInfoString(t *testing.T) { type T struct { - N string T *T } typeInfo := gcdc.newTypeInfoUnregisteredWLocked(reflect.TypeOf(T{}))