Conerlius / protobuf-net

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

Exception occurs on desrialization of string with length greater than 127 #193

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
1. Create a ProtoContract class with one string type public member.
2. Create an object of the class and set the member string a value with length 
greather than 127.
3. Serialize and Deserialize the object.

What is the expected output? What do you see instead?
Serialized and deserialized objects' member should contain same string values.
Instead the deserialization throws an "Attempted to read past the end of the 
stream" exception.

What version of the product are you using? On what operating system?
I am using NET30 revision 282. On Windows 7.

Please provide any additional information below.
I am attaching this small form based application, for your quick reference, to 
reproduce the error. You will have to click on "Test Prefilled" button to see 
the error.

Original issue reported on code.google.com by san.ar...@gmail.com on 24 Jun 2011 at 9:11

Attachments:

GoogleCodeExporter commented 8 years ago
This test is invalid. The output of a protobuf serialization is ***not*** 
string data, so you *cannot* use UTF8 to create a string from them. That is 
using a string encoding the wrong way around. If you need to create a string 
from protobuf, use base-64, i.e.

result = Convert.ToBase64String(Result, 0, streamLength);

and

MemoryStream mm = new MemoryStream(Convert.FromBase64String(serializedText));

Original comment by marc.gravell on 24 Jun 2011 at 9:33

GoogleCodeExporter commented 8 years ago
Yes, you are right. It works for me after making it to Base64.
Sorry, my bad for not reading the BinaryFormatter implementation and posted 
this.
Many thanks to you for quickly identifying the mistake. 

Regards
Sanjeev

Original comment by san.ar...@gmail.com on 24 Jun 2011 at 10:20

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 24 Jun 2011 at 10:41