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

Crash when parse very long negative values #339

Closed
abraaocaldas opened this issue Aug 4, 2020 · 3 comments · Fixed by #342
Closed

Crash when parse very long negative values #339

abraaocaldas opened this issue Aug 4, 2020 · 3 comments · Fixed by #342
Assignees
Labels

Comments

@abraaocaldas
Copy link

Hello,

Using Parse.Netstandard version 2.0.0

Parse server version 4.3.0

When you set a very long negative value Ex: -9223372036854776000 , the .Net SDK version is not able to retrieve the value and crash when it tries to deserealize the value.

I tested this way, Steps:

  1. created a parse object using Parse Android SDK

parseObject.put("badColumn", -9223372036854776000)

  1. Saved the object

parseObject.save()

  1. Object is saved on DB (I checked it at mongoDB)

  2. Tried to retrieve the Object on .NET Parse SDK
    ParseObject.findAsync().....

Got the exception:

System.OverflowException
  HResult=0x80131516
  Message=Value was either too large or too small for an Int64.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.Number.ParseInt64(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
   at System.Int64.Parse(String s)

I think C# don't support this kind of value, then instead of using a Int64 or long value it's best to use a BigInteger or something similar.

Best Regards

@TobiasPott
Copy link
Member

Hi @abraaocaldas

I checked your issue a while ago already but didn't had the time to respond.
You are right that the current state of the SDK does not convert long integer values to a corresponding type.

However I do not see a solution in using the BitInteger type but checking for the value range exceeding the 64 bit of a long and use double in that case which allows a significantly higher value range and which is the type allowing users to put such high values into objects on a parse server using the .NET SDK.

Although you are right BitInteger would allow such values as in your example, I'm not sure about the implications it would have on the SDK and would keep it in mind to extend the parsing of retrieved values to check for exceeding the double type value range and fallback on BitInteger.
The Android reference provides information about the different numerical types in the Android Java language and the long type there is restricted to 64 bits as the one in .NET. Thus I assume that the value you saved with the Android SDK is not considered an integer by the runtime/platform but a double. The Double type on the Android platform would support much larger values (not sure if the ranges match the .NET double value range but they are more close together than long and double (on neither platform).

thus my assumption is that we lack the check for the value range and a conversion to double to support the value in your example (or larger values than long supports in general).

@TobiasPott
Copy link
Member

Hi @abraaocaldas
Can I ask you to check out the https://github.com/TobiasPott/Parse-SDK-dotNET/tree/feature/fix-conversion-error-of-double-type-range-values-to-long-type feature branch of my forked repo. I've changed the conversion of numeric values to include said conversion to double type if conversion to long fails.

In my test project using the value you provided it works again and I need to add test cases for that later on but want to make sure I've targeted your issue correctly.

@mtrezza
Copy link
Member

mtrezza commented May 24, 2024

Closing via #342

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

Successfully merging a pull request may close this issue.

3 participants