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 609245e

Browse filesBrowse files
[Config] ConfigCache::isFresh() should return false on __PHP_Incomplete_Class
1 parent 777cdfc commit 609245e
Copy full SHA for 609245e

File tree

Expand file treeCollapse file tree

2 files changed

+35
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-1
lines changed

‎src/Symfony/Component/Config/ConfigCache.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/ConfigCache.php
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,33 @@ public function isFresh()
8585
return false;
8686
}
8787

88+
$e = null;
89+
$meta = false;
8890
$time = filemtime($this->file);
89-
$meta = unserialize(file_get_contents($metadata));
91+
$signalingException = new \UnexpectedValueException();
92+
$prevUnserializeHandler = ini_set('unserialize_callback_func', '');
93+
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$prevErrorHandler, $signalingException) {
94+
if (E_WARNING === $type && 'Class __PHP_Incomplete_Class has no unserializer' === $msg) {
95+
throw $signalingException;
96+
}
97+
98+
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
99+
});
100+
101+
try {
102+
$meta = unserialize(file_get_contents($metadata));
103+
} catch (\Error $e) {
104+
} catch (\Exception $e) {
105+
}
106+
restore_error_handler();
107+
ini_set('unserialize_callback_func', $prevUnserializeHandler);
108+
if (null !== $e && $e !== $signalingException) {
109+
throw $e;
110+
}
111+
if (false === $meta) {
112+
return false;
113+
}
114+
90115
foreach ($meta as $resource) {
91116
if (!$resource->isFresh($time)) {
92117
return false;

‎src/Symfony/Component/Config/Tests/ConfigCacheTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/ConfigCacheTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function testCacheIsNotFreshIfOneOfTheResourcesIsNotFresh()
9393
$this->assertFalse($cache->isFresh());
9494
}
9595

96+
public function testCacheIsNotFreshWhenUnserializeFails()
97+
{
98+
file_put_contents($this->metaFile, str_replace('FileResource', 'ClassNotHere', file_get_contents($this->metaFile)));
99+
100+
$cache = new ConfigCache($this->cacheFile, true);
101+
102+
$this->assertFalse($cache->isFresh());
103+
}
104+
96105
public function testWriteDumpsFile()
97106
{
98107
unlink($this->cacheFile);

0 commit comments

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