-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Panic if NaN is passed to
Duration
constructors
- Loading branch information
Showing
2 changed files
with
8 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,9 @@ impl Duration { | |
if seconds > i64::MAX as f64 || seconds < i64::MIN as f64 { | ||
crate::expect_failed("overflow constructing `time::Duration`"); | ||
} | ||
if seconds.is_nan() { | ||
crate::expect_failed("passed NaN to `time::Duration::seconds_f64`"); | ||
} | ||
Self::new_unchecked(seconds as _, ((seconds % 1.) * 1_000_000_000.) as _) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jhpratt
Author
Member
|
||
} | ||
|
||
|
@@ -337,6 +340,9 @@ impl Duration { | |
if seconds > i64::MAX as f32 || seconds < i64::MIN as f32 { | ||
crate::expect_failed("overflow constructing `time::Duration`"); | ||
} | ||
if seconds.is_nan() { | ||
crate::expect_failed("passed NaN to `time::Duration::seconds_f32`"); | ||
} | ||
Self::new_unchecked(seconds as _, ((seconds % 1.) * 1_000_000_000.) as _) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FWIW, I believe casting
NAN
to an integer was UB in Rust before 1.45.0:It looks like the 0.2 branch of
time
has this same uncheckedas
cast:time/src/duration.rs
Line 459 in d26562b
and its MSRV appears to be In the Rust 1.32 range:
time/.github/workflows/build.yaml
Line 11 in d26562b
I'm not sure if you want to, but I think it might be prudent to file a RustSec advisory for time 0.2.x.