Skip to content

RUST-882 Fix lossy From<u32> Bson impl, prevent overflow in From<u64> (1.2.x) #281

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 3 commits into from
Jul 23, 2021

Conversation

patrickfreed
Copy link
Contributor

RUST-882

This is the 1.2.x backport fix of RUST-882.

fn from(a: u64) -> Bson {
Bson::Int64(a as i64)
Bson::Int64(a.try_into().unwrap_or(i64::MAX))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for lack of a better option, I tried to make this "less bad", but short of panicking I'm not sure we have any other choice. I'm hesitant to panic given that we can't even deprecate this impl though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that this is the less-bad option.

fn from(a: u64) -> Bson {
Bson::Int64(a as i64)
Bson::Int64(a.try_into().unwrap_or(i64::MAX))
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that this is the less-bad option.

@patrickfreed patrickfreed force-pushed the RUST-882/fix-lossy-1.2.x branch from 74f8dbf to 21b5ec5 Compare July 23, 2021 16:27
@patrickfreed patrickfreed merged commit e81ffef into mongodb:1.2.x Jul 23, 2021
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.

3 participants