Skip to content

Commit

Permalink
Fix #79371: mb_strtolower (UTF-32LE): stack-buffer-overflow
Browse files Browse the repository at this point in the history
We make sure that negative values are properly compared.
  • Loading branch information
cmb69 authored and smalyshev committed Mar 17, 2020
1 parent 68e2da6 commit 1fdffd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/mbstring/php_unicode.c
Expand Up @@ -315,7 +315,7 @@ static int convert_case_filter(int c, void *void_data)

/* Handle invalid characters early, as we assign special meaning to
* codepoints above 0xffffff. */
if (UNEXPECTED(c > 0xffffff)) {
if (UNEXPECTED((unsigned) c > 0xffffff)) {
(*data->next_filter->filter_function)(c, data->next_filter);
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions ext/mbstring/tests/bug79371.phpt
@@ -0,0 +1,14 @@
--TEST--
Bug #79371 (mb_strtolower (UTF-32LE): stack-buffer-overflow)
--SKIPIF--
<?php
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
?>
--FILE--
<?php
$bytes = array(0xef, 0xbf, 0xbd, 0xef);
$str = implode(array_map("chr", $bytes));
var_dump(bin2hex(mb_strtolower($str, "UTF-32LE")));
?>
--EXPECT--
string(8) "3f000000"

0 comments on commit 1fdffd1

Please sign in to comment.