Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2570)

Unified Diff: base/time/time_win.cc

Issue 2405453002: Fix Integer-overflow in base::Time::FromExploded. (Closed)
Patch Set: move method under ifdef Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index ba6fc1da3bf707aef82567868e425111e16ea083..43d0e5b2eae4eaf503b3e67c43b302d7190f9268 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -109,6 +109,9 @@ uint64_t QPCNowRaw() {
return perf_counter_now.QuadPart;
}
+// Maximum size of the
+const int kMaxWinWordSize = 65535;
mmenke 2016/10/18 15:04:50 This should just be std::numeric_limits<WORD>::max
+
} // namespace
// Time -----------------------------------------------------------------------
@@ -236,6 +239,14 @@ bool Time::IsHighResolutionTimerInUse() {
// static
bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) {
+ // Windows WORD has size of 2 bytes. Thus, maximum value that can be
+ // stored is 65535. If it is not possible to cast to WORD without an overflow,
+ // just return an error.
+ if (exploded.year > kMaxWinWordSize) {
miu 2016/10/18 19:55:13 Suggestion: if (exploded.year > std::numeric_li
maksims (do not use this acc) 2016/10/19 16:41:04 Yes. Removed
+ *time = Time(0);
+ return false;
+ }
+
// Create the system struct representing our exploded time. It will either be
// in local time or UTC.
SYSTEMTIME st;
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698