Skip to content

Commit 57ddfee

Browse files
committed
add recursion depth limit in to_array_debug()
1 parent 571cc4d commit 57ddfee

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kphp_polyfills.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ function to_array_debug($any, $with_class_names = false, $public_members_only =
181181
return $key;
182182
};
183183

184-
$toArray = function($v) use (&$toArray, &$demangleField, &$with_class_names, $public_members_only, $isPrivateField) {
184+
$depth = 0;
185+
$recursion_depth_exceeded = false;
186+
$toArray = function($v) use (&$toArray, &$demangleField, &$with_class_names, $public_members_only, $isPrivateField, &$depth, &$recursion_depth_exceeded) {
185187
if (is_object($v)) {
188+
if ($depth++ > 64) {
189+
$recursion_depth_exceeded = true;
190+
return [];
191+
}
186192
$result = [];
187193
foreach ((array)$v as $field => $value) {
188194
if ($public_members_only && $isPrivateField($field)) {
@@ -204,7 +210,8 @@ function to_array_debug($any, $with_class_names = false, $public_members_only =
204210
if ($any === null) {
205211
return [];
206212
}
207-
return $toArray($any);
213+
$result = $toArray($any);
214+
return $recursion_depth_exceeded ? [] : $result;
208215
}
209216

210217
/**

0 commit comments

Comments
 (0)