Skip to content

Commit 1fdffd1

Browse files
cmb69smalyshev
authored andcommitted
Fix #79371: mb_strtolower (UTF-32LE): stack-buffer-overflow
We make sure that negative values are properly compared.
1 parent 68e2da6 commit 1fdffd1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ext/mbstring/php_unicode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static int convert_case_filter(int c, void *void_data)
315315

316316
/* Handle invalid characters early, as we assign special meaning to
317317
* codepoints above 0xffffff. */
318-
if (UNEXPECTED(c > 0xffffff)) {
318+
if (UNEXPECTED((unsigned) c > 0xffffff)) {
319319
(*data->next_filter->filter_function)(c, data->next_filter);
320320
return 0;
321321
}

ext/mbstring/tests/bug79371.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #79371 (mb_strtolower (UTF-32LE): stack-buffer-overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$bytes = array(0xef, 0xbf, 0xbd, 0xef);
10+
$str = implode(array_map("chr", $bytes));
11+
var_dump(bin2hex(mb_strtolower($str, "UTF-32LE")));
12+
?>
13+
--EXPECT--
14+
string(8) "3f000000"

0 commit comments

Comments
 (0)