diff --git a/icu4c/source/i18n/nfsubs.cpp b/icu4c/source/i18n/nfsubs.cpp index 5efbd2a72c8e..74a9af5f50c8 100644 --- a/icu4c/source/i18n/nfsubs.cpp +++ b/icu4c/source/i18n/nfsubs.cpp @@ -1343,10 +1343,18 @@ NumeratorSubstitution::doParse(const UnicodeString& text, int64_t n = result.getLong(status); // force conversion! int64_t d = 1; while (d <= n) { + if (d > U_INT64_MAX / 10) { + // Will cause int64_t overflow + return false; + } d *= 10; } // now add the zeros while (zeroCount > 0) { + if (d > U_INT64_MAX / 10) { + // Will cause int64_t overflow + return false; + } d *= 10; --zeroCount; }