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

Handle number overflow during parsing of min/max values #1480

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

Robulane
Copy link
Contributor

Sometimes developers put Double.MaxValue or Long.MaxValue asmax values for numbers in json schema, even if their numbers are not expected to be that big/small. As we have already released the library with Decimal type for Max/Min, let's not introduce the breaking change and just fallback to Decimal.Max / Min in case of overflow. This should satisfy almost every scenario. We can revisit this if somebody really needs to have double or long here.

Fixing this exception stacktrace

ExceptionType: System.OverflowException
ExceptionMessage: Value was either too large or too small for a Decimal.
InnerExceptionType:
InnerExceptionMessage:
StackTrace:
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.<>c.<.cctor>b__83_141(OpenApiSchema o, ParseNode n)
at Microsoft.OpenApi.Readers.ParseNodes.PropertyNode.ParseField[T](T parentInstance, IDictionary2 fixedFields, IDictionary2 patternFields)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.LoadSchema(ParseNode node)
at Microsoft.OpenApi.Readers.ParseNodes.MapNode.<>c__DisplayClass6_01.<CreateMap>b__0(KeyValuePair2 n)
at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.<>c.<.cctor>b__83_158(OpenApiSchema o, ParseNode n)
at Microsoft.OpenApi.Readers.ParseNodes.PropertyNode.ParseField[T](T parentInstance, IDictionary2 fixedFields, IDictionary2 patternFields)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.LoadSchema(ParseNode node)
at Microsoft.OpenApi.Readers.V2.OpenApiV2VersionService.LoadElement[T](ParseNode node)
at Microsoft.OpenApi.Readers.ParsingContext.ParseFragment[T](YamlDocument yamlDocument, OpenApiSpecVersion version)
at Microsoft.OpenApi.Readers.OpenApiYamlDocumentReader.ReadFragment[T](YamlDocument input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)
at Microsoft.OpenApi.Readers.OpenApiTextReaderReader.ReadFragment[T](TextReader input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)
at Microsoft.OpenApi.Readers.OpenApiStringReader.ReadFragment[T](String input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

@baywet baywet merged commit d06a89d into microsoft:vnext Nov 22, 2023
6 checks passed
pull bot pushed a commit to intensifier/Power-Fx that referenced this pull request Nov 22, 2023
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

Successfully merging this pull request may close these issues.

2 participants