File icu-CVE-2025-5222-shim-dd72356.patch of Package icu.39341
From dd7235624ce837183d96598a1958f6b5968a72f8 Mon Sep 17 00:00:00 2001
From: Shane Carr <shane@unicode.org>
Date: Fri, 14 Sep 2018 00:51:36 -0700
Subject: [PATCH] ICU-11276 Adding UChar* method in CharString.
---
icu4c/source/common/charstr.cpp | 12 +++++++++---
icu4c/source/common/charstr.h | 1 +
icu4c/source/common/cmemory.h | 4 ++++
icu4c/source/common/uinvchar.h | 16 ----------------
4 files changed, 14 insertions(+), 19 deletions(-)
--- a/source/common/charstr.cpp
+++ b/source/common/charstr.cpp
@@ -114,15 +114,22 @@
}
CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
+ return appendInvariantChars(s.getBuffer(), s.length(), errorCode);
+}
+
+CharString &CharString::appendInvariantChars(const UChar* uchars, int32_t ucharsLen, UErrorCode &errorCode) {
+
if(U_FAILURE(errorCode)) {
return *this;
}
- if (!uprv_isInvariantUnicodeString(s)) {
+ if (!uprv_isInvariantUString(uchars, ucharsLen)) {
errorCode = U_INVARIANT_CONVERSION_ERROR;
return *this;
}
- if(ensureCapacity(len+s.length()+1, 0, errorCode)) {
- len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity()-len, US_INV);
+ if(ensureCapacity(len+ucharsLen+1, 0, errorCode)) {
+ u_UCharsToChars(uchars, buffer.getAlias()+len, ucharsLen);
+ len += ucharsLen;
+ buffer[len] = 0;
}
return *this;
}
--- a/source/common/charstr.h
+++ b/source/common/charstr.h
@@ -111,6 +111,7 @@
UErrorCode &errorCode);
CharString &appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode);
+ CharString &appendInvariantChars(const UChar* uchars, int32_t ucharsLen, UErrorCode& errorCode);
/**
* Appends a filename/path part, e.g., a directory name.
--- a/source/common/cmemory.h
+++ b/source/common/cmemory.h
@@ -300,6 +300,10 @@
*
* Unlike LocalMemory and LocalArray, this class never adopts
* (takes ownership of) another array.
+ *
+ * WARNING: MaybeStackArray only works with primitive (plain-old data) types.
+ * It does NOT know how to call a destructor! If you work with classes with
+ * destructors, consider LocalArray in localpointer.h.
*/
template<typename T, int32_t stackCapacity>
class MaybeStackArray {
--- a/source/common/uinvchar.h
+++ b/source/common/uinvchar.h
@@ -53,22 +53,6 @@
U_INTERNAL UBool U_EXPORT2
uprv_isInvariantUString(const UChar *s, int32_t length);
-#ifdef __cplusplus
-
-/**
- * Check if a UnicodeString only contains invariant characters.
- * See utypes.h for details.
- *
- * @param s Input string.
- * @return TRUE if s contains only invariant characters.
- */
-U_INTERNAL inline UBool U_EXPORT2
-uprv_isInvariantUnicodeString(const icu::UnicodeString &s) {
- return uprv_isInvariantUString(icu::toUCharPtr(s.getBuffer()), s.length());
-}
-
-#endif /* __cplusplus */
-
/**
* \def U_UPPER_ORDINAL
* Get the ordinal number of an uppercase invariant character