From c47c2bc1dff9ed28b324d5519c7f1a31cae0309c Mon Sep 17 00:00:00 2001 From: Maheesha Perera Date: Sun, 17 Dec 2023 14:40:04 +1100 Subject: [PATCH] Add test case to demonstrate panic when UnmarshalUnsafe is called with an empty string map value or empty oneof string field --- testproto/unsafe/unsafe.pb.go | 141 ++++- testproto/unsafe/unsafe.proto | 5 + testproto/unsafe/unsafe_test.go | 75 ++- testproto/unsafe/unsafe_vtproto.pb.go | 762 +++++++++++++++++++++++++- 4 files changed, 907 insertions(+), 76 deletions(-) diff --git a/testproto/unsafe/unsafe.pb.go b/testproto/unsafe/unsafe.pb.go index 4b5a345..f7a86f9 100644 --- a/testproto/unsafe/unsafe.pb.go +++ b/testproto/unsafe/unsafe.pb.go @@ -31,6 +31,7 @@ type UnsafeTest struct { // *UnsafeTest_Sub2_ // *UnsafeTest_Sub3_ // *UnsafeTest_Sub4_ + // *UnsafeTest_Sub5_ Sub isUnsafeTest_Sub `protobuf_oneof:"sub"` } @@ -101,6 +102,13 @@ func (x *UnsafeTest) GetSub4() *UnsafeTest_Sub4 { return nil } +func (x *UnsafeTest) GetSub5() *UnsafeTest_Sub5 { + if x, ok := x.GetSub().(*UnsafeTest_Sub5_); ok { + return x.Sub5 + } + return nil +} + type isUnsafeTest_Sub interface { isUnsafeTest_Sub() } @@ -121,6 +129,10 @@ type UnsafeTest_Sub4_ struct { Sub4 *UnsafeTest_Sub4 `protobuf:"bytes,4,opt,name=sub4,proto3,oneof"` } +type UnsafeTest_Sub5_ struct { + Sub5 *UnsafeTest_Sub5 `protobuf:"bytes,5,opt,name=sub5,proto3,oneof"` +} + func (*UnsafeTest_Sub1_) isUnsafeTest_Sub() {} func (*UnsafeTest_Sub2_) isUnsafeTest_Sub() {} @@ -129,6 +141,8 @@ func (*UnsafeTest_Sub3_) isUnsafeTest_Sub() {} func (*UnsafeTest_Sub4_) isUnsafeTest_Sub() {} +func (*UnsafeTest_Sub5_) isUnsafeTest_Sub() {} + type UnsafeTest_Sub1 struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -367,11 +381,58 @@ func (*UnsafeTest_Sub4_S) isUnsafeTest_Sub4_Foo() {} func (*UnsafeTest_Sub4_B) isUnsafeTest_Sub4_Foo() {} +type UnsafeTest_Sub5 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo map[string]string `protobuf:"bytes,1,rep,name=foo,proto3" json:"foo,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *UnsafeTest_Sub5) Reset() { + *x = UnsafeTest_Sub5{} + if protoimpl.UnsafeEnabled { + mi := &file_unsafe_unsafe_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UnsafeTest_Sub5) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UnsafeTest_Sub5) ProtoMessage() {} + +func (x *UnsafeTest_Sub5) ProtoReflect() protoreflect.Message { + mi := &file_unsafe_unsafe_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UnsafeTest_Sub5.ProtoReflect.Descriptor instead. +func (*UnsafeTest_Sub5) Descriptor() ([]byte, []int) { + return file_unsafe_unsafe_proto_rawDescGZIP(), []int{0, 4} +} + +func (x *UnsafeTest_Sub5) GetFoo() map[string]string { + if x != nil { + return x.Foo + } + return nil +} + var File_unsafe_unsafe_proto protoreflect.FileDescriptor var file_unsafe_unsafe_proto_rawDesc = []byte{ 0x0a, 0x13, 0x75, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x2f, 0x75, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x97, 0x03, 0x0a, 0x0a, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xac, 0x04, 0x0a, 0x0a, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x04, 0x73, 0x75, 0x62, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x53, 0x75, 0x62, 0x31, 0x48, 0x00, 0x52, 0x04, 0x73, 0x75, 0x62, 0x31, 0x12, 0x26, 0x0a, 0x04, @@ -382,23 +443,32 @@ var file_unsafe_unsafe_proto_rawDesc = []byte{ 0x53, 0x75, 0x62, 0x33, 0x48, 0x00, 0x52, 0x04, 0x73, 0x75, 0x62, 0x33, 0x12, 0x26, 0x0a, 0x04, 0x73, 0x75, 0x62, 0x34, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x53, 0x75, 0x62, 0x34, 0x48, 0x00, 0x52, 0x04, - 0x73, 0x75, 0x62, 0x34, 0x1a, 0x22, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x31, 0x12, 0x0c, 0x0a, 0x01, - 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x01, 0x62, 0x1a, 0x22, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x32, - 0x12, 0x0c, 0x0a, 0x01, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x01, 0x73, 0x12, 0x0c, - 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x01, 0x62, 0x1a, 0x6b, 0x0a, 0x04, - 0x53, 0x75, 0x62, 0x33, 0x12, 0x2b, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x19, 0x2e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x53, - 0x75, 0x62, 0x33, 0x2e, 0x46, 0x6f, 0x6f, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x66, 0x6f, - 0x6f, 0x1a, 0x36, 0x0a, 0x08, 0x46, 0x6f, 0x6f, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x2d, 0x0a, 0x04, 0x53, 0x75, 0x62, - 0x34, 0x12, 0x0e, 0x0a, 0x01, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x01, - 0x73, 0x12, 0x0e, 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x01, - 0x62, 0x42, 0x05, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x42, 0x05, 0x0a, 0x03, 0x73, 0x75, 0x62, 0x42, - 0x12, 0x5a, 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x6e, 0x73, - 0x61, 0x66, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x75, 0x62, 0x34, 0x12, 0x26, 0x0a, 0x04, 0x73, 0x75, 0x62, 0x35, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x2e, + 0x53, 0x75, 0x62, 0x35, 0x48, 0x00, 0x52, 0x04, 0x73, 0x75, 0x62, 0x35, 0x1a, 0x22, 0x0a, 0x04, + 0x53, 0x75, 0x62, 0x31, 0x12, 0x0c, 0x0a, 0x01, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x01, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x01, 0x62, + 0x1a, 0x22, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x32, 0x12, 0x0c, 0x0a, 0x01, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x01, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x03, 0x28, + 0x0c, 0x52, 0x01, 0x62, 0x1a, 0x6b, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x33, 0x12, 0x2b, 0x0a, 0x03, + 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x55, 0x6e, 0x73, 0x61, + 0x66, 0x65, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x53, 0x75, 0x62, 0x33, 0x2e, 0x46, 0x6f, 0x6f, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x1a, 0x36, 0x0a, 0x08, 0x46, 0x6f, 0x6f, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x1a, 0x2d, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x34, 0x12, 0x0e, 0x0a, 0x01, 0x73, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x01, 0x73, 0x12, 0x0e, 0x0a, 0x01, 0x62, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x01, 0x62, 0x42, 0x05, 0x0a, 0x03, 0x66, 0x6f, 0x6f, + 0x1a, 0x6b, 0x0a, 0x04, 0x53, 0x75, 0x62, 0x35, 0x12, 0x2b, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x54, 0x65, + 0x73, 0x74, 0x2e, 0x53, 0x75, 0x62, 0x35, 0x2e, 0x46, 0x6f, 0x6f, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x1a, 0x36, 0x0a, 0x08, 0x46, 0x6f, 0x6f, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x05, 0x0a, + 0x03, 0x73, 0x75, 0x62, 0x42, 0x12, 0x5a, 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x75, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -413,26 +483,30 @@ func file_unsafe_unsafe_proto_rawDescGZIP() []byte { return file_unsafe_unsafe_proto_rawDescData } -var file_unsafe_unsafe_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_unsafe_unsafe_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_unsafe_unsafe_proto_goTypes = []interface{}{ (*UnsafeTest)(nil), // 0: UnsafeTest (*UnsafeTest_Sub1)(nil), // 1: UnsafeTest.Sub1 (*UnsafeTest_Sub2)(nil), // 2: UnsafeTest.Sub2 (*UnsafeTest_Sub3)(nil), // 3: UnsafeTest.Sub3 (*UnsafeTest_Sub4)(nil), // 4: UnsafeTest.Sub4 - nil, // 5: UnsafeTest.Sub3.FooEntry + (*UnsafeTest_Sub5)(nil), // 5: UnsafeTest.Sub5 + nil, // 6: UnsafeTest.Sub3.FooEntry + nil, // 7: UnsafeTest.Sub5.FooEntry } var file_unsafe_unsafe_proto_depIdxs = []int32{ 1, // 0: UnsafeTest.sub1:type_name -> UnsafeTest.Sub1 2, // 1: UnsafeTest.sub2:type_name -> UnsafeTest.Sub2 3, // 2: UnsafeTest.sub3:type_name -> UnsafeTest.Sub3 4, // 3: UnsafeTest.sub4:type_name -> UnsafeTest.Sub4 - 5, // 4: UnsafeTest.Sub3.foo:type_name -> UnsafeTest.Sub3.FooEntry - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 5, // 4: UnsafeTest.sub5:type_name -> UnsafeTest.Sub5 + 6, // 5: UnsafeTest.Sub3.foo:type_name -> UnsafeTest.Sub3.FooEntry + 7, // 6: UnsafeTest.Sub5.foo:type_name -> UnsafeTest.Sub5.FooEntry + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_unsafe_unsafe_proto_init() } @@ -501,12 +575,25 @@ func file_unsafe_unsafe_proto_init() { return nil } } + file_unsafe_unsafe_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UnsafeTest_Sub5); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } file_unsafe_unsafe_proto_msgTypes[0].OneofWrappers = []interface{}{ (*UnsafeTest_Sub1_)(nil), (*UnsafeTest_Sub2_)(nil), (*UnsafeTest_Sub3_)(nil), (*UnsafeTest_Sub4_)(nil), + (*UnsafeTest_Sub5_)(nil), } file_unsafe_unsafe_proto_msgTypes[4].OneofWrappers = []interface{}{ (*UnsafeTest_Sub4_S)(nil), @@ -518,7 +605,7 @@ func file_unsafe_unsafe_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_unsafe_unsafe_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/testproto/unsafe/unsafe.proto b/testproto/unsafe/unsafe.proto index 3150189..59e5e0e 100644 --- a/testproto/unsafe/unsafe.proto +++ b/testproto/unsafe/unsafe.proto @@ -23,10 +23,15 @@ message UnsafeTest { } } + message Sub5 { + map foo = 1; + } + oneof sub { Sub1 sub1 = 1; Sub2 sub2 = 2; Sub3 sub3 = 3; Sub4 sub4 = 4; + Sub5 sub5 = 5; } } diff --git a/testproto/unsafe/unsafe_test.go b/testproto/unsafe/unsafe_test.go index 179faed..2329c8e 100644 --- a/testproto/unsafe/unsafe_test.go +++ b/testproto/unsafe/unsafe_test.go @@ -94,7 +94,7 @@ func Test_UnmarshalVTUnsafe(t *testing.T) { assertBytesAreOriginal(t, (t2Unsafe.Sub).(*UnsafeTest_Sub2_).Sub2.B[i], true, originalData2) } - // map field + // map[string]bytes field t3Orig := &UnsafeTest{ Sub: &UnsafeTest_Sub3_{ Sub3: &UnsafeTest_Sub3{ @@ -122,27 +122,32 @@ func Test_UnmarshalVTUnsafe(t *testing.T) { } // oneof field - t4OrigS := &UnsafeTest{ - Sub: &UnsafeTest_Sub4_{ - Sub4: &UnsafeTest_Sub4{ - Foo: &UnsafeTest_Sub4_S{ - S: testString, + for _, stringVal := range []string{ + testString, + "", + } { + t4OrigS := &UnsafeTest{ + Sub: &UnsafeTest_Sub4_{ + Sub4: &UnsafeTest_Sub4{ + Foo: &UnsafeTest_Sub4_S{ + S: stringVal, + }, }, }, - }, + } + originalData4S, err := t4OrigS.MarshalVT() + require.NoError(t, err) + + t4SafeS := &UnsafeTest{} + require.NoError(t, t4SafeS.UnmarshalVT(originalData4S)) + assert.Equal(t, (t4OrigS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, (t4SafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S) + assertStringIsOriginal(t, (t4SafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, false, originalData4S) + + t4UnsafeS := &UnsafeTest{} + require.NoError(t, t4UnsafeS.UnmarshalVTUnsafe(originalData4S)) + assert.Equal(t, (t4OrigS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, (t4UnsafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S) + assertStringIsOriginal(t, (t4UnsafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, true, originalData4S) } - originalData4S, err := t4OrigS.MarshalVT() - require.NoError(t, err) - - t4SafeS := &UnsafeTest{} - require.NoError(t, t4SafeS.UnmarshalVT(originalData4S)) - assert.Equal(t, (t4OrigS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, (t4SafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S) - assertStringIsOriginal(t, (t4SafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, false, originalData4S) - - t4UnsafeS := &UnsafeTest{} - require.NoError(t, t4UnsafeS.UnmarshalVTUnsafe(originalData4S)) - assert.Equal(t, (t4OrigS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, (t4UnsafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S) - assertStringIsOriginal(t, (t4UnsafeS.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_S).S, true, originalData4S) t4OrigB := &UnsafeTest{ Sub: &UnsafeTest_Sub4_{ @@ -165,4 +170,36 @@ func Test_UnmarshalVTUnsafe(t *testing.T) { require.NoError(t, t4UnsafeB.UnmarshalVTUnsafe(originalData4B)) assert.Equal(t, (t4OrigB.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_B).B, (t4UnsafeB.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_B).B) assertBytesAreOriginal(t, (t4UnsafeB.Sub).(*UnsafeTest_Sub4_).Sub4.Foo.(*UnsafeTest_Sub4_B).B, true, originalData4B) + + // map[string]string field + for _, stringVal := range []string{ + testString, + "", + } { + t5Orig := &UnsafeTest{ + Sub: &UnsafeTest_Sub5_{ + Sub5: &UnsafeTest_Sub5{ + Foo: map[string]string{testString: stringVal}, + }, + }, + } + originalData5, err := t5Orig.MarshalVT() + require.NoError(t, err) + + t5Safe := &UnsafeTest{} + require.NoError(t, t5Safe.UnmarshalVT(originalData5)) + assert.Equal(t, (t5Orig.Sub).(*UnsafeTest_Sub5_).Sub5.Foo, (t5Safe.Sub).(*UnsafeTest_Sub5_).Sub5.Foo) + for k, v := range (t5Safe.Sub).(*UnsafeTest_Sub5_).Sub5.Foo { + assertStringIsOriginal(t, k, false, originalData5) + assertStringIsOriginal(t, v, false, originalData5) + } + + t5Unsafe := &UnsafeTest{} + require.NoError(t, t5Unsafe.UnmarshalVTUnsafe(originalData5)) + assert.Equal(t, (t5Orig.Sub).(*UnsafeTest_Sub5_).Sub5.Foo, (t5Unsafe.Sub).(*UnsafeTest_Sub5_).Sub5.Foo) + for k, v := range (t5Unsafe.Sub).(*UnsafeTest_Sub5_).Sub5.Foo { + assertStringIsOriginal(t, k, true, originalData5) + assertStringIsOriginal(t, v, true, originalData5) + } + } } diff --git a/testproto/unsafe/unsafe_vtproto.pb.go b/testproto/unsafe/unsafe_vtproto.pb.go index 5126407..5b87df2 100644 --- a/testproto/unsafe/unsafe_vtproto.pb.go +++ b/testproto/unsafe/unsafe_vtproto.pb.go @@ -138,6 +138,29 @@ func (m *UnsafeTest_Sub4_B) CloneVT() isUnsafeTest_Sub4_Foo { return r } +func (m *UnsafeTest_Sub5) CloneVT() *UnsafeTest_Sub5 { + if m == nil { + return (*UnsafeTest_Sub5)(nil) + } + r := new(UnsafeTest_Sub5) + if rhs := m.Foo; rhs != nil { + tmpContainer := make(map[string]string, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.Foo = tmpContainer + } + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *UnsafeTest_Sub5) CloneMessageVT() proto.Message { + return m.CloneVT() +} + func (m *UnsafeTest) CloneVT() *UnsafeTest { if m == nil { return (*UnsafeTest)(nil) @@ -193,6 +216,15 @@ func (m *UnsafeTest_Sub4_) CloneVT() isUnsafeTest_Sub { return r } +func (m *UnsafeTest_Sub5_) CloneVT() isUnsafeTest_Sub { + if m == nil { + return (*UnsafeTest_Sub5_)(nil) + } + r := new(UnsafeTest_Sub5_) + r.Sub5 = m.Sub5.CloneVT() + return r +} + func (this *UnsafeTest_Sub1) EqualVT(that *UnsafeTest_Sub1) bool { if this == that { return true @@ -339,6 +371,34 @@ func (this *UnsafeTest_Sub4_B) EqualVT(thatIface isUnsafeTest_Sub4_Foo) bool { return true } +func (this *UnsafeTest_Sub5) EqualVT(that *UnsafeTest_Sub5) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if len(this.Foo) != len(that.Foo) { + return false + } + for i, vx := range this.Foo { + vy, ok := that.Foo[i] + if !ok { + return false + } + if vx != vy { + return false + } + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *UnsafeTest_Sub5) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*UnsafeTest_Sub5) + if !ok { + return false + } + return this.EqualVT(that) +} func (this *UnsafeTest) EqualVT(that *UnsafeTest) bool { if this == that { return true @@ -465,6 +525,31 @@ func (this *UnsafeTest_Sub4_) EqualVT(thatIface isUnsafeTest_Sub) bool { return true } +func (this *UnsafeTest_Sub5_) EqualVT(thatIface isUnsafeTest_Sub) bool { + that, ok := thatIface.(*UnsafeTest_Sub5_) + if !ok { + return false + } + if this == that { + return true + } + if this == nil && that != nil || this != nil && that == nil { + return false + } + if p, q := this.Sub5, that.Sub5; p != q { + if p == nil { + p = &UnsafeTest_Sub5{} + } + if q == nil { + q = &UnsafeTest_Sub5{} + } + if !p.EqualVT(q) { + return false + } + } + return true +} + func (m *UnsafeTest_Sub1) MarshalVT() (dAtA []byte, err error) { if m == nil { return nil, nil @@ -685,6 +770,58 @@ func (m *UnsafeTest_Sub4_B) MarshalToSizedBufferVT(dAtA []byte) (int, error) { dAtA[i] = 0x12 return len(dAtA) - i, nil } +func (m *UnsafeTest_Sub5) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UnsafeTest_Sub5) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *UnsafeTest_Sub5) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.Foo) > 0 { + for k := range m.Foo { + v := m.Foo[k] + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *UnsafeTest) MarshalVT() (dAtA []byte, err error) { if m == nil { return nil, nil @@ -803,6 +940,25 @@ func (m *UnsafeTest_Sub4_) MarshalToSizedBufferVT(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } +func (m *UnsafeTest_Sub5_) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *UnsafeTest_Sub5_) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Sub5 != nil { + size, err := m.Sub5.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} func (m *UnsafeTest_Sub1) MarshalVTStrict() (dAtA []byte, err error) { if m == nil { return nil, nil @@ -1028,6 +1184,58 @@ func (m *UnsafeTest_Sub4_B) MarshalToSizedBufferVTStrict(dAtA []byte) (int, erro dAtA[i] = 0x12 return len(dAtA) - i, nil } +func (m *UnsafeTest_Sub5) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UnsafeTest_Sub5) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *UnsafeTest_Sub5) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.Foo) > 0 { + for k := range m.Foo { + v := m.Foo[k] + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *UnsafeTest) MarshalVTStrict() (dAtA []byte, err error) { if m == nil { return nil, nil @@ -1058,6 +1266,13 @@ func (m *UnsafeTest) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if msg, ok := m.Sub.(*UnsafeTest_Sub5_); ok { + size, err := msg.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + } if msg, ok := m.Sub.(*UnsafeTest_Sub4_); ok { size, err := msg.MarshalToSizedBufferVTStrict(dAtA[:i]) if err != nil { @@ -1165,6 +1380,25 @@ func (m *UnsafeTest_Sub4_) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error } return len(dAtA) - i, nil } +func (m *UnsafeTest_Sub5_) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *UnsafeTest_Sub5_) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Sub5 != nil { + size, err := m.Sub5.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} func (m *UnsafeTest_Sub1) SizeVT() (n int) { if m == nil { return 0 @@ -1257,6 +1491,24 @@ func (m *UnsafeTest_Sub4_B) SizeVT() (n int) { n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) return n } +func (m *UnsafeTest_Sub5) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Foo) > 0 { + for k, v := range m.Foo { + _ = k + _ = v + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + 1 + len(v) + protohelpers.SizeOfVarint(uint64(len(v))) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + n += len(m.unknownFields) + return n +} + func (m *UnsafeTest) SizeVT() (n int) { if m == nil { return 0 @@ -1318,6 +1570,18 @@ func (m *UnsafeTest_Sub4_) SizeVT() (n int) { } return n } +func (m *UnsafeTest_Sub5_) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sub5 != nil { + l = m.Sub5.SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + return n +} func (m *UnsafeTest_Sub1) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1845,7 +2109,7 @@ func (m *UnsafeTest_Sub4) UnmarshalVT(dAtA []byte) error { } return nil } -func (m *UnsafeTest) UnmarshalVT(dAtA []byte) error { +func (m *UnsafeTest_Sub5) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1868,15 +2132,15 @@ func (m *UnsafeTest) UnmarshalVT(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: UnsafeTest: wiretype end group for non-group") + return fmt.Errorf("proto: UnsafeTest_Sub5: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: UnsafeTest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: UnsafeTest_Sub5: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sub1", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1903,33 +2167,211 @@ func (m *UnsafeTest) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if oneof, ok := m.Sub.(*UnsafeTest_Sub1_); ok { - if err := oneof.Sub1.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - v := &UnsafeTest_Sub1{} - if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sub = &UnsafeTest_Sub1_{Sub1: v} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sub2", wireType) + if m.Foo == nil { + m.Foo = make(map[string]string) } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protohelpers.ErrIntOverflow - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Foo[mapkey] = mapvalue + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UnsafeTest) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UnsafeTest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UnsafeTest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sub1", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if oneof, ok := m.Sub.(*UnsafeTest_Sub1_); ok { + if err := oneof.Sub1.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + } else { + v := &UnsafeTest_Sub1{} + if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sub = &UnsafeTest_Sub1_{Sub1: v} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sub2", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2038,6 +2480,47 @@ func (m *UnsafeTest) UnmarshalVT(dAtA []byte) error { m.Sub = &UnsafeTest_Sub4_{Sub4: v} } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sub5", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if oneof, ok := m.Sub.(*UnsafeTest_Sub5_); ok { + if err := oneof.Sub5.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + } else { + v := &UnsafeTest_Sub5{} + if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sub = &UnsafeTest_Sub5_{Sub5: v} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:]) @@ -2581,6 +3064,184 @@ func (m *UnsafeTest_Sub4) UnmarshalVTUnsafe(dAtA []byte) error { } return nil } +func (m *UnsafeTest_Sub5) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UnsafeTest_Sub5: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UnsafeTest_Sub5: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Foo == nil { + m.Foo = make(map[string]string) + } + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = unsafe.String(&dAtA[iNdEx], intStringLenmapkey) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + mapvalue = unsafe.String(&dAtA[iNdEx], intStringLenmapvalue) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Foo[mapkey] = mapvalue + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *UnsafeTest) UnmarshalVTUnsafe(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -2774,6 +3435,47 @@ func (m *UnsafeTest) UnmarshalVTUnsafe(dAtA []byte) error { m.Sub = &UnsafeTest_Sub4_{Sub4: v} } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sub5", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if oneof, ok := m.Sub.(*UnsafeTest_Sub5_); ok { + if err := oneof.Sub5.UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + } else { + v := &UnsafeTest_Sub5{} + if err := v.UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sub = &UnsafeTest_Sub5_{Sub5: v} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:])