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

Fix soundness bug in NotNan::cmp. #151

Merged
merged 1 commit into from
Jun 29, 2024
Merged

Fix soundness bug in NotNan::cmp. #151

merged 1 commit into from
Jun 29, 2024

Conversation

mbrubeck
Copy link
Collaborator

@mbrubeck mbrubeck commented Jun 29, 2024

Ill-behaved FloatCore implementations for user types could have x.partial_cmp(&x) == None even when x.is_nan() == false. This crate will now panic in those cases, rather than execute undefined behavior.

Fixes #150.

@mbrubeck mbrubeck force-pushed the partial_cmp branch 3 times, most recently from 712389b to 37cd73b Compare June 29, 2024 19:27
@mbrubeck
Copy link
Collaborator Author

Unfortunately this may cause a performance regression, but I don't think there is an alternative that is both sound and backward-compatible. The regression could be fixed if impl specialization were available on stable Rust.

@mbrubeck mbrubeck force-pushed the partial_cmp branch 2 times, most recently from 315ab14 to 9593cb8 Compare June 29, 2024 19:34
Ill-behaved FloatCore implementations for user types could have
`x.partial_cmp(&x) == None` even when `x.is_nan() == false`.  This crate
will now panic in those cases, rather than execute undefined behavior.

Fixes #150.
@mbrubeck mbrubeck merged commit 06b03f7 into master Jun 29, 2024
4 checks passed
@mbrubeck mbrubeck changed the title Fix soundness bug in NotNan::partial_cmp. Fix soundness bug in NotNan::cmp. Jun 29, 2024
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.

Implementation of NotNan::cmp is unsound
1 participant