File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/Symfony/Component/Config Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,26 @@ public function isFresh()
86
86
}
87
87
88
88
$ time = filemtime ($ this ->file );
89
- $ meta = unserialize (file_get_contents ($ metadata ));
89
+ try {
90
+ $ unserializeCallbackHandler = ini_set ('unserialize_callback_func ' , '' );
91
+ $ signalingException = new \UnexpectedValueException ();
92
+ set_error_handler (function () use ($ signalingException ) { throw $ signalingException ; });
93
+
94
+ $ e = null ;
95
+ $ meta = false ;
96
+ $ meta = unserialize (file_get_contents ($ metadata ));
97
+ } catch (\Error $ e ) {
98
+ } catch (\Exception $ e ) {
99
+ }
100
+ restore_error_handler ();
101
+ ini_set ('unserialize_callback_func ' , $ unserializeCallbackHandler );
102
+ if (null !== $ e && $ e !== $ signalingException ) {
103
+ throw $ e ;
104
+ }
105
+ if (false === $ meta ) {
106
+ return false ;
107
+ }
108
+
90
109
foreach ($ meta as $ resource ) {
91
110
if (!$ resource ->isFresh ($ time )) {
92
111
return false ;
Original file line number Diff line number Diff line change @@ -93,6 +93,15 @@ public function testCacheIsNotFreshIfOneOfTheResourcesIsNotFresh()
93
93
$ this ->assertFalse ($ cache ->isFresh ());
94
94
}
95
95
96
+ public function testCacheIsNotFreshWhenUnserializeFails ()
97
+ {
98
+ file_put_contents ($ this ->metaFile , substr (file_get_contents ($ this ->metaFile ), 2 ));
99
+
100
+ $ cache = new ConfigCache ($ this ->cacheFile , true );
101
+
102
+ $ this ->assertFalse ($ cache ->isFresh ());
103
+ }
104
+
96
105
public function testWriteDumpsFile ()
97
106
{
98
107
unlink ($ this ->cacheFile );
You can’t perform that action at this time.
0 commit comments