diff --git a/src/objects/js-locale.cc b/src/objects/js-locale.cc index 64644abad2..e3fee128f8 100644 --- a/src/objects/js-locale.cc +++ b/src/objects/js-locale.cc @@ -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) { diff --git a/test/intl/intl.status b/test/intl/intl.status index 8c223580db..01847d6d02 100644 --- a/test/intl/intl.status +++ b/test/intl/intl.status @@ -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], diff --git a/test/intl/regress-12059.js b/test/intl/regress-12059.js new file mode 100644 index 0000000000..dfe02e2687 --- /dev/null +++ b/test/intl/regress-12059.js @@ -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)));