From 844a2dd6ac9e411e4f24d3a0beab9a23e820325c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 18 Aug 2020 13:24:17 +0200 Subject: [PATCH] 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 --- NEWS | 3 +++ ext/standard/string.c | 2 +- ext/standard/tests/strings/bug79986.phpt | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/strings/bug79986.phpt 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-- + +--FILE-- + +--EXPECT-- +11 22 33 -- 2.40.0