Skip to content

Commit

Permalink
Fix #79986: str_ireplace bug with diacritics characters
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
cmb69 committed Aug 24, 2020
1 parent fcd26ff commit 844a2dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions ext/standard/tests/strings/bug79986.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 844a2dd

Please sign in to comment.