Skip to content

Commit

Permalink
Merge pull request #79370 from dalexeev/core-array-recursion-check
Browse files Browse the repository at this point in the history
Core: Fix recursion level check for array stringification
  • Loading branch information
akien-mga committed Aug 18, 2023
2 parents ff5c884 + bb40bd9 commit 1d70968
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions core/variant/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,10 @@ String Variant::stringify(int recursion_count) const {
case COLOR:
return operator Color();
case DICTIONARY: {
ERR_FAIL_COND_V_MSG(recursion_count > MAX_RECURSION, "{ ... }", "Maximum dictionary recursion reached!");
recursion_count++;

const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
if (recursion_count > MAX_RECURSION) {
ERR_PRINT("Maximum dictionary recursion reached!");
return "{ ... }";
}

// Add leading and trailing space to Dictionary printing. This distinguishes it
// from array printing on fonts that have similar-looking {} and [] characters.
Expand All @@ -1768,7 +1767,6 @@ String Variant::stringify(int recursion_count) const {

Vector<_VariantStrPair> pairs;

recursion_count++;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
_VariantStrPair sp;
sp.key = stringify_variant_clean(E->get(), recursion_count);
Expand All @@ -1787,6 +1785,7 @@ String Variant::stringify(int recursion_count) const {

return str;
}
// Packed arrays cannot contain recursive structures, the recursion_count increment is not needed.
case PACKED_VECTOR2_ARRAY: {
return stringify_vector(operator Vector<Vector2>(), recursion_count);
}
Expand Down Expand Up @@ -1815,13 +1814,10 @@ String Variant::stringify(int recursion_count) const {
return stringify_vector(operator Vector<double>(), recursion_count);
}
case ARRAY: {
Array arr = operator Array();
if (recursion_count > MAX_RECURSION) {
ERR_PRINT("Maximum array recursion reached!");
return "[...]";
}
ERR_FAIL_COND_V_MSG(recursion_count > MAX_RECURSION, "[...]", "Maximum array recursion reached!");
recursion_count++;

return stringify_vector(arr, recursion_count);
return stringify_vector(operator Array(), recursion_count);
}
case OBJECT: {
if (_get_obj().obj) {
Expand Down

0 comments on commit 1d70968

Please sign in to comment.