[php-src] Issue #14164: Maximum call stack size reached case triggers stack overflow from ASan
| From: | YuanchengJiang | Date: | Tue, 07 May 2024 11:00:25 +0000 |
| Subject: | [php-src] Issue #14164: Maximum call stack size reached case triggers stack overflow from ASan | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246872@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14164
Author: YuanchengJiang
### Description
The following code:
```php
<?php
$input = "plain [indent] deep [indent] [abcd]deeper[/abcd] [/indent] deep [/indent]
plain";
function parseTagsRecursive($input)
{
$regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
if (is_array($input)) {
}
return preg_replace_callback($regex, 'parseTagsRecursive', $input);
}
$output = parseTagsRecursive($input);
?>
```
Resulted in this output:
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==599856==ERROR: AddressSanitizer: stack-overflow on address 0x7ffdbcc63c98 (pc 0x5625043d7a3a bp
0x7ffdbcc640e0 sp 0x7ffdbcc63ca0 T0)
#0 0x5625043d7a3a in zend_is_callable_at_frame /php-src/Zend/zend_API.c:4049
#1 0x5625043e7649 in zend_is_callable_ex /php-src/Zend/zend_API.c:4165:13
#2 0x5625043e774d in zend_is_callable /php-src/Zend/zend_API.c:4174:9
#3 0x562504500b6e in zend_check_type_slow /php-src/Zend/zend_execute.c:1165:3
#4 0x562504506616 in zend_check_type /php-src/Zend/zend_execute.c:1206:9
#5 0x562504502ad3 in zend_verify_internal_arg_types /php-src/Zend/zend_execute.c:1261:8
#6 0x562504501fff in zend_internal_call_should_throw /php-src/Zend/zend_execute.c:1293:5
#7 0x5625049909ba in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER
/php-src/Zend/zend_vm_execute.h:1343:22
#8 0x56250452e8f7 in execute_ex /php-src/Zend/zend_vm_execute.h:57125:7
#9 0x5625042b29bb in zend_call_function /php-src/Zend/zend_execute_API.c:971:3
#10 0x56250294d8c6 in preg_do_repl_func /php-src/ext/pcre/php_pcre.c:1552:6
#11 0x56250294c0ac in php_pcre_replace_func_impl /php-src/ext/pcre/php_pcre.c:1945:18
#12 0x56250294b123 in php_pcre_replace_func /php-src/ext/pcre/php_pcre.c:2067:11
#13 0x56250294a928 in php_replace_in_subject_func /php-src/ext/pcre/php_pcre.c:2181:12
#14 0x56250293584d in preg_replace_func_impl /php-src/ext/pcre/php_pcre.c:2249:13
#15 0x5625029333fd in zif_preg_replace_callback /php-src/ext/pcre/php_pcre.c:2424:18
#16 0x562504990d41 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER
/php-src/Zend/zend_vm_execute.h:1349:2
#17 0x56250452e8f7 in execute_ex /php-src/Zend/zend_vm_execute.h:57125:7
#18 0x5625042b29bb in zend_call_function /php-src/Zend/zend_execute_API.c:971:3
#19 0x56250294d8c6 in preg_do_repl_func /php-src/ext/pcre/php_pcre.c:1552:6
#20 0x56250294c0ac in php_pcre_replace_func_impl /php-src/ext/pcre/php_pcre.c:1945:18
#21 0x56250294b123 in php_pcre_replace_func /php-src/ext/pcre/php_pcre.c:2067:11
#22 0x56250294a928 in php_replace_in_subject_func /php-src/ext/pcre/php_pcre.c:2181:12
#23 0x56250293584d in preg_replace_func_impl /php-src/ext/pcre/php_pcre.c:2249:13
#24 0x5625029333fd in zif_preg_replace_callback /php-src/ext/pcre/php_pcre.c:2424:18
#25 0x562504990d41 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER
/php-src/Zend/zend_vm_execute.h:1349:2
...
#241 0x562504990d41 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER
/php-src/Zend/zend_vm_execute.h:1349:2
#242 0x56250452e8f7 in execute_ex /php-src/Zend/zend_vm_execute.h:57125:7
#243 0x5625042b29bb in zend_call_function /php-src/Zend/zend_execute_API.c:971:3
#244 0x56250294d8c6 in preg_do_repl_func /php-src/ext/pcre/php_pcre.c:1552:6
#245 0x56250294c0ac in php_pcre_replace_func_impl /php-src/ext/pcre/php_pcre.c:1945:18
#246 0x56250294b123 in php_pcre_replace_func /php-src/ext/pcre/php_pcre.c:2067:11
SUMMARY: AddressSanitizer: stack-overflow /php-src/Zend/zend_API.c:4049 in zend_is_callable_at_frame
```
Similar to #13768, kindly close this issue if it is already handled correctly.
### PHP Version
PHP 8.4.0-dev
### Operating System
ubuntu 22.04