Skip to content

Commit 9579bea

Browse files
committed
Dont allow unserializing classes with a destructor
1 parent 41a1b8c commit 9579bea

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

DataCollector/DataCollector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public function __sleep()
123123
public function __wakeup()
124124
{
125125
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'unserialize'))->getDeclaringClass()->name) {
126+
if (\is_object($this->data)) {
127+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
128+
}
129+
126130
@trigger_error(sprintf('Implementing the "%s::unserialize()" method is deprecated since Symfony 4.3, store all the serialized state in the "data" property instead.', $c), \E_USER_DEPRECATED);
127131
$this->unserialize($this->data);
128132
}

DataCollector/DumpDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function __wakeup()
184184
$fileLinkFormat = array_pop($this->data);
185185
$this->dataCount = \count($this->data);
186186

187-
self::__construct($this->stopwatch, $fileLinkFormat, $charset);
187+
self::__construct($this->stopwatch, \is_string($fileLinkFormat) || $fileLinkFormat instanceof FileLinkFormatter ? $fileLinkFormat : null, \is_string($charset) ? $charset : null);
188188
}
189189

190190
public function getDumpsCount()

Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,10 @@ public function __sleep()
920920

921921
public function __wakeup()
922922
{
923+
if (\is_object($this->environment) || \is_object($this->debug)) {
924+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
925+
}
926+
923927
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) {
924928
@trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), \E_USER_DEPRECATED);
925929
$this->unserialize($this->serialized);

0 commit comments

Comments
 (0)