[php-src] PR #23107: Fix GH-23106: mb_strpos() reads past the end of a truncated UTF-8 haystack
| From: | lazerg | Date: | Fri, 07 Aug 2026 18:02:16 +0000 |
| Subject: | [php-src] PR #23107: Fix GH-23106: mb_strpos() reads past the end of a truncated UTF-8 haystack | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-37624@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23107
Author: lazerg
offset_to_pointer_utf8() walks the haystack with the UTF-8 mblen table. If the string
ends in a truncated multi-byte sequence, the table length for the lead byte is larger than the bytes
actually left, so the walk returns a pointer past the end of the string. mb_strpos()
passes that pointer to zend_memnstr() as the start of the search, which fails the
end >= p assertion on a debug build.
On a release build it is an out-of-bounds read instead: mb_strpos("AA\xf0\x90",
"x", 3) returns a different bogus offset on every run, and with a long enough
haystack it segfaults.
Clamping the walk to the end of the string makes the search start at the end and find nothing, which
is what an offset equal to mb_strlen() should do.
Fixes GH-23106