Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonConvert.DeserializeObject can throw several unexpected exceptions #1947

Open
Metalnem opened this issue Dec 25, 2018 · 1 comment
Open

Comments

@Metalnem
Copy link

Metalnem commented Dec 25, 2018

JsonConvert.DeserializeObject can throw several unexpected exceptions (JsonReaderException is the one that is usually expected). These are:

  • ArgumentException
  • JsonSerializationException
  • JsonWriterException
  • NullReferenceException

Documentation doesn't say anything about this, but deserialization is definitely weird place for a JsonWriterException. ArgumentException and NullReferenceException should not be possible in my opinion (if the input strings are non-empty). Here is the complete program to reproduce all of this:

using System;

namespace Newtonsoft.Json.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      try
      {
        JsonConvert.DeserializeObject("[{\"click\":\"X\",\"Close()\"://[{\"click\":\"Kpen()\"},{\"cOOOOOOOOOO\u007f]}}}");
      }
      catch (ArgumentException) { }

      try
      {
        JsonConvert.DeserializeObject("{\"menu\":{\"id\":1,\"val\":\"X\",\"pop\":{\"a\":[{\"click\":\"Open()\"},{\"click\":\"Close()\"}]}}");
      }
      catch (JsonSerializationException) { }

      try
      {
        JsonConvert.DeserializeObject("{\"menu\":{\"id\":1,\"val\":\"X\",\"pop\":{\"a\":[{\"clicT\":\"Open()\"},");
      }
      catch (JsonWriterException) { }

      try
      {
        JsonConvert.DeserializeObject("[new\0([");
      }
      catch (NullReferenceException) { }
    }
  }
}

Found via SharpFuzz.

@AaronJThompson
Copy link

The last 3 seem to have been fixed. However, the first one now throws the error:
Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.
Which I presume is still a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants