Repository navigation
Fix GH-23106: mb_strpos() reads past the end of a haystack ending in a truncated UTF-8 sequence - #25121
Closed
VishnuSrivatsava wants to merge 1 commit into
Closed
Fix GH-23106: mb_strpos() reads past the end of a haystack ending in a truncated UTF-8 sequence#25121VishnuSrivatsava wants to merge 1 commit into
VishnuSrivatsava wants to merge 1 commit into
Conversation
…in a truncated UTF-8 sequence Backport of master commit cc22056 (PR php#23107), requested in phpGH-25025. offset_to_pointer_utf8() can step past the end of the haystack when the forward offset walk lands on a truncated multi-byte sequence, and the returned pointer is then used by zend_memnstr() despite violating its end >= pointer invariant. Clamp the pointer to the end of the haystack.
VishnuSrivatsava
requested review from
alexdowad and
youkidearitai
as code owners
November 1, 2026 10:55
Contributor
|
Hmm, 8.3 and 8.2 is security fixes only. So I think we can't merge in 8.3 and 8.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25025 and GH-23106 for the PHP-8.3 branch.
Backport of master commit cc22056 (PR #23107, credited to Lazizbek Ergashev), which shipped in 8.4.27 / 8.5.12 but never reached the stable branches. The forward offset walk in
offset_to_pointer_utf8()can step past the end of the haystack when it lands on a truncated multi-byte lead byte, and the returned pointer then violateszend_memnstr()'send >= pinvariant (assertion failure in debug builds). #25025 additionally documents overshoots on the reverse path — the same clamp fixes those as well, since both paths shareoffset_to_pointer_utf8().Changes:
offset_to_pointer_utf8()to the end of the haystack after the forward offset walk — identical to master.ext/mbstring/tests/gh23106.phpt.Verification on this branch (macOS arm64,
--enable-debug+ AddressSanitizer):mb_strpos("AA\xf0\x90", "xyz", 3)aborts withAssertion failed: (end >= p), function zend_memnstr, file zend_operators.h, line 182.ext/mbstringsuite passes (343 passed, 0 failed, 82 environment skips).Not touching NEWS, following the branch convention where release managers add entries at packaging time.
For PHP-8.2: per the analysis in #25025, the fix there has to be rewritten against
mbfl_find_offset_utf8()in libmbfl (different function and file,const unsigned char *pointers), so I have not attempted a straight backport; happy to prepare it if release managers want it while the branch is in security support.