Skip to content

Commit

Permalink
Merge pull request nextcloud#28324 from nextcloud/bugfix/noid/avoid-s…
Browse files Browse the repository at this point in the history
…tack-depth-exceed
  • Loading branch information
skjnldsv committed Aug 5, 2021
2 parents fc4e1d3 + b235a85 commit d65a35e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/private/Log/ExceptionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,27 @@ private function encodeTrace($trace) {
}, $filteredTrace);
}

private function encodeArg($arg) {
private function encodeArg($arg, $nestingLevel = 5) {
if (is_object($arg)) {
$data = get_object_vars($arg);
$data['__class__'] = get_class($arg);
return array_map([$this, 'encodeArg'], $data);
if ($nestingLevel === 0) {
return [
'__class__' => get_class($arg),
'__properties__' => 'Encoding skipped as the maximum nesting level was reached',
];
}

$objectInfo = [ '__class__' => get_class($arg) ];
$objectVars = get_object_vars($arg);
return array_map(function ($arg) use ($nestingLevel) {
return $this->encodeArg($arg, $nestingLevel - 1);
}, array_merge($objectInfo, $objectVars));
}

if (is_array($arg)) {
if ($nestingLevel === 0) {
return ['Encoding skipped as the maximum nesting level was reached'];
}

// Only log the first 5 elements of an array unless we are on debug
if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) {
$elemCount = count($arg);
Expand All @@ -244,7 +257,9 @@ private function encodeArg($arg) {
$arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries';
}
}
return array_map([$this, 'encodeArg'], $arg);
return array_map(function ($e) use ($nestingLevel) {
return $this->encodeArg($e, $nestingLevel - 1);
}, $arg);
}

return $arg;
Expand Down

0 comments on commit d65a35e

Please sign in to comment.