summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/icu/icu/CVE-2020-10531.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-support/icu/icu/CVE-2020-10531.patch')
-rw-r--r--meta/recipes-support/icu/icu/CVE-2020-10531.patch122
1 files changed, 122 insertions, 0 deletions
diff --git a/meta/recipes-support/icu/icu/CVE-2020-10531.patch b/meta/recipes-support/icu/icu/CVE-2020-10531.patch
new file mode 100644
index 0000000000..56303fc0f2
--- /dev/null
+++ b/meta/recipes-support/icu/icu/CVE-2020-10531.patch
@@ -0,0 +1,122 @@
1From b7d08bc04a4296982fcef8b6b8a354a9e4e7afca Mon Sep 17 00:00:00 2001
2From: Frank Tang <ftang@chromium.org>
3Date: Sat, 1 Feb 2020 02:39:04 +0000
4Subject: [PATCH] ICU-20958 Prevent SEGV_MAPERR in append
5
6See #971
7
8Upstream-Status: Backport [https://github.com/unicode-org/icu/commit/b7d08bc04a4296982fcef8b6b8a354a9e4e7afca]
9CVE: CVE-2020-10531
10Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
11---
12 icu4c/source/common/unistr.cpp | 6 ++-
13 icu4c/source/test/intltest/ustrtest.cpp | 62 +++++++++++++++++++++++++
14 icu4c/source/test/intltest/ustrtest.h | 1 +
15 3 files changed, 68 insertions(+), 1 deletion(-)
16
17diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp
18index 901bb3358ba..077b4d6ef20 100644
19--- a/icu4c/source/common/unistr.cpp
20+++ b/icu4c/source/common/unistr.cpp
21@@ -1563,7 +1563,11 @@ UnicodeString::doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLeng
22 }
23
24 int32_t oldLength = length();
25- int32_t newLength = oldLength + srcLength;
26+ int32_t newLength;
27+ if (uprv_add32_overflow(oldLength, srcLength, &newLength)) {
28+ setToBogus();
29+ return *this;
30+ }
31
32 // Check for append onto ourself
33 const UChar* oldArray = getArrayStart();
34diff --git a/icu4c/source/test/intltest/ustrtest.cpp b/icu4c/source/test/intltest/ustrtest.cpp
35index b6515ea813c..ad38bdf53a3 100644
36--- a/icu4c/source/test/intltest/ustrtest.cpp
37+++ b/icu4c/source/test/intltest/ustrtest.cpp
38@@ -67,6 +67,7 @@ void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* &
39 TESTCASE_AUTO(TestWCharPointers);
40 TESTCASE_AUTO(TestNullPointers);
41 TESTCASE_AUTO(TestUnicodeStringInsertAppendToSelf);
42+ TESTCASE_AUTO(TestLargeAppend);
43 TESTCASE_AUTO_END;
44 }
45
46@@ -2310,3 +2311,64 @@ void UnicodeStringTest::TestUnicodeStringInsertAppendToSelf() {
47 str.insert(2, sub);
48 assertEquals("", u"abbcdcde", str);
49 }
50+
51+void UnicodeStringTest::TestLargeAppend() {
52+ if(quick) return;
53+
54+ IcuTestErrorCode status(*this, "TestLargeAppend");
55+ // Make a large UnicodeString
56+ int32_t len = 0xAFFFFFF;
57+ UnicodeString str;
58+ char16_t *buf = str.getBuffer(len);
59+ // A fast way to set buffer to valid Unicode.
60+ // 4E4E is a valid unicode character
61+ uprv_memset(buf, 0x4e, len * 2);
62+ str.releaseBuffer(len);
63+ UnicodeString dest;
64+ // Append it 16 times
65+ // 0xAFFFFFF times 16 is 0xA4FFFFF1,
66+ // which is greater than INT32_MAX, which is 0x7FFFFFFF.
67+ int64_t total = 0;
68+ for (int32_t i = 0; i < 16; i++) {
69+ dest.append(str);
70+ total += len;
71+ if (total <= INT32_MAX) {
72+ assertFalse("dest is not bogus", dest.isBogus());
73+ } else {
74+ assertTrue("dest should be bogus", dest.isBogus());
75+ }
76+ }
77+ dest.remove();
78+ total = 0;
79+ for (int32_t i = 0; i < 16; i++) {
80+ dest.append(str);
81+ total += len;
82+ if (total + len <= INT32_MAX) {
83+ assertFalse("dest is not bogus", dest.isBogus());
84+ } else if (total <= INT32_MAX) {
85+ // Check that a string of exactly the maximum size works
86+ UnicodeString str2;
87+ int32_t remain = INT32_MAX - total;
88+ char16_t *buf2 = str2.getBuffer(remain);
89+ if (buf2 == nullptr) {
90+ // if somehow memory allocation fail, return the test
91+ return;
92+ }
93+ uprv_memset(buf2, 0x4e, remain * 2);
94+ str2.releaseBuffer(remain);
95+ dest.append(str2);
96+ total += remain;
97+ assertEquals("When a string of exactly the maximum size works", (int64_t)INT32_MAX, total);
98+ assertEquals("When a string of exactly the maximum size works", INT32_MAX, dest.length());
99+ assertFalse("dest is not bogus", dest.isBogus());
100+
101+ // Check that a string size+1 goes bogus
102+ str2.truncate(1);
103+ dest.append(str2);
104+ total++;
105+ assertTrue("dest should be bogus", dest.isBogus());
106+ } else {
107+ assertTrue("dest should be bogus", dest.isBogus());
108+ }
109+ }
110+}
111diff --git a/icu4c/source/test/intltest/ustrtest.h b/icu4c/source/test/intltest/ustrtest.h
112index 218befdcc68..4a356a92c7a 100644
113--- a/icu4c/source/test/intltest/ustrtest.h
114+++ b/icu4c/source/test/intltest/ustrtest.h
115@@ -97,6 +97,7 @@ class UnicodeStringTest: public IntlTest {
116 void TestWCharPointers();
117 void TestNullPointers();
118 void TestUnicodeStringInsertAppendToSelf();
119+ void TestLargeAppend();
120 };
121
122 #endif