Protobuf空重复字段导致ParseFromArray崩溃

时间:2019-01-31 20:56:29

标签: c++ protocol-buffers

当我的接收代码使用ParseFromArray解码protobuf消息时,发生以下崩溃:

Thread 0 Crashed:: Main Thread Dispatch queue: com.apple.main-thread
0 org.chromium.ContentShell.framework 0x00000001107ef955 0x1106e1000 + 1108309
1 org.chromium.ContentShell.framework 0x000000011082e312 0x1106e1000 + 1364754
2 libsystem_malloc.dylib 0x00007fff7ddaf1bd malloc_zone_malloc + 103
3 libsystem_malloc.dylib 0x00007fff7ddae4c7 malloc + 24
4 libc++abi.dylib 0x00007fff7bbac628 operator new(unsigned long) + 40
5 libc++.1.dylib 0x00007fff7bb90aae std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
>::__grow_by_and_replace(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, char const*) + 142
6 libc++.1.dylib 0x00007fff7bb90973 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
>::append(char const*, unsigned long) + 105
7 libprotobuf-lite.17.dylib 0x00000003c20a0bd7
google::protobuf::io::CodedInputStream::ReadStringFallback(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
>*, int) + 999
8 libprotobuf-lite.17.dylib 0x00000003c209e893
google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >*) + 467
9 com.aa.am 0x0000000467ae7a9e
ClientAudio::equip_info::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) + 382
10 com.aa.am 0x0000000467ae864a
ClientAudio::msg_conn_rsp::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) + 714
11 com.aa.am 0x0000000467af22dc
ClientAudio::msg_base::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) + 2252
12 libprotobuf-lite.17.dylib 0x00000003c2098f36 google::protobuf::MessageLite::ParseFromArray(void const*, int) + 182
13 com.aa.am 0x0000000467af5813 Session::messageReceived(

相关的protobuf(proto3)消息:

message equip_info {
int32 id = 1;
string end_time = 2;
}

message msg_conn_rsp {
bool granted = 1;
string info = 2;
repeated equip_info equip_list = 3;
}

message msg_base {
enum id_e {
...
CONN_RSP = 1;
...
}
id_e id = 1;

oneof sub_msg {
...
msg_conn_rsp conn_rsp = 3;
...
}

}

在此崩溃的情况下,发件人不会设置equip_list(从不调用add_)。我希望它是默认值(空)。不允许吗?

0 个答案:

没有答案