bug #39795 Dont allow unserializing classes with a destructor - 5.1 (jderusse)

This PR was merged into the 5.1 branch.

Discussion
----------

Dont allow unserializing classes with a destructor - 5.1

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Prevent destructors with side-effects from being unserialized

Commits
-------

07402f4af3 Dont allow unserializing classes with a destructor - 5.1
This commit is contained in:
Nicolas Grekas 2021-01-12 10:31:38 +01:00
commit 8bc5679bcc
3 changed files with 24 additions and 0 deletions

View File

@ -109,6 +109,16 @@ final class AmpResponse implements ResponseInterface
return null !== $type ? $this->info[$type] ?? null : $this->info;
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
try {

View File

@ -63,6 +63,16 @@ class Connection
$this->client = $client ?? new SqsClient([]);
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
$this->reset();

View File

@ -359,6 +359,10 @@ class UnicodeString extends AbstractUnicodeString
public function __wakeup()
{
if (!\is_string($this->string)) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
normalizer_is_normalized($this->string) ?: $this->string = normalizer_normalize($this->string);
}