taohyson / protobuf-net

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

(De/)Serialization of Byte Array Appends Erroneous Zero #433

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
zak.klajda@gmail.com

Byte arrays seem to improperly deserialize.  It adds approximately one byte per 
deserialization.  Will add one new (zero) byte to the array each time the data 
is re-serialized and again deserialized.

==============

What steps will reproduce the problem?
1. Run the attached project.
2. Note the Debug.Asserts -- three of which will fire, one will not.
3. Profit!

What is the expected output? What do you see instead?
The expected output is a restored BigInteger on the receiving end that matches 
the sending end-- but the bytes restored by the deserializer and passed into 
the setter are incorrect in length and (one) value.

What version of the product are you using? On what operating system?
2.0.0.668 on Win7

Please provide any additional information below.
I saw issue 271, which suggested that this can be "corrected" by supplying the 
OverwriteList option to the ProtoMember attribute.  While this prevents the 
extra bytes from being appended, this shouldn't be necessary as the arrays are 
not initialized in any constructor.  Appension should not be occurring as there 
is nothing to append *to*.

Original issue reported on code.google.com by TheMaske...@gmail.com on 4 Mar 2014 at 3:34

Attachments:

GoogleCodeExporter commented 8 years ago
I just revisited the code and poked around more-- it is specific to the 
BigInteger ToByteArray.  It returns that zero-array because the BigInteger is 
zero by default, even if uninitialized.

Requiring the OverwriteList still seems counter-intuitive and I believe it 
would be better to have OverwriteList be the default and AppendList (or 
something like it) be specified.  However, this issue can probably be closed if 
that isn't a desired design direction.

Original comment by TheMaske...@gmail.com on 4 Mar 2014 at 5:09

GoogleCodeExporter commented 8 years ago
Re OverwriteList vs AppendList: it is a specific part of the Google protobuf 
specification that appending two buffers performs a merge, which for lists 
means: append. It is therefore required that append is the default.

Original comment by marc.gravell on 4 Mar 2014 at 7:50