summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-08-18 13:24:17 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-08-24 11:08:48 +0200
commit844a2dd6ac9e411e4f24d3a0beab9a23e820325c (patch)
treef9350311d768c018a417966b6b490f2dc6914326
parentfcd26ffcc3f3a1ce5e5bd78afd89c484e206e3ea (diff)
downloadphp-git-844a2dd6ac9e411e4f24d3a0beab9a23e820325c.tar.gz
Fix #79986: str_ireplace bug with diacritics characters
`tolower()` returns an `int`, so we must not convert to `char` which may be `signed` and as such may be subject to overflow (actually, implementation defined behavior). Closes GH-6007
-rw-r--r--NEWS3
-rw-r--r--ext/standard/string.c2
-rw-r--r--ext/standard/tests/strings/bug79986.phpt13
3 files changed, 17 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 2dfd4e2fcb..9666878056 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ PHP NEWS
. Fixed bug #80002 (calc free space for new interned string is wrong).
(t-matsuno)
+- Standard:
+ . Fixed bug #79986 (str_ireplace bug with diacritics characters). (cmb)
+
03 Sep 2020, PHP 7.3.22
- Core:
diff --git a/ext/standard/string.c b/ext/standard/string.c
index b070a5e827..e4361a1114 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3156,7 +3156,7 @@ static zend_string* php_char_to_str_ex(zend_string *str, char from, char *to, si
{
zend_string *result;
size_t char_count = 0;
- char lc_from = 0;
+ int lc_from = 0;
const char *source, *source_end= ZSTR_VAL(str) + ZSTR_LEN(str);
char *target;
diff --git a/ext/standard/tests/strings/bug79986.phpt b/ext/standard/tests/strings/bug79986.phpt
new file mode 100644
index 0000000000..fcbc72148c
--- /dev/null
+++ b/ext/standard/tests/strings/bug79986.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #79986 (str_ireplace bug with diacritics characters)
+--SKIPIF--
+<?php
+if (!setlocale(LC_ALL, 'de_DE.ISO-8859-1', 'de-DE')) die('skip German locale not available');
+?>
+--FILE--
+<?php
+setlocale(LC_ALL, 'de_DE.ISO-8859-1', 'de-DE');
+echo str_ireplace(["\xE4", "\xF6", "\xFC"], ['1', '2', '3'], "\xE4\xC4 \xF6\xD6 \xFC\xDC") . PHP_EOL;
+?>
+--EXPECT--
+11 22 33