Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/mbstring/php_mbregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ static inline void mb_regex_substitute(
clen = (int) php_mb_mbchar_bytes(p, enc);
if (clen != 1 || p == eos || p[0] != '\\') {
/* skip anything that's not an ascii backslash */
smart_str_appendl(pbuf, p, clen);
p += clen;
sp = p;
p = MIN(p + clen, eos);
smart_str_appendl(pbuf, sp, p - sp);
continue;
}
sp = p; /* save position */
Expand Down
19 changes: 19 additions & 0 deletions ext/mbstring/tests/gh24769.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-24769 (mb_ereg_replace() reads past the replacement on a truncated trailing multibyte character)
--EXTENSIONS--
mbstring
--SKIPIF--
<?php
if (!function_exists('mb_ereg')) die('skip mbregex support not available');
?>
--FILE--
<?php
mb_regex_encoding('UTF-8');
var_dump(bin2hex(mb_ereg_replace('a', "x\xF0", 'a')));
var_dump(bin2hex(mb_ereg_replace('a', "x\xE2\x82", 'a')));
var_dump(bin2hex(mb_ereg_replace('a', "\xF0\x9F", 'bab')));
?>
--EXPECT--
string(4) "78f0"
string(6) "78e282"
string(8) "62f09f62"
Loading