Skip to content

Commit 00a8c94

Browse files
bug symfony#23783 Avoid infinite loops when profiler data is malformed (javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- Avoid infinite loops when profiler data is malformed | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#22963 | License | MIT | Doc PR | - Thanks to the bug reproducer provided by @Kyoushu, I could reproduce this error: ``` PHP 7.1.4 Development Server started at Thu Aug 3 22:13:26 2017 Listening on http://127.0.0.1:8000 Document root is projects/symfony-fileprofilerstorage-bug/web Press Ctrl-C to quit. [Thu Aug 3 22:13:26 2017] PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 282624 bytes) in projects/symfony-fileprofilerstorage-bug/vendor/symfony/symfony/src/Symfony/Component/ HttpKernel/Profiler/FileProfilerStorage.php on line 124 ``` After the changes proposed in this PR, the browser no longer exhausts the memory and you can see the exception page explaining the error. The web debug toolbar doesn't load, but it doesn't crash anything: ![error-profiler](https://user-images.githubusercontent.com/73419/28941732-3c7eb29c-7899-11e7-88e8-a16517d5bcf7.png) Commits ------- e5ef9fb Avoid infinite loops when profiler data is malformed
2 parents e1ffb33 + e5ef9fb commit 00a8c94

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,19 @@ public function write(Profile $profile)
144144
}
145145
}
146146

147+
$profileToken = $profile->getToken();
148+
// when there are errors in sub-requests, the parent and/or children tokens
149+
// may equal the profile token, resulting in infinite loops
150+
$parentToken = $profile->getParentToken() !== $profileToken ? $profile->getParentToken() : null;
151+
$childrenToken = array_filter(array_map(function ($p) use ($profileToken) {
152+
return $profileToken !== $p->getToken() ? $p->getToken() : null;
153+
}, $profile->getChildren()));
154+
147155
// Store profile
148156
$data = array(
149-
'token' => $profile->getToken(),
150-
'parent' => $profile->getParentToken(),
151-
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
157+
'token' => $profileToken,
158+
'parent' => $parentToken,
159+
'children' => $childrenToken,
152160
'data' => $profile->getCollectors(),
153161
'ip' => $profile->getIp(),
154162
'method' => $profile->getMethod(),

0 commit comments

Comments
 (0)