Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Prevent feedback loops in SentryLogger ([#275](https://github.com/getsentry/sentry-godot/pull/275))
- Fix `release` option not honored if set to a custom value in the project settings, and fix parsing of `app_name`/`app_version` replacement tokens if set via a configuration script. ([#276](https://github.com/getsentry/sentry-godot/pull/276))
- Remove `libatomic.so.1` dependency on Linux ([#278](https://github.com/getsentry/sentry-godot/pull/278))
- Prevent stack overflow in variant conversion ([#284](https://github.com/getsentry/sentry-godot/pull/284))

## 1.0.0-alpha.2

Expand Down
8 changes: 8 additions & 0 deletions project/test/suites/test_sdk.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ func test_remove_tag() -> void:
await assert_signal(monitor).is_emitted("callback_processed")

SentrySDK._unset_before_send()


## SentrySDK Variant conversion should not cause stack overflow.
func test_variant_conversion_against_stack_overflow() -> void:
var dict: Dictionary = { "some_key": "some_value"}
var arr: Array = [dict, "another_value"]
dict["array"] = arr
SentrySDK.set_context("broken_context", dict)
6 changes: 6 additions & 0 deletions src/sentry/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
#define SENTRY_SCREENSHOT_FN "screenshot.jpg"
#define SENTRY_VIEW_HIERARCHY_FN "view-hierarchy.json"

namespace sentry {

constexpr int VARIANT_CONVERSION_MAX_DEPTH = 32;

};

#endif // SENTRY_COMMON_DEFS_H
18 changes: 15 additions & 3 deletions src/sentry/native/native_util.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "native_util.h"

#include "sentry/common_defs.h"

namespace sentry::native {

sentry_value_t variant_to_sentry_value(const Variant &p_variant) {
sentry_value_t variant_to_sentry_value(const Variant &p_variant, int p_depth) {
switch (p_variant.get_type()) {
case Variant::Type::NIL: {
return sentry_value_new_null();
Expand All @@ -20,12 +22,17 @@ sentry_value_t variant_to_sentry_value(const Variant &p_variant) {
return sentry_value_new_string(((String)p_variant).utf8());
} break;
case Variant::Type::DICTIONARY: {
if (p_depth > VARIANT_CONVERSION_MAX_DEPTH) {
ERR_PRINT_ONCE("Sentry: Maximum Variant conversion depth reached!");
return sentry_value_new_string("{...}");
}

Dictionary dic = p_variant;
sentry_value_t sentry_dic = sentry_value_new_object();
const Array &keys = dic.keys();
for (int i = 0; i < keys.size(); i++) {
const String &key = keys[i];
sentry_value_set_by_key(sentry_dic, key.utf8(), variant_to_sentry_value(dic[key]));
sentry_value_set_by_key(sentry_dic, key.utf8(), variant_to_sentry_value(dic[key], p_depth + 1));
}
return sentry_dic;
} break;
Expand All @@ -40,14 +47,19 @@ sentry_value_t variant_to_sentry_value(const Variant &p_variant) {
case Variant::Type::PACKED_VECTOR3_ARRAY:
case Variant::Type::PACKED_COLOR_ARRAY:
case Variant::Type::PACKED_VECTOR4_ARRAY: {
if (p_depth > VARIANT_CONVERSION_MAX_DEPTH) {
ERR_PRINT_ONCE("Sentry: Maximum Variant conversion depth reached!");
return sentry_value_new_string("[...]");
}

bool oob = false;
bool valid = true;
int i = 0;
sentry_value_t sentry_list = sentry_value_new_list();
do {
Variant item = p_variant.get_indexed(i++, valid, oob);
if (valid) {
sentry_value_append(sentry_list, variant_to_sentry_value(item));
sentry_value_append(sentry_list, variant_to_sentry_value(item, p_depth + 1));
}
} while (!oob);
return sentry_list;
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/native/native_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace godot;
namespace sentry::native {

// Convert Godot Variant to sentry_value_t.
sentry_value_t variant_to_sentry_value(const Variant &p_variant);
sentry_value_t variant_to_sentry_value(const Variant &p_variant, int p_depth = 0);

// Convert PackedStringArray to sentry_value_t (as a list).
sentry_value_t strings_to_sentry_list(const PackedStringArray &p_strings);
Expand Down
Loading