Skip to content

Commit 97e7619

Browse files
kojiishiV8 LUCI CQ
authored andcommitted
[icu] Fix LookupAndValidateUnicodeExtensions() for ICU 77
ICU 77 `getKeywordValue()` changed to return `U_STRING_NOT_TERMINATED_WARNING` when the value is exactly the same size as the given buffer size. In this case, the buffer is not null-terminated[1]. This patch fixes `LookupAndValidateUnicodeExtensions()` for this change. [1] https://unicode-org.github.io/icu/userguide/strings/#using-c-strings-nul-terminated-vs-length-parameters Bug: 458186954 Change-Id: Iaff890f93cc392d4deb71ab881ab4bcce97f5b34 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7137918 Auto-Submit: Koji Ishii <[email protected]> Commit-Queue: Jakob Linke <[email protected]> Reviewed-by: Jakob Linke <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Cr-Commit-Position: refs/heads/main@{#103662}
1 parent c48578c commit 97e7619

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/objects/intl-objects.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ std::map<std::string, std::string> LookupAndValidateUnicodeExtensions(
24452445
if (U_FAILURE(status)) return extensions;
24462446

24472447
if (!keywords) return extensions;
2448-
char value[ULOC_FULLNAME_CAPACITY];
2448+
char value[ULOC_FULLNAME_CAPACITY + 1];
24492449

24502450
int32_t length;
24512451
status = U_ZERO_ERROR;
@@ -2459,7 +2459,8 @@ std::map<std::string, std::string> LookupAndValidateUnicodeExtensions(
24592459
continue;
24602460
}
24612461

2462-
icu_locale->getKeywordValue(keyword, value, ULOC_FULLNAME_CAPACITY, status);
2462+
const int32_t value_len = icu_locale->getKeywordValue(
2463+
keyword, value, ULOC_FULLNAME_CAPACITY, status);
24632464

24642465
// Ignore failures in ICU and skip to the next keyword.
24652466
//
@@ -2468,6 +2469,9 @@ std::map<std::string, std::string> LookupAndValidateUnicodeExtensions(
24682469
status = U_ZERO_ERROR;
24692470
continue;
24702471
}
2472+
// Ensure the `value` is null-terminated even when the `status` is
2473+
// `U_STRING_NOT_TERMINATED_WARNING`.
2474+
value[value_len] = '\0';
24712475

24722476
const char* bcp47_key = uloc_toUnicodeLocaleKey(keyword);
24732477

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
let locale = "zh-TW-u-ca-chinese";
6+
for (let i = 0; i < 300; ++i) {
7+
try {
8+
Intl.DateTimeFormat(locale);
9+
} catch (e) {
10+
// "RangeError: Invalid language tag", for locales ending with "-", or
11+
// sub-tags of one character, are not relevant to this test.
12+
}
13+
locale += (i % 5) ? "a" : "-";
14+
}
15+
// Pass if this test doesn't crash.

0 commit comments

Comments
 (0)