Skip to content

Commit d65a35e

Browse files
authored
Merge pull request #28324 from nextcloud/bugfix/noid/avoid-stack-depth-exceed
2 parents fc4e1d3 + b235a85 commit d65a35e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lib/private/Log/ExceptionSerializer.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,27 @@ private function encodeTrace($trace) {
228228
}, $filteredTrace);
229229
}
230230

231-
private function encodeArg($arg) {
231+
private function encodeArg($arg, $nestingLevel = 5) {
232232
if (is_object($arg)) {
233-
$data = get_object_vars($arg);
234-
$data['__class__'] = get_class($arg);
235-
return array_map([$this, 'encodeArg'], $data);
233+
if ($nestingLevel === 0) {
234+
return [
235+
'__class__' => get_class($arg),
236+
'__properties__' => 'Encoding skipped as the maximum nesting level was reached',
237+
];
238+
}
239+
240+
$objectInfo = [ '__class__' => get_class($arg) ];
241+
$objectVars = get_object_vars($arg);
242+
return array_map(function ($arg) use ($nestingLevel) {
243+
return $this->encodeArg($arg, $nestingLevel - 1);
244+
}, array_merge($objectInfo, $objectVars));
236245
}
237246

238247
if (is_array($arg)) {
248+
if ($nestingLevel === 0) {
249+
return ['Encoding skipped as the maximum nesting level was reached'];
250+
}
251+
239252
// Only log the first 5 elements of an array unless we are on debug
240253
if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) {
241254
$elemCount = count($arg);
@@ -244,7 +257,9 @@ private function encodeArg($arg) {
244257
$arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries';
245258
}
246259
}
247-
return array_map([$this, 'encodeArg'], $arg);
260+
return array_map(function ($e) use ($nestingLevel) {
261+
return $this->encodeArg($e, $nestingLevel - 1);
262+
}, $arg);
248263
}
249264

250265
return $arg;

0 commit comments

Comments
 (0)