[date] Fix crash by invalid TimeZone "US/x0" names.

Bug: chromium:1132641
Change-Id: Ifa005f9c901ccc865159b618e5145b6d83293b2a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2436078
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70182}
This commit is contained in:
Frank Tang 2020-09-28 11:05:32 -07:00 committed by Commit Bot
parent df92d806b8
commit 07e0c55538
2 changed files with 12 additions and 2 deletions

View File

@ -432,8 +432,10 @@ std::string CanonicalizeTimeZoneID(const std::string& input) {
}
} else if (memcmp(upper.c_str(), "US/", 3) == 0) {
std::string title = ToTitleCaseTimezoneLocation(input);
// Change "Us/" to "US/"
title[1] = 'S';
if (title.length() >= 2) {
// Change "Us/" to "US/"
title[1] = 'S';
}
return title;
} else if (memcmp(upper.c_str(), "SYSTEMV/", 8) == 0) {
upper.replace(0, 8, "SystemV/");

View File

@ -0,0 +1,8 @@
// Copyright 2020 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.
// Test invalid timezones under US/... won't cause crash.
assertThrows(() => {
new Intl.DateTimeFormat("en" , { timeZone: "US/Alaska0" });},
RangeError);