Fixed variant decoding Segmentation Fault
(cherry picked from commit 6aede992a9
)
This commit is contained in:
parent
ec1dc201f6
commit
12b9fe5021
|
@ -99,7 +99,8 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
|
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects, int p_depth) {
|
||||||
|
ERR_FAIL_COND_V_MSG(p_depth > Variant::MAX_RECURSION_DEPTH, ERR_OUT_OF_MEMORY, "Variant is too deep. Bailing.");
|
||||||
const uint8_t *buf = p_buffer;
|
const uint8_t *buf = p_buffer;
|
||||||
int len = p_len;
|
int len = p_len;
|
||||||
|
|
||||||
|
@ -430,7 +431,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
|
||||||
|
|
||||||
Variant value;
|
Variant value;
|
||||||
int used;
|
int used;
|
||||||
err = decode_variant(value, buf, len, &used, p_allow_objects);
|
err = decode_variant(value, buf, len, &used, p_allow_objects, p_depth + 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +474,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
|
||||||
Variant key, value;
|
Variant key, value;
|
||||||
|
|
||||||
int used;
|
int used;
|
||||||
Error err = decode_variant(key, buf, len, &used, p_allow_objects);
|
Error err = decode_variant(key, buf, len, &used, p_allow_objects, p_depth + 1);
|
||||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
||||||
|
|
||||||
buf += used;
|
buf += used;
|
||||||
|
@ -482,7 +483,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
|
||||||
(*r_len) += used;
|
(*r_len) += used;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = decode_variant(value, buf, len, &used, p_allow_objects);
|
err = decode_variant(value, buf, len, &used, p_allow_objects, p_depth + 1);
|
||||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
||||||
|
|
||||||
buf += used;
|
buf += used;
|
||||||
|
@ -515,7 +516,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
int used = 0;
|
int used = 0;
|
||||||
Variant v;
|
Variant v;
|
||||||
Error err = decode_variant(v, buf, len, &used, p_allow_objects);
|
Error err = decode_variant(v, buf, len, &used, p_allow_objects, p_depth + 1);
|
||||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
ERR_FAIL_COND_V_MSG(err != OK, err, "Error when trying to decode Variant.");
|
||||||
buf += used;
|
buf += used;
|
||||||
len -= used;
|
len -= used;
|
||||||
|
|
|
@ -180,7 +180,7 @@ public:
|
||||||
EncodedObjectAsID();
|
EncodedObjectAsID();
|
||||||
};
|
};
|
||||||
|
|
||||||
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false);
|
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false, int p_depth = 0);
|
||||||
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0);
|
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue