-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement RF bug #72777 - Add oniguruma stack limit #2109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a99595c
Implement RF bug #72777
38f398e
Remove global var usage
c416d5e
Add test
00cfae6
Fix limit condition. Increase stack limit from 10k to 100k.
52484b3
Merge branch 'master' into master-bug72777
ba4fece
Add #if HAVE_MBREGEX
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1473,6 +1473,27 @@ static PHP_INI_MH(OnUpdate_mbstring_http_output_conv_mimetypes) | |
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
#if HAVE_MBREGEX | ||
/* {{{ static PHP_INI_MH(OnUpdate_regex_stack_limit */ | ||
static PHP_INI_MH(OnUpdate_regex_stack_limit) | ||
{ | ||
zend_long stack_limit; | ||
|
||
stack_limit = atol(ZSTR_VAL(new_value)); | ||
if (stack_limit > 0 && stack_limit <= UINT_MAX) { | ||
onig_set_match_stack_limit_size(stack_limit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use onig_set_match_stack_limit_size_of_match_param() and onig_match_with_param() |
||
} else if (stack_limit <= 0) { | ||
onig_set_match_stack_limit_size(UINT_MAX); | ||
} else { | ||
php_error_docref("ref.mbstring", E_WARNING, "mbstring.regex_stack_limit exceeds UNIT_MAX"); | ||
return FAILURE; | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
#endif | ||
/* }}} */ | ||
/* }}} */ | ||
|
||
/* {{{ php.ini directive registration */ | ||
|
@@ -1499,6 +1520,9 @@ PHP_INI_BEGIN() | |
PHP_INI_ALL, | ||
OnUpdateLong, | ||
strict_detection, zend_mbstring_globals, mbstring_globals) | ||
#if HAVE_MBREGEX | ||
PHP_INI_ENTRY("mbstring.regex_stack_limit", "100000", PHP_INI_ALL, OnUpdate_regex_stack_limit) | ||
#endif | ||
PHP_INI_END() | ||
/* }}} */ | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
Test oniguruma stack limit | ||
--SKIPIF-- | ||
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> | ||
--FILE-- | ||
<?php | ||
$s = str_repeat(' ', 30000); | ||
|
||
ini_set('mbstring.regex_stack_limit', 10000); | ||
var_dump(mb_ereg('\\s+$', $s)); | ||
|
||
ini_set('mbstring.regex_stack_limit', 30000); | ||
var_dump(mb_ereg('\\s+$', $s)); | ||
|
||
ini_set('mbstring.regex_stack_limit', 30001); | ||
var_dump(mb_ereg('\\s+$', $s)); | ||
|
||
echo 'OK'; | ||
?> | ||
--EXPECT-- | ||
bool(false) | ||
bool(false) | ||
int(1) | ||
OK |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
Test oniguruma stack limit | ||
--SKIPIF-- | ||
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> | ||
--FILE-- | ||
<?php | ||
function mb_trim( $string, $chars = "", $chars_array = array() ) | ||
{ | ||
for( $x=0; $x<iconv_strlen( $chars ); $x++ ) $chars_array[] = preg_quote( iconv_substr( $chars, $x, 1 ) ); | ||
$encoded_char_list = implode( "|", array_merge( array( "\s","\t","\n","\r", "\0", "\x0B" ), $chars_array ) ); | ||
|
||
$string = mb_ereg_replace( "^($encoded_char_list)*", "", $string ); | ||
$string = mb_ereg_replace( "($encoded_char_list)*$", "", $string ); | ||
return $string; | ||
} | ||
|
||
ini_set('mbstring.regex_stack_limit', 10000); | ||
var_dump(mb_trim(str_repeat(' ', 10000))); | ||
|
||
echo 'OK'; | ||
?> | ||
--EXPECTF-- | ||
Warning: mb_ereg_replace(): mbregex search failure in php_mbereg_replace_exec(): match-stack limit over in %s on line %d | ||
string(0) "" | ||
OK |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the PHP_INI_ENTRY() is commented out by preprocessor macros, then shouldn't the PHP_INI_MH() function be too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I should!