Skip to content

Commit

Permalink
Guard decoding issues when core logs invalid utf-8 messages (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Jul 5, 2024
1 parent 74e24c2 commit 2eaaf92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* None.

### Fixed
* Fix crashes when core tries to log invalid utf-8 messages. (Issue [#1760](https://github.com/realm/realm-kotlin/issues/1760) [RKOTLIN-1089](https://jira.mongodb.org/browse/RKOTLIN-1089)).
* [Sync] Fatal sync exceptions are now thrown as `UnrecoverableSyncException`. (Issue [#1767](https://github.com/realm/realm-kotlin/issues/1767) [RKOTLIN-1096](https://jira.mongodb.org/browse/RKOTLIN-1096)).
* [Sync] Fix `NullPointerException` in `SubscriptionSet.waitForSynchronization`. (Issue [#1777](https://github.com/realm/realm-kotlin/issues/1777) [RKOTLIN-1102](https://jira.mongodb.org/browse/RKOTLIN-1102)).

Expand Down
7 changes: 3 additions & 4 deletions packages/cinterop/src/jvm/jni/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ static std::string string_to_hex(const std::string& message, realm::StringData&
ret << "error_code = " << error_code << "; ";
ret << "retcode = " << retcode << "; ";
ret << "StringData.size = " << str.size() << "; ";
ret << "StringData.data = " << str << "; ";
ret << "StringData as hex = ";
ret << "StringData as hex =";
for (std::string::size_type i = 0; i < str.size(); ++i)
ret << " 0x" << std::hex << std::setfill('0') << std::setw(2) << (int)s[i];
ret << "; ";
ret << "in_begin = " << in_begin << "; ";
ret << "in_end = " << in_end << "; ";
ret << "in_begin = " << (void*) in_begin << "; ";
ret << "in_end = " << (void*) in_end << "; ";
ret << "out_curr = " << out_curr << "; ";
ret << "out_end = " << out_end << ";";
return ret.str();
Expand Down
10 changes: 9 additions & 1 deletion packages/jni-swig-stub/src/main/jni/realm_api_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,15 @@ realm_set_log_callback([](void *userdata, const char *category, realm_log_level_
"(SLjava/lang/String;Ljava/lang/String;)V");

push_local_frame(jenv, 2);
jenv->CallVoidMethod(log_callback, log_method, java_level, to_jstring(jenv, category), to_jstring(jenv, message));
jstring j_message = NULL;
try {
j_message = to_jstring(jenv, message);
} catch (RuntimeError exception) {
std::ostringstream ret;
ret << "Invalid data: " << exception.reason();
j_message = to_jstring(jenv, ret.str());
}
jenv->CallVoidMethod(log_callback, log_method, java_level, to_jstring(jenv, category), j_message);
jni_check_exception(jenv);
jenv->PopLocalFrame(NULL);
},
Expand Down

0 comments on commit 2eaaf92

Please sign in to comment.