[php-src] Issue #18826: ZEND_ARG_VARIADIC_TYPE_INFO(0, str, IS_STRING, 0) does not enforce strings
| From: | divinity76 | Date: | Tue, 10 Jun 2025 15:47:05 +0000 |
| Subject: | [php-src] Issue #18826: ZEND_ARG_VARIADIC_TYPE_INFO(0, str, IS_STRING, 0) does not enforce strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250232@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18826
Author: divinity76
### Description
When doing
```c
function str_starts_with(string $haystack, string ...$needle): bool {}
(...)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_str_starts_with, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_END_ARG_INFO()
```
You would think that the string type would be enforced with strict_types=1
but it doesn't! If you do
```c
function str_starts_with(string $haystack, string ...$needle): bool {}
(...)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_str_starts_with, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_END_ARG_INFO()
(...)
zval *needles;
size_t num_needles;
ZEND_PARSE_PARAMETERS_START(2, -1)
Z_PARAM_STR(haystack)
Z_PARAM_VARIADIC('+', needles, num_needles)
ZEND_PARSE_PARAMETERS_END();
for (size_t i = 0; i < num_needles; ++i) {
Z_STR(needles[i]);
}
```
and 1 of the needles is an int, you get a segfault!
### PHP Version
```plain
current git master, 3399235bec275516f6b87714087526d36d6f6976
```
### Operating System
Ubuntu 24.04