summaryrefslogtreecommitdiffstats
path: root/core/io/marshalls.h
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-30 15:43:01 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-30 16:13:43 +0200
commit324636473aa65165caeee29e9b70e2d8c21fcb96 (patch)
tree505d93035a7c82f317b9315feff47029f35663da /core/io/marshalls.h
parente95e33f25137486d2df0a1c13e17394454c7fdf1 (diff)
downloadredot-engine-324636473aa65165caeee29e9b70e2d8c21fcb96.tar.gz
[Net] Fix Marshalls infinite recursion crash.
Variants like dictionaries and arrays can have cyclic references, which caused `encode_variant` to run an infinite recursion. Instead of keeping a stack and looking for cyclic references which would make serialization slower, this commit adds a `MAX_RECURSION_DEPTH` constant to Variant, and have `encode_variant` keep track of the current recursion depth, bailing when it's too high since this likely means a cyclic reference has been encountered.
Diffstat (limited to 'core/io/marshalls.h')
-rw-r--r--core/io/marshalls.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 3ebed914a3..05804d5a46 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -213,6 +213,6 @@ public:
};
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false);
-Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false);
+Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0);
#endif // MARSHALLS_H