OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
687 stars 349 forks source link

Stackoverflow Exception when resolving `Partners` in OData contract (xml) #3114

Closed adeel2023 closed 2 days ago

adeel2023 commented 1 week ago

Parsing the attached OData contract/metadata XML file (attached as .txt file) leads to Stack overflow exception when traversing Partners. The file has complex Navigation props. structure and If all the NavigationProperty tags from the first EntityType User are removed, the file is parsed without errors.

SOE-OData-xml.txt

Assemblies affected

Initially observed on Microsoft.OData.Edm, v7.21.1 but also exists on the latest v8.0.1

Reproduce steps

Read the attached-xml file's contents and invoke CsdlReader.TryParse(...) method.

Expected result

OData contract should be parsed without errors or any errors, if encountered, should be reported gracefully rather than SOE.

Actual result

Stackoverflow exception is thrown out of CsdlSemanticsNavigationProperty.ComputePartner() every single time. A part of recursive stacktrace is given below:

 at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty.get_Partner()
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty.ComputePartner()
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty+<>c.<.cctor>b__45_1(Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty)
   at Microsoft.OData.Edm.Cache`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetValue(System.__Canon, System.Func`2<System.__Canon,System.__Canon>, System.Func`2<System.__Canon,System.__Canon>)
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty.get_Partner()
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty.ComputePartner()
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty+<>c.<.cctor>b__45_1(Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationProperty)
   at Microsoft.OData.Edm.Cache`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetValue(System.__Canon, System.Func`2<System.__Canon,System.__Canon>, System.Func`2<System.__Canon,System.__Canon>)

[Stacktrace goes on further repeating the same output]