Skip to content

Commit

Permalink
ICU-22797 Move the loop limit before ignore continue
Browse files Browse the repository at this point in the history
Fix an infinity loop issue inside collation builder
  • Loading branch information
FrankYFTang committed Jun 13, 2024
1 parent 64f529e commit 09dce10
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/i18n/collationbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand All @@ -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; }
}
Expand Down

0 comments on commit 09dce10

Please sign in to comment.