Commit 37b5ebc3 authored by ishell's avatar ishell Committed by Commit bot

Fix UTC offset computation in date parser.

BUG=chromium:561973
LOG=N

Review URL: https://codereview.chromium.org/1532573003

Cr-Commit-Position: refs/heads/master@{#32956}
parent 153f2bd4
......@@ -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);
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
Date.parse('Sat, 01 Jan 100 08:00:00 UT-59011430400000');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment