summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/icu
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-support/icu')
-rw-r--r--meta/recipes-support/icu/icu/CVE-2020-10531.patch122
-rw-r--r--meta/recipes-support/icu/icu_64.2.bb12
2 files changed, 131 insertions, 3 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
diff --git a/meta/recipes-support/icu/icu_64.2.bb b/meta/recipes-support/icu/icu_64.2.bb
index 10bac7aac0..d09776f4bc 100644
--- a/meta/recipes-support/icu/icu_64.2.bb
+++ b/meta/recipes-support/icu/icu_64.2.bb
@@ -6,18 +6,24 @@ def icu_download_version(d):
6 pvsplit = d.getVar('PV').split('.') 6 pvsplit = d.getVar('PV').split('.')
7 return pvsplit[0] + "_" + pvsplit[1] 7 return pvsplit[0] + "_" + pvsplit[1]
8 8
9def icu_download_folder(d):
10 pvsplit = d.getVar('PV').split('.')
11 return pvsplit[0] + "-" + pvsplit[1]
12
9ICU_PV = "${@icu_download_version(d)}" 13ICU_PV = "${@icu_download_version(d)}"
14ICU_FOLDER = "${@icu_download_folder(d)}"
10 15
11# http://errors.yoctoproject.org/Errors/Details/20486/ 16# http://errors.yoctoproject.org/Errors/Details/20486/
12ARM_INSTRUCTION_SET_armv4 = "arm" 17ARM_INSTRUCTION_SET_armv4 = "arm"
13ARM_INSTRUCTION_SET_armv5 = "arm" 18ARM_INSTRUCTION_SET_armv5 = "arm"
14 19
15BASE_SRC_URI = "http://download.icu-project.org/files/icu4c/${PV}/icu4c-${ICU_PV}-src.tgz" 20BASE_SRC_URI = "https://github.com/unicode-org/icu/releases/download/release-${ICU_FOLDER}/icu4c-${ICU_PV}-src.tgz"
16SRC_URI = "${BASE_SRC_URI} \ 21SRC_URI = "${BASE_SRC_URI} \
17 file://icu-pkgdata-large-cmd.patch \ 22 file://icu-pkgdata-large-cmd.patch \
18 file://fix-install-manx.patch \ 23 file://fix-install-manx.patch \
19 file://0001-Fix-big-endian-build.patch \ 24 file://0001-Fix-big-endian-build.patch \
20 file://0001-icu-Added-armeb-support.patch \ 25 file://0001-icu-Added-armeb-support.patch \
26 file://CVE-2020-10531.patch;striplevel=3 \
21 " 27 "
22 28
23SRC_URI_append_class-target = "\ 29SRC_URI_append_class-target = "\
@@ -26,5 +32,5 @@ SRC_URI_append_class-target = "\
26SRC_URI[md5sum] = "a3d18213beec454e3cdec9a3116d6b05" 32SRC_URI[md5sum] = "a3d18213beec454e3cdec9a3116d6b05"
27SRC_URI[sha256sum] = "627d5d8478e6d96fc8c90fed4851239079a561a6a8b9e48b0892f24e82d31d6c" 33SRC_URI[sha256sum] = "627d5d8478e6d96fc8c90fed4851239079a561a6a8b9e48b0892f24e82d31d6c"
28 34
29UPSTREAM_CHECK_REGEX = "(?P<pver>\d+(\.\d+)+)/" 35UPSTREAM_CHECK_REGEX = "icu4c-(?P<pver>\d+(_\d+)+)-src"
30UPSTREAM_CHECK_URI = "http://download.icu-project.org/files/icu4c/" 36UPSTREAM_CHECK_URI = "https://github.com/unicode-org/icu/releases"