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

Unified Diff: src/dateparser.cc

Issue 1532573003: Fix UTC offset computation in date parser. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-561973.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/dateparser.cc
diff --git a/src/dateparser.cc b/src/dateparser.cc
index 09dbf1127dbf19f604ce99336f8936a4d82b4d7e..d096a7ec9fc58ce24c970075b09b2409357fb972 100644
--- a/src/dateparser.cc
+++ b/src/dateparser.cc
@@ -100,8 +100,15 @@ bool DateParser::TimeZoneComposer::Write(FixedArray* output) {
if (sign_ != kNone) {
if (hour_ == kNone) hour_ = 0;
if (minute_ == kNone) minute_ = 0;
- int total_seconds = sign_ * (hour_ * 3600 + minute_ * 60);
- if (!Smi::IsValid(total_seconds)) return false;
+ // Avoid signed integer overflow (undefined behavior) by doing unsigned
+ // arithmetic.
+ unsigned total_seconds_unsigned = hour_ * 3600U + minute_ * 60U;
+ if (total_seconds_unsigned > Smi::kMaxValue) return false;
+ int total_seconds = static_cast<int>(total_seconds_unsigned);
+ if (sign_ < 0) {
+ total_seconds = -total_seconds;
+ }
+ DCHECK(Smi::IsValid(total_seconds));
output->set(UTC_OFFSET, Smi::FromInt(total_seconds));
} else {
output->set_null(UTC_OFFSET);
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-561973.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698