-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-9186 @strict-properties can be bypassed using unserialization #9354
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
Changes from all commits
6d66a7a
0869882
ebafb25
a8515c7
b1f1abc
8c8ff84
f1a6837
817adf5
d730db9
90bef0f
25863e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Fix GH-9186 Readonly classes can have dynamic properties created by unserialize() | ||
--FILE-- | ||
<?php | ||
|
||
readonly class C {} | ||
|
||
try { | ||
$readonly = unserialize('O:1:"C":1:{s:1:"x";b:1;}'); | ||
} catch (Error $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Cannot create dynamic property C::$x |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
GH-9186 Dynamic property unserialization should trigger a deprecated notice | ||
--EXTENSIONS-- | ||
gmp | ||
--FILE-- | ||
<?php | ||
|
||
$g = new GMP(); | ||
$g->{1} = 123; | ||
|
||
$serialized = serialize($g); | ||
var_dump(unserialize($serialized)); | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Creation of dynamic property GMP::$1 is deprecated in %s on line %d | ||
|
||
Deprecated: Creation of dynamic property GMP::$1 is deprecated in %s on line %d | ||
object(GMP)#%d (%d) { | ||
[1]=> | ||
int(123) | ||
["num"]=> | ||
string(1) "0" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Fix GH-9186 @strict-properties can be bypassed using unserialization | ||
--FILE-- | ||
<?php | ||
|
||
try { | ||
unserialize('O:17:"Random\Randomizer":1:{i:0;a:2:{s:3:"foo";N;s:6:"engine";O:32:"Random\Engine\Xoshiro256StarStar":2:{i:0;a:0:{}i:1;a:4:{i:0;s:16:"7520fbc2d6f8de46";i:1;s:16:"84d2d2b9d7ba0a34";i:2;s:16:"d975f36db6490b32";i:3;s:16:"c19991ee16785b94";}}}}'); | ||
} catch (Exception $error) { | ||
echo $error->getMessage() . "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Invalid serialization data for Random\Randomizer object |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ public function __construct(int $size = 0) {} | |
/** @tentative-return-type */ | ||
public function __wakeup(): void {} | ||
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.
php > class MyClass extends SplFixedArray { public function __construct(public readonly int $abc) {} }
php > $x = new MyClass(123);
php > var_export($x);
\MyClass::__set_state(array(
'abc' => 123,
))
php > echo serialize($x);
O:7:"MyClass":1:{s:3:"abc";i:123;}
php > $x->__wakeup();
php > echo serialize($x);
O:7:"MyClass":1:{i:0;i:123;} // <-- no longer serializing $x->abc
php > var_export($x->abc);
123 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. I also support the deprecation of |
||
|
||
public function __serialize(): array {} | ||
|
||
public function __unserialize(array $data): void {} | ||
|
||
/** @tentative-return-type */ | ||
public function count(): int {} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.