Uh oh!
There was an error while loading. Please reload this page.
Implement checked_add_duration for SystemTime - #55527
Conversation
rust-highfive
commented
Oct 31, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
0a87de2 to
3aced4cComparesgeisler
commented
Oct 31, 2018
I just noticed that I also need to make make |
3aced4c to
dd605a1Comparesgeisler
commented
Nov 2, 2018
I think the PR is ready for review/an automated all-platforms test run. Is there an easy way to just try to compile it on all platforms? |
Uh oh!
There was an error while loading. Please reload this page.
687eac9 to
52ba35dComparerust-highfive
commented
Nov 5, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
52ba35d to
74d7fbaCompareUh oh!
There was an error while loading. Please reload this page.
sfackler
commented
Nov 13, 2018
LGTM with the issue number changed! |
74d7fba to
8e4711dComparesgeisler
commented
Nov 13, 2018
When will the full test suite (all platforms) be run? I expect some problems at first due to conditional compilation (which I can't test). |
sfackler
commented
Nov 14, 2018
@bors r+ It'll run now! No worries if it bounces a couple of times due to the platform specific stuff - it happens all the time. |
bors
commented
Nov 14, 2018
📌 Commit 8e4711d65612f61f57845738db90bccec59d9833 has been approved by |
Uh oh!
There was an error while loading. Please reload this page.
kennytm
commented
Nov 14, 2018
@bors r- Failed in #55943 (comment) on wasm32. |
bors
commented
Nov 16, 2018
⌛ Testing commit 8231831 with merge dee94cd6869ed5b55506b11479dafa5f1ad523da... |
bors
commented
Nov 16, 2018
💔 Test failed - status-travis |
rust-highfive
commented
Nov 16, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Since SystemTime is opaque there is no way to check if the result of an addition will be in bounds. That makes the Add<Duration> trait completely unusable with untrusted data. This is a big problem because adding a Duration to UNIX_EPOCH is the standard way of constructing a SystemTime from a unix timestamp. This commit implements checked_add_duration(&self, &Duration) -> Option<SystemTime> for std::time::SystemTime and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many add_duration(&self, &Duration) -> SystemTime functions to avoid redundancy (they now unwrap the result of checked_add_duration). Some basic unit tests for the newly introduced function were added too.
8231831 to
f2106d0CompareXAMPPRocky
commented
Nov 25, 2018
Triage; @sfackler Hello, have you been able to get back to this PR? |
sfackler
commented
Nov 25, 2018
@bors r+ |
bors
commented
Nov 25, 2018
📌 Commit f2106d0 has been approved by |
sfackler
commented
Nov 25, 2018
Sorry, missed that you updated this - github doesn't notify on force pushes :( |
bors
commented
Nov 25, 2018
Implement checked_add_duration for SystemTime [Original discussion on the rust user forum](https://users.rust-lang.org/t/std-systemtime-misses-a-checked-add-function/21785) Since `SystemTime` is opaque there is no way to check if the result of an addition will be in bounds. That makes the `Add<Duration>` trait completely unusable with untrusted data. This is a big problem because adding a `Duration` to `UNIX_EPOCH` is the standard way of constructing a `SystemTime` from a unix timestamp. This PR implements `checked_add_duration(&self, &Duration) -> Option<SystemTime>` for `std::time::SystemTime` and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many `add_duration(&self, &Duration) -> SystemTime` functions to avoid redundancy (they now unwrap the result of `checked_add_duration`). Some basic unit tests for the newly introduced function were added too. I wasn't sure which stabilization attribute to add to the newly introduced function, so I just chose `#[stable(feature = "time_checked_add", since = "1.32.0")]` for now to make it compile. Please let me know how I should change it or if I violated any other conventions. P.S.: I could only test on Linux so far, so I don't necessarily expect it to compile for all platforms.
bors
commented
Nov 25, 2018
☀️ Test successful - status-appveyor, status-travis |
jethrogb
commented
Mar 12, 2019
This PR acknowledges that |
sfackler
commented
Mar 12, 2019
Yeah, seems best to alter the tests to avoid pre-epoch times if those aren't universally supported. |
Original discussion on the rust user forum
Since
SystemTimeis opaque there is no way to check if the result of an addition will be in bounds. That makes theAdd<Duration>trait completely unusable with untrusted data. This is a big problem because adding aDurationtoUNIX_EPOCHis the standard way of constructing aSystemTimefrom a unix timestamp.This PR implements
checked_add_duration(&self, &Duration) -> Option<SystemTime>forstd::time::SystemTimeand as a prerequisite also for all platform specific time structs. This also led to the refactoring of manyadd_duration(&self, &Duration) -> SystemTimefunctions to avoid redundancy (they now unwrap the result ofchecked_add_duration).Some basic unit tests for the newly introduced function were added too.
I wasn't sure which stabilization attribute to add to the newly introduced function, so I just chose
#[stable(feature = "time_checked_add", since = "1.32.0")]for now to make it compile. Please let me know how I should change it or if I violated any other conventions.P.S.: I could only test on Linux so far, so I don't necessarily expect it to compile for all platforms.