]> granicus.if.org Git - php/commitdiff
Fix #79371: mb_strtolower (UTF-32LE): stack-buffer-overflow
authorChristoph M. Becker <cmbecker69@gmx.de>
Thu, 12 Mar 2020 12:04:04 +0000 (13:04 +0100)
committerStanislav Malyshev <stas@php.net>
Tue, 17 Mar 2020 05:40:00 +0000 (22:40 -0700)
We make sure that negative values are properly compared.

ext/mbstring/php_unicode.c
ext/mbstring/tests/bug79371.phpt [new file with mode: 0644]

index ac452b6a20776189432823f23ddbecf809e65ebc..acb16bf06e4cc6be8f8fbe715083c65264f78a0c 100644 (file)
@@ -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;
        }
diff --git a/ext/mbstring/tests/bug79371.phpt b/ext/mbstring/tests/bug79371.phpt
new file mode 100644 (file)
index 0000000..3014feb
--- /dev/null
@@ -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"