Skip to content

Accept ints as doubles in Bson inputs #413

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

Merged
merged 2 commits into from
Mar 21, 2022

Conversation

pulewicz
Copy link
Contributor

@pulewicz pulewicz commented Mar 18, 2022

Just a draft, I'm not sure it's a good approach.

Ready for review now.

@ghik
Copy link
Contributor

ghik commented Mar 18, 2022

Hi,

I'm fine with reading INT32 as Double since every Int value fits into a Double. This is not the case with INT64 though - reading it as Double is not safe.

There are two approaches we can take here:

  • only allow DOUBLE and INT32 BSON types in readDouble()
  • allow other types like INT64 and DECIMAL128 but validate whether the value is a valid Double, throw exception otherwise

However, in each approach we need to look at other readX() methods and change them accordingly in order to make the behaviour of these Inputs consistent. For example, if we're accepting INT32 when reading Double, we should probably also accept INT32 and INT64 when reading BigDecimal.

If sufficient, the first approach would be preferable by me because it's much simpler to implement. Taking the second approach, i.e. making the Input implementation as lenient as possible while keeping it as safe as possible would be nice but also probably complex to implement due to the necessity of thorough validation of runtime values.

Thanks,
Roman

@pulewicz pulewicz force-pushed the accept-bson-ints-as-doubles branch 2 times, most recently from 2c6efb3 to 65c8e78 Compare March 20, 2022 16:16
@pulewicz
Copy link
Contributor Author

I'm also fine with the first approach. I updated the code to disallow Int64, I also added a test for BsonBinaryReader.

@pulewicz pulewicz force-pushed the accept-bson-ints-as-doubles branch from 65c8e78 to 6d2bf0f Compare March 20, 2022 16:20
@pulewicz pulewicz marked this pull request as ready for review March 20, 2022 16:23
@ghik ghik merged commit 3cad3bc into AVSystem:master Mar 21, 2022
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