From 09dce103f2bd6e621a153da3f399d2c52a9f668e Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 11 Jun 2024 14:33:25 -0700 Subject: [PATCH] ICU-22797 Move the loop limit before ignore continue Fix an infinity loop issue inside collation builder --- icu4c/source/i18n/collationbuilder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/icu4c/source/i18n/collationbuilder.cpp b/icu4c/source/i18n/collationbuilder.cpp index b243992cc58b..af631e6a52ef 100644 --- a/icu4c/source/i18n/collationbuilder.cpp +++ b/icu4c/source/i18n/collationbuilder.cpp @@ -1138,12 +1138,12 @@ CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeSt for(;;) { 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; } + if(ignoreString(str, errorCode) || str == nfdString) { continue; } ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode); if(U_FAILURE(errorCode)) { return ce32; } } @@ -1159,12 +1159,12 @@ CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeSt for(;;) { 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; } + if(ignoreString(str, errorCode) || (samePrefix && str == nfdString)) { continue; } ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode); if(U_FAILURE(errorCode)) { return ce32; } }