From 324636473aa65165caeee29e9b70e2d8c21fcb96 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 30 Jul 2021 15:43:01 +0200 Subject: [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. --- core/variant/variant.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'core/variant') diff --git a/core/variant/variant.h b/core/variant/variant.h index 4dc706e853..780f9b4e70 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -118,6 +118,11 @@ public: VARIANT_MAX }; + enum { + // Maximum recursion depth allowed when serializing variants. + MAX_RECURSION_DEPTH = 1024, + }; + private: friend struct _VariantCall; friend class VariantInternal; -- cgit v1.2.3