Fix mbregex search state after cache invalidation - #22954
Closed
matthiasgoergens wants to merge 2 commits into
Closed
Fix mbregex search state after cache invalidation#22954matthiasgoergens wants to merge 2 commits into
matthiasgoergens wants to merge 2 commits into
Conversation
matthiasgoergens
marked this pull request as ready for review
July 30, 2026 17:32
matthiasgoergens
requested review from
alexdowad and
youkidearitai
as code owners
July 30, 2026 17:32
Contributor
|
I have very limited time right now. Is @youkidearitai in a position to review this one? |
youkidearitai
approved these changes
Jul 31, 2026
youkidearitai
left a comment
Contributor
There was a problem hiding this comment.
Thank you for your pull request.
I confirmed failed test when before patch this pull request. And I confirmed delete segfault.
=====================================================================
Running selected tests.
TEST 1/1 [ext/mbstring/tests/gh21036.phpt]
========DIFF========
001- bool(false)
001+ Segmentation fault (core dumped)
002+
003+ Termsig=11
========DONE========
FAIL GH-21036 (mb_ereg_search_getregs() after regex cache invalidation) [ext/mbstring/tests/gh21036.phpt]
=====================================================================
Number of tests : 1 1
Tests skipped : 0 ( 0.0%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 1 (100.0%) (100.0%)
Tests passed : 0 ( 0.0%) ( 0.0%)
---------------------------------------------------------------------
Time taken : 0.072 seconds
=====================================================================
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
GH-21036 (mb_ereg_search_getregs() after regex cache invalidation) [ext/mbstring/tests/gh21036.phpt]
=====================================================================
Please add a NEWS that this fixes.
matthiasgoergens
force-pushed
the
codex/gh-21036-php-8.4-20260731
branch
from
July 31, 2026 05:16
6e99a28 to
7d9f78a
Compare
Contributor
Author
|
Thanks @alexdowad and @youkidearitai for the quick turnaround, and thanks for independently verifying the reproducer and fix. I’ve added the requested NEWS entry and folded it into the fix commit. |
youkidearitai
pushed a commit
that referenced
this pull request
Aug 1, 2026
youkidearitai
pushed a commit
that referenced
this pull request
Aug 1, 2026
Contributor
|
@matthiasgoergens Thank you very much for your pull request. I merged and closed. |
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 GH-21036.
php_mbregex_compile_pattern()may replace the cache entry currently referenced bysearch_re. The replacement destroys that regex and clearssearch_re, but leavessearch_regsholding match offsets associated with the destroyed regex.mb_ereg_search_getregs()then treats those registers as valid and dereferences the null regex when processing named captures.Free and clear
search_regswhenever cache replacement clearssearch_re. This preserves the existing invariant that match registers do not outlive their regex and makesmb_ereg_search_getregs()returnfalseinstead of returning stale numeric captures while losing named captures.PR #21038 identified the crash and proposed guarding the named-capture lookup. This alternative also discards the invalidated match state, following the approach used for the analogous invalid-pattern path in commit 392ad20.