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

DataContractJsonSerializer.ReadObject throws IndexOutOfRangeException #1410

Closed
Metalnem opened this issue Feb 9, 2019 · 5 comments
Closed

Comments

@Metalnem
Copy link

Metalnem commented Feb 9, 2019

DataContractJsonSerializer.ReadObject sometimes throws IndexOutOfRangeException. Here's the full program that reproduces this:

using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;

namespace CoreFX.Fuzz
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var json = @"{""a"":N2,]}";
      var bytes = Encoding.UTF8.GetBytes(json);
      var stream = new MemoryStream(bytes);
      var serializer = new DataContractJsonSerializer(typeof(object));

      serializer.ReadObject(stream);
    }
  }
}

The stack trace:

Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in System.Private.DataContractSerialization.dll: 'Index was outside the bounds of the array.'
   at System.Runtime.Serialization.Json.XmlJsonReader.ExitJsonScope()
   at System.Runtime.Serialization.Json.XmlJsonReader.Read()
   at System.Xml.XmlBaseReader.ReadEndElement()
   at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
   at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
   at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract)
   at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
   at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
   at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.ReadObject(XmlDictionaryReader reader)
   at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.ReadObject(Stream stream)
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream)

The environment:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.103
 Commit:    8edbc2570a

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.2.103/

Found via SharpFuzz.

@Lxiamail
Copy link
Member

Lxiamail commented Apr 3, 2019

We should throw a different exception other than IndexOutOfRangeException. However, due to the issue is not reported by real world scenario, this is lower priority issue.

@StephenBonikowsky StephenBonikowsky transferred this issue from dotnet/corefx Jan 7, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Serialization untriaged New issue has not been triaged by the area owner labels Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added this to the Future milestone Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added this to Future P2 (Backlog) in WCF Owned Areas Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added bug and removed untriaged New issue has not been triaged by the area owner labels Jan 7, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@StephenBonikowsky StephenBonikowsky removed the untriaged New issue has not been triaged by the area owner label Feb 28, 2020
@StephenBonikowsky
Copy link
Member

@imcarolwang Another issue that your team can look into fixing.

@StephenBonikowsky StephenBonikowsky removed this from the Future milestone Mar 5, 2020
@HongGit HongGit added this to the Future milestone Jul 1, 2020
@imcarolwang
Copy link
Contributor

The program throws the same IndexOutOfRangeException when running on .NetFramework project.

@HongGit
Copy link
Contributor

HongGit commented Oct 8, 2020

@Metalnem this does not seem to be a regression from .NET Framework. If you still need us to investigate further, please provide a repro app.

@HongGit HongGit closed this as completed Oct 8, 2020
WCF Owned Areas automation moved this from Future P2 (Backlog) to Completed Oct 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 2020
@danmoseley
Copy link
Member

it's OK to not fix this, but just noting that the repro app is the code above. I just ran it against 6.0 and it produced this result.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

8 participants