Skip to content

Commit 5087cf3

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-20435: SensitiveParameter doesn't work for named argument passing to variadic parameter Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
2 parents a0b918d + 3e715d3 commit 5087cf3

File tree

6 files changed

+62
-34
lines changed

6 files changed

+62
-34
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Sync all boost.context files with release 1.86.0. (mvorisek)
7+
. Fixed bug GH-20435 (SensitiveParameter doesn't work for named argument
8+
passing to variadic parameter). (ndossche)
79

810
- Standard:
911
. Fix memory leak in array_diff() with custom type checks. (ndossche)
@@ -12,6 +14,10 @@ PHP NEWS
1214
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
1315
buffer). (Arnaud)
1416

17+
- Phar:
18+
. Fixed bug GH-20442 (Phar does not respect case-insensitiveness of
19+
__halt_compiler() when reading stub). (ndossche, TimWolla)
20+
1521
06 Nov 2025, PHP 8.5.0RC4
1622

1723
- Core:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20435 (SensitiveParameter doesn't work for named argument passing to variadic parameter)
3+
--FILE--
4+
<?php
5+
6+
function test($a, #[\SensitiveParameter] ...$x) {
7+
debug_print_backtrace();
8+
}
9+
10+
test(b: 1, a: 2, c: 3);
11+
12+
?>
13+
--EXPECTF--
14+
#0 %s(%d): test(2, b: Object(SensitiveParameterValue), c: Object(SensitiveParameterValue))

Zend/zend_builtin_functions.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,11 +1856,29 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
18561856
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
18571857
zend_string *name;
18581858
zval *arg;
1859+
1860+
ZEND_ASSERT(call->func->common.fn_flags & ZEND_ACC_VARIADIC);
1861+
1862+
zend_attribute *attribute = zend_get_parameter_attribute_str(
1863+
call->func->common.attributes,
1864+
"sensitiveparameter",
1865+
sizeof("sensitiveparameter") - 1,
1866+
call->func->common.num_args
1867+
);
1868+
bool is_sensitive = attribute != NULL;
1869+
18591870
SEPARATE_ARRAY(arg_array);
18601871
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(call->extra_named_params, name, arg) {
18611872
ZVAL_DEREF(arg);
1862-
Z_TRY_ADDREF_P(arg);
1863-
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1873+
if (is_sensitive) {
1874+
zval redacted_arg;
1875+
object_init_ex(&redacted_arg, zend_ce_sensitive_parameter_value);
1876+
zend_call_method_with_1_params(Z_OBJ_P(&redacted_arg), zend_ce_sensitive_parameter_value, &zend_ce_sensitive_parameter_value->constructor, "__construct", NULL, arg);
1877+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, &redacted_arg);
1878+
} else {
1879+
Z_TRY_ADDREF_P(arg);
1880+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1881+
}
18641882
} ZEND_HASH_FOREACH_END();
18651883
}
18661884
}

ext/phar/phar.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,35 +1600,6 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, char *alias,
16001600
}
16011601
/* }}}*/
16021602

1603-
static inline char *phar_strnstr(const char *buf, size_t buf_len, const char *search, size_t search_len) /* {{{ */
1604-
{
1605-
const char *c;
1606-
ptrdiff_t so_far = 0;
1607-
1608-
if (buf_len < search_len) {
1609-
return NULL;
1610-
}
1611-
1612-
c = buf - 1;
1613-
1614-
do {
1615-
if (!(c = memchr(c + 1, search[0], buf_len - search_len - so_far))) {
1616-
return (char *) NULL;
1617-
}
1618-
1619-
so_far = c - buf;
1620-
1621-
if (so_far >= (buf_len - search_len)) {
1622-
return (char *) NULL;
1623-
}
1624-
1625-
if (!memcmp(c, search, search_len)) {
1626-
return (char *) c;
1627-
}
1628-
} while (1);
1629-
}
1630-
/* }}} */
1631-
16321603
/**
16331604
* Scan an open fp for the required __HALT_COMPILER(); ?> token and verify
16341605
* that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
@@ -1640,7 +1611,8 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16401611
static const char zip_magic[] = "PK\x03\x04";
16411612
static const char gz_magic[] = "\x1f\x8b\x08";
16421613
static const char bz_magic[] = "BZh";
1643-
char *pos, test = '\0';
1614+
const char *pos;
1615+
char test = '\0';
16441616
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16451617
const int window_size = 1024;
16461618
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1789,14 +1761,14 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17891761
}
17901762

17911763
if (got >= 512) {
1792-
if (phar_is_tar(pos, fname)) {
1764+
if (phar_is_tar((char *) pos, fname)) { /* TODO: fix const correctness */
17931765
php_stream_rewind(fp);
17941766
return phar_parse_tarfile(fp, fname, fname_len, alias, alias_len, pphar, compression, error);
17951767
}
17961768
}
17971769
}
17981770

1799-
if (got > 0 && (pos = phar_strnstr(buffer, got + sizeof(token), token, sizeof(token)-1)) != NULL) {
1771+
if (got > 0 && (pos = php_memnistr(buffer, token, tokenlen, buffer + got + sizeof(token))) != NULL) {
18001772
halt_offset += (pos - buffer); /* no -tokenlen+tokenlen here */
18011773
return phar_parse_pharfile(fp, fname, fname_len, alias, alias_len, halt_offset, pphar, compression, error);
18021774
}

ext/phar/tests/files/gh20442.phar

144 Bytes
Binary file not shown.

ext/phar/tests/gh20442.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-20442 (Phar does not respect case-insensitiveness of __halt_compiler() when reading stub)
3+
--EXTENSIONS--
4+
phar
5+
--FILE--
6+
<?php
7+
8+
$phar = new Phar(__DIR__.'/files/gh20442.phar');
9+
var_dump($phar->count());
10+
var_dump($phar->getStub());
11+
12+
?>
13+
--EXPECT--
14+
int(1)
15+
string(50) "<?php
16+
echo "Hello World!";
17+
__halt_compiler(); ?>
18+
"

0 commit comments

Comments
 (0)