Issue with Newtonsoft.Json.Bson.BsonReader.GetString

Jul 12, 2010 at 10:50 PM
Edited Jul 12, 2010 at 10:54 PM

There seems to be an issue with the GetString method with greek strings over 128 bytes long. 

The following object: 

 

  {

    "EntryDate": "\/Date(1278936490955+0300)\/",
    "SerializableNotes": "ΕΝΤΟΛΗ ΧΧΧ ΧΧΧΧΧΧΧΧΧ ΤΑ ΠΡΩΤΑΣΦΑΛΙΣΤΗΡΙΑ ΠΟΥ ΔΕΝ ΕΧΟΥΝ ΥΠΟΛΟΙΠΟ ΝΑ ΤΑ ΣΤΕΛΝΟΥΜΕ ΑΠΕΥΘΕΙΑΣ ΣΤΟΥΣ ΠΕΛΑΤΕΣ"
  }

when serialized in bson will always throw an exception when I try to deserialize it. While the serialization works as expected (190 bytes length + 1) when deserializing the length
is not calculated correctly and as a result it takes the trailing x0 (null char) into the buffer. I was not able to pin-point the problem but my naive solution was to change the GetString 
implementation into : 
    private string GetString(int length)
    {
      if (length == 0)
        return string.Empty;

      EnsureBuffers();

      byte[] buf = new byte[length];
       _reader.BaseStream.Read(buf, 0, length);
      return new string(Encoding.UTF8.GetChars(buf));
    }

which seems to work (at least according to both the supplied and my project's unit tests).

Any ideas ?

Regards,
Tasos
Jul 23, 2010 at 8:32 AM

I debugged this problem and submitted a patch several weeks ago:

 http://json.codeplex.com/workitem/18126

It is a pretty serious bug.  It occurs with any multibyte characters, not just foreign languages.  At least one other person encountered it:

  http://json.codeplex.com/Thread/View.aspx?ThreadId=218611

James, will there be an official update any time soon?

Coordinator
Jul 26, 2010 at 3:32 AM

Yes