8000 add a limit and a test to FlattenExceptionTest. · symfony/symfony@c6bcf05 · GitHub
[go: up one dir, main page]

Skip to content

Commit c6bcf05

Browse files
dawehnerfabpot
authored andcommitted
add a limit and a test to FlattenExceptionTest.
1 parent 3a35bec commit c6bcf05

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,20 @@ public function setTrace($trace, $file, $line)
239239
}
240240
}
241241

242-
private function flattenArgs($args, $level = 0)
242+
private function flattenArgs($args, $level = 0, &$count = 0)
243243
{
244244
$result = array();
245245
foreach ($args as $key => $value) {
246+
if (++$count > 1e4) {
247+
return array('array', '*SKIPPED over 10000 entries*');
248+
}
246249
if (is_object($value)) {
247250
$result[$key] = array('object', get_class($value));
248251
} elseif (is_array($value)) {
249252
if ($level > 10) {
250253
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
251254
} else {
252-
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
255+
$result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
253256
}
254257
} elseif (null === $value) {
255258
$result[$key] = array('null', null);

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ public function testRecursionInArguments()
186186
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
187187
}
188188

189+
public function testTooBigArray()
190+
{
191+
$a = array();
192+
for ($i = 0; $i < 20; $i++) {
193+
for ($j = 0; $j < 50; $j++) {
194+
for ($k = 0; $k < 10; $k++) {
195+
$a[$i][$j][$k] = 'value';
196+
}
197+
}
198+
}
199+
$a[20] = 'value';
200+
$a[21] = 'value1';
201+
$exception = $this->createException($a);
202+
203+
$flattened = FlattenException::create($exception);
204+
$trace = $flattened->getTrace();
205+
$serialize_trace = serialize($trace);
206+
207+
$this->assertContains('*SKIPPED over 10000 entries*', $serialize_trace);
208+
$this->assertNotContains('*value1*', $serialize_trace);
209+
}
210+
189211
private function createException($foo)
190212
{
191213
return new \Exception();

0 commit comments

Comments
 (0)
0