1 |
From 7bb2a4671503c41d63989dcef9ef54dea0c73b43 Mon Sep 17 00:00:00 2001 |
2 |
From: Tatsuya Kinoshita <tats@debian.org> |
3 |
Date: Thu, 7 Apr 2016 06:42:55 +0900 |
4 |
Subject: Fix segfault on bogus text |
5 |
|
6 |
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=820162 |
7 |
--- |
8 |
libwc/map/big5_ucs.map | 4 ++- |
9 |
libwc/map/cns11643_ucs.map | 8 +++-- |
10 |
libwc/map/gb12345_ucs.map | 4 ++- |
11 |
libwc/map/gb2312_ucs.map | 4 ++- |
12 |
libwc/map/gbk_ucs.map | 4 ++- |
13 |
libwc/map/hkscs_ucs.map | 4 ++- |
14 |
libwc/map/jisx0208x0212x0213_ucs.map | 8 +++-- |
15 |
libwc/map/ksx1001_ucs.map | 4 ++- |
16 |
libwc/map/sjis_ext_ucs.map | 4 ++- |
17 |
libwc/map/uhc_ucs.map | 4 ++- |
18 |
libwc/ucs.c | 6 ++++ |
19 |
libwc/ucs.map | 57 ++++++++++++++++++++++++++++++++++++ |
20 |
12 files changed, 99 insertions(+), 12 deletions(-) |
21 |
|
22 |
diff --git a/libwc/map/big5_ucs.map b/libwc/map/big5_ucs.map |
23 |
index 0c6fd12..ac817a9 100644 |
24 |
--- a/libwc/map/big5_ucs.map |
25 |
+++ b/libwc/map/big5_ucs.map |
26 |
@@ -1,6 +1,8 @@ |
27 |
/* Big5 (Chinese Taiwan) */ |
28 |
|
29 |
-static wc_uint16 big5_ucs_map[ 0x59 * 0x9D ] = { |
30 |
+#define N_big5_ucs_map (0x59 * 0x9D) |
31 |
+ |
32 |
+static wc_uint16 big5_ucs_map[ N_big5_ucs_map ] = { |
33 |
0x3000, /* 0xA140 */ |
34 |
0xFF0C, /* 0xA141 */ |
35 |
0x3001, /* 0xA142 */ |
36 |
diff --git a/libwc/map/cns11643_ucs.map b/libwc/map/cns11643_ucs.map |
37 |
index b426dd3..fcba334 100644 |
38 |
--- a/libwc/map/cns11643_ucs.map |
39 |
+++ b/libwc/map/cns11643_ucs.map |
40 |
@@ -1,6 +1,8 @@ |
41 |
/* CNS 11643 (Chinese Taiwan) */ |
42 |
|
43 |
-static wc_uint16 cns116431_ucs_map[ 0x5E * 0x5E ] = { |
44 |
+#define N_cns116431_ucs_map (0x5E * 0x5E) |
45 |
+ |
46 |
+static wc_uint16 cns116431_ucs_map[ N_cns116431_ucs_map ] = { |
47 |
0x3000, /* 0x2121 */ |
48 |
0xFF0C, /* 0x2122 */ |
49 |
0x3001, /* 0x2123 */ |
50 |
@@ -8839,7 +8841,9 @@ static wc_uint16 cns116431_ucs_map[ 0x5E * 0x5E ] = { |
51 |
0, /* 0x7E7E */ |
52 |
}; |
53 |
|
54 |
-static wc_uint16 cns116432_ucs_map[ 0x5E * 0x5E ] = { |
55 |
+#define N_cns116432_ucs_map (0x5E * 0x5E) |
56 |
+ |
57 |
+static wc_uint16 cns116432_ucs_map[ N_cns116432_ucs_map ] = { |
58 |
0x4E42, /* 0x2121 */ |
59 |
0x4E5C, /* 0x2122 */ |
60 |
0x51F5, /* 0x2123 */ |
61 |
diff --git a/libwc/map/gb12345_ucs.map b/libwc/map/gb12345_ucs.map |
62 |
index 55558c7..3fb338d 100644 |
63 |
--- a/libwc/map/gb12345_ucs.map |
64 |
+++ b/libwc/map/gb12345_ucs.map |
65 |
@@ -1,6 +1,8 @@ |
66 |
/* GB 12345 (Chinese) */ |
67 |
|
68 |
-static wc_uint16 gb12345_ucs_map[ 0x5E * 0x5E ] = { |
69 |
+#define N_gb12345_ucs_map (0x5E * 0x5E) |
70 |
+ |
71 |
+static wc_uint16 gb12345_ucs_map[ N_gb12345_ucs_map ] = { |
72 |
0x3000, /* 0x2121 */ |
73 |
0x3001, /* 0x2122 */ |
74 |
0x3002, /* 0x2123 */ |
75 |
diff --git a/libwc/map/gb2312_ucs.map b/libwc/map/gb2312_ucs.map |
76 |
index 38fb88f..3d37465 100644 |
77 |
--- a/libwc/map/gb2312_ucs.map |
78 |
+++ b/libwc/map/gb2312_ucs.map |
79 |
@@ -1,6 +1,8 @@ |
80 |
/* GB 2312 (Chinese) */ |
81 |
|
82 |
-static wc_uint16 gb2312_ucs_map[ 0x5E * 0x5E ] = { |
83 |
+#define N_gb2312_ucs_map (0x5E * 0x5E) |
84 |
+ |
85 |
+static wc_uint16 gb2312_ucs_map[ N_gb2312_ucs_map ] = { |
86 |
0x3000, /* 0x2121 */ |
87 |
0x3001, /* 0x2122 */ |
88 |
0x3002, /* 0x2123 */ |
89 |
diff --git a/libwc/map/gbk_ucs.map b/libwc/map/gbk_ucs.map |
90 |
index 5a0d5ba..d092fd7 100644 |
91 |
--- a/libwc/map/gbk_ucs.map |
92 |
+++ b/libwc/map/gbk_ucs.map |
93 |
@@ -6,7 +6,9 @@ static wc_map ucs_gbk_80_map[ N_ucs_gbk_80_map ] = { |
94 |
{ 0x20AC, 0x0080 }, |
95 |
}; |
96 |
|
97 |
-static wc_uint16 gbk_ucs_map[ 0x7E * 0xBE - 0x5E * 0x5E + 0x0A + 0x16 + 0x06 ] = { |
98 |
+#define N_gbk_ucs_map (0x7E * 0xBE - 0x5E * 0x5E + 0x0A + 0x16 + 0x06) |
99 |
+ |
100 |
+static wc_uint16 gbk_ucs_map[ N_gbk_ucs_map ] = { |
101 |
0x4E02, /* 0x8140 */ |
102 |
0x4E04, /* 0x8141 */ |
103 |
0x4E05, /* 0x8142 */ |
104 |
diff --git a/libwc/map/hkscs_ucs.map b/libwc/map/hkscs_ucs.map |
105 |
index 96d1566..2fbe6b4 100644 |
106 |
--- a/libwc/map/hkscs_ucs.map |
107 |
+++ b/libwc/map/hkscs_ucs.map |
108 |
@@ -1,6 +1,8 @@ |
109 |
/* HKSCS (Chinese Hong Kong) */ |
110 |
|
111 |
-static wc_uint16 hkscs_ucs_map[ 0x1E * 0x9D ] = { |
112 |
+#define N_hkscs_ucs_map (0x1E * 0x9D) |
113 |
+ |
114 |
+static wc_uint16 hkscs_ucs_map[ N_hkscs_ucs_map ] = { |
115 |
0, /* 0x8840 */ |
116 |
0, /* 0x8841 */ |
117 |
0, /* 0x8842 */ |
118 |
diff --git a/libwc/map/jisx0208x0212x0213_ucs.map b/libwc/map/jisx0208x0212x0213_ucs.map |
119 |
index 1a1d706..28c2a6c 100644 |
120 |
--- a/libwc/map/jisx0208x0212x0213_ucs.map |
121 |
+++ b/libwc/map/jisx0208x0212x0213_ucs.map |
122 |
@@ -1,6 +1,8 @@ |
123 |
/* JIS X 0208, JIS X 0212, JIS X 0213 (Japanese) */ |
124 |
|
125 |
-static wc_uint16 jisx0208x02131_ucs_map[ 0x5E * 0x5E ] = { |
126 |
+#define N_jisx0208x02131_ucs_map (0x5E * 0x5E) |
127 |
+ |
128 |
+static wc_uint16 jisx0208x02131_ucs_map[ N_jisx0208x02131_ucs_map ] = { |
129 |
0x3000, /* JIS X 0208 0x2121 */ |
130 |
0x3001, /* JIS X 0208 0x2122 */ |
131 |
0x3002, /* JIS X 0208 0x2123 */ |
132 |
@@ -8839,7 +8841,9 @@ static wc_uint16 jisx0208x02131_ucs_map[ 0x5E * 0x5E ] = { |
133 |
0, /* JIS X 0213-1 0x7E7E */ |
134 |
}; |
135 |
|
136 |
-static wc_uint16 jisx0212x02132_ucs_map[ 0x5E * 0x5E ] = { |
137 |
+#define N_jisx0212x02132_ucs_map (0x5E * 0x5E) |
138 |
+ |
139 |
+static wc_uint16 jisx0212x02132_ucs_map[ N_jisx0212x02132_ucs_map ] = { |
140 |
0, /* JIS X 0213-2 0x2121 */ |
141 |
0x4E02, /* JIS X 0213-2 0x2122 */ |
142 |
0x4E0F, /* JIS X 0213-2 0x2123 */ |
143 |
diff --git a/libwc/map/ksx1001_ucs.map b/libwc/map/ksx1001_ucs.map |
144 |
index 9a17d61..cb62f98 100644 |
145 |
--- a/libwc/map/ksx1001_ucs.map |
146 |
+++ b/libwc/map/ksx1001_ucs.map |
147 |
@@ -1,6 +1,8 @@ |
148 |
/* KS X 1001 (Korean) */ |
149 |
|
150 |
-static wc_uint16 ksx1001_ucs_map[ 0x5E * 0x5E ] = { |
151 |
+#define N_ksx1001_ucs_map (0x5E * 0x5E) |
152 |
+ |
153 |
+static wc_uint16 ksx1001_ucs_map[ N_ksx1001_ucs_map ] = { |
154 |
0x3000, /* 0x2121 */ |
155 |
0x3001, /* 0x2122 */ |
156 |
0x3002, /* 0x2123 */ |
157 |
diff --git a/libwc/map/sjis_ext_ucs.map b/libwc/map/sjis_ext_ucs.map |
158 |
index a82995c..cc748ba 100644 |
159 |
--- a/libwc/map/sjis_ext_ucs.map |
160 |
+++ b/libwc/map/sjis_ext_ucs.map |
161 |
@@ -1,6 +1,8 @@ |
162 |
/* Shift_JIS/CP932 (Japanese) */ |
163 |
|
164 |
-static wc_uint16 sjis_ext_ucs_map[ 0x5E * 10 ] = { |
165 |
+#define N_sjis_ext_ucs_map (0x5E * 10) |
166 |
+ |
167 |
+static wc_uint16 sjis_ext_ucs_map[ N_sjis_ext_ucs_map ] = { |
168 |
0x2460, /* 0x8740 */ |
169 |
0x2461, /* 0x8741 */ |
170 |
0x2462, /* 0x8742 */ |
171 |
diff --git a/libwc/map/uhc_ucs.map b/libwc/map/uhc_ucs.map |
172 |
index b6b43ca..55efc09 100644 |
173 |
--- a/libwc/map/uhc_ucs.map |
174 |
+++ b/libwc/map/uhc_ucs.map |
175 |
@@ -1,6 +1,8 @@ |
176 |
/* UHC/CP949 (Korean) */ |
177 |
|
178 |
-static wc_uint16 uhc_ucs_map[ 0x20 * 0xB2 + 0x27 * 0x54 + 2 ] = { |
179 |
+#define N_uhc_ucs_map (0x20 * 0xB2 + 0x27 * 0x54 + 2) |
180 |
+ |
181 |
+static wc_uint16 uhc_ucs_map[ N_uhc_ucs_map ] = { |
182 |
0xAC02, /* 0x8141 */ |
183 |
0xAC03, /* 0x8142 */ |
184 |
0xAC05, /* 0x8143 */ |
185 |
diff --git a/libwc/ucs.c b/libwc/ucs.c |
186 |
index 5e78b4e..727e574 100644 |
187 |
--- a/libwc/ucs.c |
188 |
+++ b/libwc/ucs.c |
189 |
@@ -109,6 +109,7 @@ wc_any_to_ucs(wc_wchar_t cc) |
190 |
{ |
191 |
int f; |
192 |
wc_uint16 *map = NULL; |
193 |
+ wc_uint32 map_size = 0x80; |
194 |
wc_map *map2; |
195 |
|
196 |
f = WC_CCS_INDEX(cc.ccs); |
197 |
@@ -139,6 +140,7 @@ wc_any_to_ucs(wc_wchar_t cc) |
198 |
if (f < WC_F_ISO_BASE || f > WC_F_CS94W_END) |
199 |
return 0; |
200 |
map = cs94w_ucs_map[f - WC_F_ISO_BASE]; |
201 |
+ map_size = cs94w_ucs_map_size[f - WC_F_ISO_BASE]; |
202 |
cc.code = WC_CS94W_N(cc.code); |
203 |
break; |
204 |
case WC_CCS_A_CS96: |
205 |
@@ -151,6 +153,7 @@ wc_any_to_ucs(wc_wchar_t cc) |
206 |
if (f < WC_F_ISO_BASE || f > WC_F_CS96W_END) |
207 |
return WC_C_UCS4_ERROR; |
208 |
map = cs96w_ucs_map[f - WC_F_ISO_BASE]; |
209 |
+ map_size = cs96w_ucs_map_size[f - WC_F_ISO_BASE]; |
210 |
cc.code = WC_CS96W_N(cc.code); |
211 |
break; |
212 |
case WC_CCS_A_CS942: |
213 |
@@ -181,6 +184,7 @@ wc_any_to_ucs(wc_wchar_t cc) |
214 |
if (f < WC_F_PCS_BASE || f > WC_F_PCSW_END) |
215 |
return WC_C_UCS4_ERROR; |
216 |
map = pcsw_ucs_map[f - WC_F_PCS_BASE]; |
217 |
+ map_size = pcsw_ucs_map_size[f - WC_F_PCS_BASE]; |
218 |
switch (cc.ccs) { |
219 |
case WC_CCS_BIG5: |
220 |
cc.code = WC_BIG5_N(cc.code); |
221 |
@@ -272,6 +276,8 @@ wc_any_to_ucs(wc_wchar_t cc) |
222 |
} |
223 |
if (map == NULL) |
224 |
return WC_C_UCS4_ERROR; |
225 |
+ if (map_size == 0 || cc.code > map_size - 1) |
226 |
+ return WC_C_UCS4_ERROR; |
227 |
cc.code = map[cc.code]; |
228 |
return cc.code ? cc.code : WC_C_UCS4_ERROR; |
229 |
} |
230 |
diff --git a/libwc/ucs.map b/libwc/ucs.map |
231 |
index dfac6d9..5d6f688 100644 |
232 |
--- a/libwc/ucs.map |
233 |
+++ b/libwc/ucs.map |
234 |
@@ -195,7 +195,28 @@ static wc_uint16 *cs94w_ucs_map[] = { |
235 |
jisx0212x02132_ucs_map, /* 50 (JIS X 0213-2) */ |
236 |
}; |
237 |
|
238 |
+static wc_uint32 cs94w_ucs_map_size[] = { |
239 |
+ N_jisx0208x02131_ucs_map, /* 40 (JIS C 6226) */ |
240 |
+ N_gb2312_ucs_map, /* 41 (GB 2312) */ |
241 |
+ N_jisx0208x02131_ucs_map, /* 42 (JIS X 0208) */ |
242 |
+ N_ksx1001_ucs_map, /* 43 (KS X 1001) */ |
243 |
+ N_jisx0212x02132_ucs_map, /* 44 (JIS X 0212) */ |
244 |
+ 0, /* 45 (ISO IR 165) */ |
245 |
+ 0, /* 46 */ |
246 |
+ N_cns116431_ucs_map, /* 47 (CNS 11643-1) */ |
247 |
+ N_cns116432_ucs_map, /* 48 (CNS 11643-2) */ |
248 |
+ 0, /* 49 (CNS 11643-3) */ |
249 |
+ 0, /* 4A (CNS 11643-4) */ |
250 |
+ 0, /* 4B (CNS 11643-5) */ |
251 |
+ 0, /* 4C (CNS 11643-6) */ |
252 |
+ 0, /* 4D (CNS 11643-7) */ |
253 |
+ 0, /* 4E (KSP 9566) */ |
254 |
+ N_jisx0208x02131_ucs_map, /* 4F (JIS X 0213-1) */ |
255 |
+ N_jisx0212x02132_ucs_map, /* 50 (JIS X 0213-2) */ |
256 |
+}; |
257 |
+ |
258 |
static wc_uint16 **cs96w_ucs_map; |
259 |
+static wc_uint32 *cs96w_ucs_map_size; |
260 |
|
261 |
static wc_uint16 *pcsw_ucs_map[] = { |
262 |
big5_ucs_map, /* Big5 */ |
263 |
@@ -233,6 +254,42 @@ static wc_uint16 *pcsw_ucs_map[] = { |
264 |
hkscs_ucs_map, /* HKSCS-2 */ |
265 |
}; |
266 |
|
267 |
+static wc_uint32 pcsw_ucs_map_size[] = { |
268 |
+ N_big5_ucs_map, /* Big5 */ |
269 |
+ N_big5_ucs_map, /* Big5-1 */ |
270 |
+ N_big5_ucs_map, /* Big5-2 */ |
271 |
+ 0, /* CNS 11643-8 */ |
272 |
+ 0, /* CNS 11643-9 */ |
273 |
+ 0, /* CNS 11643-10 */ |
274 |
+ 0, /* CNS 11643-11 */ |
275 |
+ 0, /* CNS 11643-12 */ |
276 |
+ 0, /* CNS 11643-13 */ |
277 |
+ 0, /* CNS 11643-14 */ |
278 |
+ 0, /* CNS 11643-15 */ |
279 |
+ 0, /* CNS 11643-16 */ |
280 |
+ 0, /* CNS 11643-X */ |
281 |
+ N_gb12345_ucs_map, /* GB 12345 */ |
282 |
+ 0, /* Johab (special conversion) */ |
283 |
+ 0, /* Johab-1 (special conversion) */ |
284 |
+ 0, /* Johab-2 (special conversion) */ |
285 |
+ N_ksx1001_ucs_map, /* Johab-3 */ |
286 |
+ N_sjis_ext_ucs_map, /* Shift_JIS(CP932) ext */ |
287 |
+ N_sjis_ext_ucs_map, /* Shift_JIS(CP932) ext-1 */ |
288 |
+ N_sjis_ext_ucs_map, /* Shift_JIS(CP932) ext-2 */ |
289 |
+ N_gbk_ucs_map, /* GBK(CP936) */ |
290 |
+ N_gbk_ucs_map, /* GBK(CP936)-1 */ |
291 |
+ N_gbk_ucs_map, /* GBK(CP936)-2 */ |
292 |
+ 0, /* GB18030 GBK-ext (special conversion) */ |
293 |
+ 0, /* GB18030 GBK-ext-1 (special conversion) */ |
294 |
+ 0, /* GB18030 GBK-ext-2 (special conversion) */ |
295 |
+ N_uhc_ucs_map, /* UHC(CP949) */ |
296 |
+ N_uhc_ucs_map, /* UHC(CP949)-1 */ |
297 |
+ N_uhc_ucs_map, /* UHC(CP949)-2 */ |
298 |
+ N_hkscs_ucs_map, /* HKSCS */ |
299 |
+ N_hkscs_ucs_map, /* HKSCS-1 */ |
300 |
+ N_hkscs_ucs_map, /* HKSCS-2 */ |
301 |
+}; |
302 |
+ |
303 |
static wc_wchar_t |
304 |
ucs_cs94_conv(wc_ccs ccs, wc_uint16 c) |
305 |
{ |
306 |
-- |
307 |
cgit v0.12 |
308 |
|