[intl] Change JSLocale::Is38AlphaNumList

Move from recusion to loop to avoid stack overflow

Bug: v8:12059
Change-Id: I44981f4271495adf00d7697114663f966b8f9f11
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3087937
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76252}
This commit is contained in:
Frank Tang 2021-08-10 18:03:38 -07:00 committed by V8 LUCI CQ
parent 363a591d11
commit 19996d6de5
3 changed files with 40 additions and 12 deletions

View File

@ -177,19 +177,24 @@ int32_t weekdayFromEDaysOfWeek(icu::Calendar::EDaysOfWeek eDaysOfWeek) {
} // namespace
bool JSLocale::Is38AlphaNumList(const std::string& value) {
std::size_t found_dash = value.find("-");
std::size_t found_underscore = value.find("_");
if (found_dash == std::string::npos &&
found_underscore == std::string::npos) {
return IsAlphanum(value, 3, 8);
bool JSLocale::Is38AlphaNumList(const std::string& in) {
std::string value = in;
while (true) {
std::size_t found_dash = value.find("-");
std::size_t found_underscore = value.find("_");
if (found_dash == std::string::npos &&
found_underscore == std::string::npos) {
return IsAlphanum(value, 3, 8);
}
if (found_underscore == std::string::npos ||
found_dash < found_underscore) {
if (!IsAlphanum(value.substr(0, found_dash), 3, 8)) return false;
value = value.substr(found_dash + 1);
} else {
if (!IsAlphanum(value.substr(0, found_underscore), 3, 8)) return false;
value = value.substr(found_underscore + 1);
}
}
if (found_underscore == std::string::npos || found_dash < found_underscore) {
return IsAlphanum(value.substr(0, found_dash), 3, 8) &&
JSLocale::Is38AlphaNumList(value.substr(found_dash + 1));
}
return IsAlphanum(value.substr(0, found_underscore), 3, 8) &&
JSLocale::Is38AlphaNumList(value.substr(found_underscore + 1));
}
bool JSLocale::Is3Alpha(const std::string& value) {

View File

@ -31,6 +31,11 @@
'overrides/caching': [PASS, FAIL],
}], # ALWAYS
['asan == True or msan == True or tsan == True', {
# Take too long to run
'regress-12059': [SKIP],
}],
['gc_stress', {
# Push limit of stack, too flaky with machine with more memory.
'regress-1130489': [SKIP],

View File

@ -0,0 +1,18 @@
// Copyright 2021 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.
assertThrows(
() => new Intl.DateTimeFormat('en', {calendar: 'abc-'.repeat(100000)}),
RangeError,
"Invalid calendar : " + ('abc-'.repeat(100000)));
assertThrows(
() => new Intl.DateTimeFormat('en', {calendar: 'abc_'.repeat(100000)}),
RangeError,
"Invalid calendar : " + ('abc_'.repeat(100000)));
assertThrows(
() => new Intl.DateTimeFormat('en', {calendar: 'abc_efgh-'.repeat(100000)}),
RangeError,
"Invalid calendar : " + ('abc_efgh-'.repeat(100000)));