gnu: graphite2: Add fixes for CVE-2017-5436 and other bugs.
[jackhill/guix/guix.git] / gnu / packages / patches / graphite2-check-code-point-limit.patch
1 From 348c11e4571b534efdbd58a575bbea979c880b2f Mon Sep 17 00:00:00 2001
2 From: Tim Eves <tim_eves@sil.org>
3 Date: Wed, 1 Mar 2017 14:23:46 +0700
4 Subject: [PATCH] Fix decoding of USV greater than U+110000
5
6 Add test cases too
7 ---
8 src/inc/UtfCodec.h | 4 ++--
9 tests/utftest/utftest.cpp | 3 +++
10 2 files changed, 5 insertions(+), 2 deletions(-)
11
12 diff --git a/src/inc/UtfCodec.h b/src/inc/UtfCodec.h
13 index 3417bac..9dc760f 100644
14 --- a/src/inc/UtfCodec.h
15 +++ b/src/inc/UtfCodec.h
16 @@ -124,7 +124,7 @@ struct _utf_codec<8>
17 private:
18 static const int8 sz_lut[16];
19 static const byte mask_lut[5];
20 -
21 + static const uchar_t limit = 0x110000;
22
23 public:
24 typedef uint8 codeunit_t;
25 @@ -157,7 +157,7 @@ public:
26 case 0: l = -1; return 0xFFFD;
27 }
28
29 - if (l != seq_sz || toolong)
30 + if (l != seq_sz || toolong || u >= limit)
31 {
32 l = -l;
33 return 0xFFFD;
34 diff --git a/tests/utftest/utftest.cpp b/tests/utftest/utftest.cpp
35 index 21cb188..a23553a 100644
36 --- a/tests/utftest/utftest.cpp
37 +++ b/tests/utftest/utftest.cpp
38 @@ -8,6 +8,9 @@ struct test8
39 unsigned char str[12];
40 };
41 struct test8 tests8[] = {
42 + { 0, 0, {0xF4, 0x90, 0x80, 0x80, 0, 0, 0, 0, 0, 0, 0, 0} }, // bad(4) [U+110000]
43 + { 0, 0, {0xC0, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, // bad(4) [U+110000]
44 + { 0, 0, {0xA0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, // bad(4) [U+110000]
45 { 4, -1, {0x7F, 0xDF, 0xBF, 0xEF, 0xBF, 0xBF, 0xF4, 0x8F, 0xBF, 0xBF, 0, 0} }, // U+7F, U+7FF, U+FFFF, U+10FFF
46 { 2, 3, {0x7F, 0xDF, 0xBF, 0xF0, 0x8F, 0xBF, 0xBF, 0xF4, 0x8F, 0xBF, 0xBF, 0} }, // U+7F, U+7FF, long(U+FFFF), U+10FFF
47 { 1, 1, {0x7F, 0xE0, 0x9F, 0xBF, 0xEF, 0xBF, 0xBF, 0xF4, 0x8F, 0xBF, 0xBF, 0} }, // U+7F, long(U+7FF), U+FFFF, U+10FFF
48 --
49 2.12.2
50