Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix recursion level check for array stringification #79370

Merged
merged 1 commit into from Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions core/variant/variant.cpp
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