Repository navigation
Fix stack overflow in mb_check_encoding() and mb_convert_encoding() - #25219
Closed
eyupcanakman wants to merge 1 commit into
Closed
eyupcanakman wants to merge 1 commit into
eyupcanakman wants to merge 1 commit into
Conversation
The array walk in both functions goes one C call deeper per nesting level without checking the stack limit, so a deeply nested array crashes the process. Call mb_check_stack_limit() in the two recursive helpers, as mb_convert_variables() already does.
eyupcanakman
requested review from
alexdowad and
youkidearitai
as code owners
November 5, 2026 17:34
Contributor
|
@eyupcanakman Thanks very much for the report! Will look into it ASAP. |
Contributor
|
OK, the bug is real, the fix is good, the regression test catches it... this looks very nice! |
Contributor
|
Merged into PHP 8.4 → 8.5 → 8.6 → master. |
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.
mb_check_encoding()andmb_convert_encoding()walk array arguments withphp_mb_check_encoding_recursive()andphp_mb_convert_encoding_recursive(). Neither helper looks at the stack limit before going one level deeper, so a deep enough array crashes the process.mb_convert_encoding()already segfaults at 30000 levels with the default stack.mbstring.c has had
mb_check_stack_limit()since GH-20836, but onlymb_convert_variables()uses it. Both helpers now call it and return early once the Error is thrown, so the walk stops there and a second nested array never adds a chained Error. The helper moves up the file so the convert path can see it.There is no GitHub issue for this.