aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/collationbuilder.cpp
diff options
context:
space:
mode:
authorromankoshelev <romankoshelev@yandex-team.com>2024-05-13 11:00:27 +0300
committerromankoshelev <romankoshelev@yandex-team.com>2024-05-13 11:13:05 +0300
commit5b22fadb0f035a3b82c328e0ae710ad2b92f6eac (patch)
treee15dc649c79c4fb78f35cd6694dfe9af9bfcc0ad /contrib/libs/icu/i18n/collationbuilder.cpp
parent5946aa7d3cbca62f6bcf074e8a2b9346e7a96af4 (diff)
downloadydb-5b22fadb0f035a3b82c328e0ae710ad2b92f6eac.tar.gz
Update ICU to 75.1
904da4ae1c86fc5542eac7f1cd18d97b72eb8517
Diffstat (limited to 'contrib/libs/icu/i18n/collationbuilder.cpp')
-rw-r--r--contrib/libs/icu/i18n/collationbuilder.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/contrib/libs/icu/i18n/collationbuilder.cpp b/contrib/libs/icu/i18n/collationbuilder.cpp
index d8fb89738c..b243992cc5 100644
--- a/contrib/libs/icu/i18n/collationbuilder.cpp
+++ b/contrib/libs/icu/i18n/collationbuilder.cpp
@@ -1113,12 +1113,23 @@ CollationBuilder::addWithClosure(const UnicodeString &nfdPrefix, const UnicodeSt
return ce32;
}
+// ICU-22517
+// This constant defines a limit for the addOnlyClosure to return
+// error, to avoid taking a long time for canonical closure expansion.
+// Please let us know if you have a reasonable use case that needed
+// for a practical Collation rule that needs to increase this limit.
+// This value is needed for compiling a rule with eight Hangul syllables such as
+// "&a=b쫊쫊쫊쫊쫊쫊쫊" without error, which should be more than realistic
+// usage.
+static constexpr int32_t kClosureLoopLimit = 3000;
+
uint32_t
CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) { return ce32; }
+ int32_t loop = 0;
// Map from canonically equivalent input to the CEs. (But not from the all-NFD input.)
if(nfdPrefix.isEmpty()) {
CanonicalIterator stringIter(nfdString, errorCode);
@@ -1128,6 +1139,11 @@ CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeSt
UnicodeString str = stringIter.next();
if(str.isBogus()) { break; }
if(ignoreString(str, errorCode) || str == nfdString) { continue; }
+ if (loop++ > kClosureLoopLimit) {
+ // To avoid hang as in ICU-22517, return with error.
+ errorCode = U_INPUT_TOO_LONG_ERROR;
+ return ce32;
+ }
ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode);
if(U_FAILURE(errorCode)) { return ce32; }
}
@@ -1144,6 +1160,11 @@ CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeSt
UnicodeString str = stringIter.next();
if(str.isBogus()) { break; }
if(ignoreString(str, errorCode) || (samePrefix && str == nfdString)) { continue; }
+ if (loop++ > kClosureLoopLimit) {
+ // To avoid hang as in ICU-22517, return with error.
+ errorCode = U_INPUT_TOO_LONG_ERROR;
+ return ce32;
+ }
ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode);
if(U_FAILURE(errorCode)) { return ce32; }
}