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 · 0 comments
Open

JsonConvert.DeserializeObject can throw several unexpected exceptions #1947

Metalnem opened this issue Dec 25, 2018 · 0 comments

Comments

@Metalnem
Copy link

@Metalnem 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.

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

Successfully merging a pull request may close this issue.

None yet
1 participant