Skip to content

Commit 2bcbc95

Browse files
committed
Fix bug #79037 (global buffer-overflow in mbfl_filt_conv_big5_wchar)
1 parent 0f79b1b commit 2bcbc95

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

ext/mbstring/libmbfl/filters/mbfilter_big5.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ static unsigned short cp950_pua_tbl[][4] = {
138138
{0xf70f,0xf848,0xc740,0xc8fe},
139139
};
140140

141+
static inline int is_in_cp950_pua(int c1, int c) {
142+
if ((c1 >= 0xfa && c1 <= 0xfe) || (c1 >= 0x8e && c1 <= 0xa0) ||
143+
(c1 >= 0x81 && c1 <= 0x8d) || (c1 >= 0xc7 && c1 <= 0xc8)) {
144+
return (c >=0x40 && c <= 0x7e) || (c >= 0xa1 && c <= 0xfe);
145+
}
146+
if (c1 == 0xc6) {
147+
return c >= 0xa1 && c <= 0xfe;
148+
}
149+
return 0;
150+
}
151+
141152
/*
142153
* Big5 => wchar
143154
*/
@@ -186,11 +197,7 @@ mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter)
186197

187198
if (filter->from->no_encoding == mbfl_no_encoding_cp950) {
188199
/* PUA for CP950 */
189-
if (w <= 0 &&
190-
(((c1 >= 0xfa && c1 <= 0xfe) || (c1 >= 0x8e && c1 <= 0xa0) ||
191-
(c1 >= 0x81 && c1 <= 0x8d) ||(c1 >= 0xc7 && c1 <= 0xc8))
192-
&& ((c > 0x39 && c < 0x7f) || (c > 0xa0 && c < 0xff))) ||
193-
((c1 == 0xc6) && (c > 0xa0 && c < 0xff))) {
200+
if (w <= 0 && is_in_cp950_pua(c1, c)) {
194201
c2 = c1 << 8 | c;
195202
for (k = 0; k < sizeof(cp950_pua_tbl)/(sizeof(unsigned short)*4); k++) {
196203
if (c2 >= cp950_pua_tbl[k][2] && c2 <= cp950_pua_tbl[k][3]) {

ext/mbstring/tests/bug79037.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #79037: global buffer-overflow in `mbfl_filt_conv_big5_wchar`
3+
--FILE--
4+
<?php
5+
6+
var_dump(mb_convert_encoding("\x81\x3a", "UTF-8", "CP950"));
7+
8+
?>
9+
--EXPECT--
10+
string(1) "?"

0 commit comments

Comments
 (0)