Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a75896d

Browse filesBrowse files
committed
[VarExporter] unserialize() might throw an Exception on php 8.
1 parent fff8c00 commit a75896d
Copy full SHA for a75896d

File tree

2 files changed

+11
-4
lines changed
Filter options

2 files changed

+11
-4
lines changed

‎src/Symfony/Component/VarExporter/Exception/NotInstantiableTypeException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Exception/NotInstantiableTypeException.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
class NotInstantiableTypeException extends \Exception implements ExceptionInterface
1515
{
16-
public function __construct(string $type)
16+
public function __construct(string $type, \Throwable $previous = null)
1717
{
18-
parent::__construct(sprintf('Type "%s" is not instantiable.', $type));
18+
parent::__construct(sprintf('Type "%s" is not instantiable.', $type), 0, $previous);
1919
}
2020
}

‎src/Symfony/Component/VarExporter/Internal/Registry.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Internal/Registry.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ public static function getClassReflector($class, $instantiableWithoutConstructor
8989
$proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:';
9090
if ('C:' === $proto && !$reflector->getMethod('unserialize')->isInternal()) {
9191
$proto = null;
92-
} elseif (false === $proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}')) {
93-
throw new NotInstantiableTypeException($class);
92+
} else {
93+
try {
94+
$proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}');
95+
} catch (\Exception $e) {
96+
throw new NotInstantiableTypeException($class, $e);
97+
}
98+
if (false === $proto) {
99+
throw new NotInstantiableTypeException($class);
100+
}
94101
}
95102
}
96103
if (null !== $proto && !$proto instanceof \Throwable && !$proto instanceof \Serializable && !method_exists($class, '__sleep') && (\PHP_VERSION_ID < 70400 || !method_exists($class, '__serialize'))) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.