[php-src] PR #25143: Fix GH-25024: backport mb_ereg_replace() \k<name> OOB-read clamp to PHP-8.2/8.3
| From: | dhrupo | Date: | Mon, 02 Nov 2026 05:57:31 +0000 |
| Subject: | [php-src] PR #25143: Fix GH-25024: backport mb_ereg_replace() \k<name> OOB-read clamp to PHP-8.2/8.3 | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40213@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25143
Author: dhrupo
Backports the
mb_ereg_replace() \k<name> out-of-bounds read fix
(509e27bae1cd, Closes GH-23499; fix by Ilia Alshanetsky) to the still-supported PHP-8.2 and PHP-8.3
branches, as requested in GH-25024.
When a \k<name> backref in the replacement string has no closing delimiter,
mb_regex_substitute() advances p past eos at two sites and
the following smart_str_appendl(pbuf, sp, p - sp) copies the overshoot (a NUL
terminator, or heap bytes past the string) into the returned result. Both sites are clamped to
eos, identical to PHP-8.4+.
Opened against PHP-8.2 so it merges up into 8.3 (8.4 already has the fix). If 8.2 is considered too
close to EOL to warrant it, happy to retarget to PHP-8.3.
Testing (built from source, NTS, --enable-mbstring):
- ext/mbstring/tests/mb_ereg_replace_kname_unterminated_nul.phpt (the upstream test):
FAILS on clean 8.2 and 8.3 (output carries a trailing NUL / overshoot), PASSES after the clamps.
- Full ext/mbstring/tests: 8.2 = 406 passed / 0 failed (2 skipped), 8.3 = 423 passed /
0 failed (2 skipped).
Drafted with an LLM; I reviewed and tested it myself.