Skip to content

Commit 9db9405

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: ext/standard: Don't share the unserialize() context with enum autoloaders
2 parents 4c6bf5f + bbed764 commit 9db9405

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ PHP NEWS
102102
bcrypt costs. (Ilia Alshanetsky)
103103
. Fixed proc_open() null descriptor not being inheritable on Windows.
104104
(Jorg Sowa)
105+
. Don't share the unserialize() context with enum autoloaders.
106+
(Nicolas Grekas)
105107

106108
- Tidy:
107109
. Fixed tidy_repair_string(), tidy_repair_file(), tidy::repairString() and
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Enum unserialize runs the autoloader outside of the current unserialize() context
3+
--FILE--
4+
<?php
5+
6+
class Init {
7+
public bool $ready = false;
8+
9+
public function __unserialize(array $data): void {
10+
$this->ready = true;
11+
}
12+
}
13+
14+
enum Backed: string {
15+
case Foo = Value::FOO;
16+
}
17+
18+
spl_autoload_register(function ($class) {
19+
var_dump(unserialize('O:4:"Init":0:{}')->ready);
20+
eval(match ($class) {
21+
'Pure' => 'enum Pure { case Foo; }',
22+
'Value' => 'class Value { const FOO = "foo"; }',
23+
});
24+
});
25+
26+
foreach (['E:8:"Pure:Foo";', 'E:10:"Backed:Foo";'] as $enum) {
27+
$data = unserialize('a:3:{i:0;' . $enum . 'i:1;O:8:"stdClass":0:{}i:2;r:3;}');
28+
var_dump($data[1] === $data[2]);
29+
}
30+
31+
?>
32+
--EXPECT--
33+
bool(true)
34+
bool(true)
35+
bool(true)
36+
bool(true)

‎ext/standard/var_unserializer.re‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,9 @@ object ":" uiv ":" ["] {
13851385
goto fail;
13861386
}
13871387
1388+
BG(serialize_lock)++;
13881389
zend_class_entry *ce = zend_lookup_class(enum_name);
1390+
BG(serialize_lock)--;
13891391
if (!ce) {
13901392
php_error_docref(NULL, E_WARNING, "Class '%s' not found", ZSTR_VAL(enum_name));
13911393
goto fail;
@@ -1414,7 +1416,10 @@ object ":" uiv ":" ["] {
14141416
14151417
zval *value = &c->value;
14161418
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
1417-
if (zval_update_constant_ex(value, c->ce) == FAILURE) {
1419+
BG(serialize_lock)++;
1420+
zend_result result = zval_update_constant_ex(value, c->ce);
1421+
BG(serialize_lock)--;
1422+
if (result == FAILURE) {
14181423
return 0;
14191424
}
14201425
}

0 commit comments

Comments
 (0)