zf8848 / protobuf

Automatically exported from code.google.com/p/protobuf
Other
0 stars 0 forks source link

String corruption #655

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am seeing an issue with string corruption under very specific circumstances.

My Proto file:

message MyMessage
{
   required int32 field1 = 1;
   enum MyEnum
   {
      ENUM_0 = 0; 
      ENUM_1 = 1; 
      ENUM_2 = 2; 
      ENUM_3 = 3; 
   }
   optional MyEnum field2 = 2;
   optional string field3 = 3;
   optional string field4 = 4;
   optional string field5 = 5;
   optional string field6 = 6;
   optional string field7 = 7;
   optional string field8 = 8;
   optional string field9 = 9;
   message MySubMessage
   {
      required float field1 = 1;
      required string field2 = 2;
   }
   repeated MySubMessage field10 = 10;
}

I fill in the message with the following values:
field1 = 1
field2 = ENUM_3
field3 = "ccccccccbaaaaaa"
field4 = "ccccccccbaaaaaab"
field5 = "ccccccccbaaaaaa"
field6 = "ccccccccbaaaaaab"
field7 = "ccccccccbaaaaa"
field8 = "ccccccccbaaaaaabbbb"
field9 = "ddddd"
field10.field1 = 0.91629
field10.field2 = "aaabcccccc"

All of the strings are set using the char* setter. I check the values after 
adding them and they look good. I then serialize the message and call 
ParseFromArray to de-serialize.

When I check the values, field3 has been corrupted and comes out as "▒ckk".

If i change the length of field3 to be one more or one less character it works 
fine. I went down the list of subsequent string fields and tried changing the 
length of each and it appears to solve the problem as well.

I am using protobuf 2.5 with GCC and running on QNX 6.4.1

Original issue reported on code.google.com by Simon...@gmail.com on 11 Jul 2014 at 1:41

GoogleCodeExporter commented 9 years ago
I realized that this issue was being caused by me calling 
ParseFromArray(message_body, body_size) with a body_size that was bigger than 
the actual message. It manifested itself in a very strange way. I guess I would 
not have expected issues with a string in the middle of the message. You can 
close this.

Original comment by Simon...@gmail.com on 4 Sep 2014 at 2:20

GoogleCodeExporter commented 9 years ago

Original comment by liujisi@google.com on 4 Sep 2014 at 5:29