[GIT-PULLS] [php-src] PR #22780: Fix GH-22779: mb_strrpos() wrong result in a non-UTF-8 encoding

[email protected] (eyupcanakman) Fri, 17 Jul 2026 01:52:59 +0000
Newsgroups php.git-pulls
Message-ID <CG8bMudsICiroOpJ4CiujtTVdpk7lDT4DcpNecU21Sk@main.internal.php.net>
Pull Request: https://github.com/php/php-src/pull/22780
Author: eyupcanakman

`mb_strrpos()` with a negative offset returns the wrong position (or `false`) when the encoding is not UTF-8. `mb_find_strpos()` converts the haystack and needle to UTF-8 and does its length math on the converted strings, but the negative-offset branch measured the needle length from the raw `needle`. `mb_fast_strlen_utf8()` counts those bytes as UTF-8, so the length is wrong when the source bytes are not their own UTF-8 form. A byte in 0x80-0xBF makes it too low and an ASCII needle in UTF-16 makes it too high, shifting the reverse-search window.

The fix measures the length from `needle_u8`. The test covers ISO-8859-1, Windows-1252, Shift_JIS and UTF-16.

Fixes GH-22779