Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add safety to transfer context long to ptr conversions. #275

Merged
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
6 changes: 3 additions & 3 deletions src/transfer_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void TransferContext::read_args(jni::Env& p_env, Variant* args) {
void TransferContext::icall(
JNIEnv* rawEnv,
jobject instance,
jlong jPtr,
jlong j_ptr,
jint p_method_index,
jint expectedReturnType) {
if (unlikely(!icall_args_init)) {
Expand All @@ -130,7 +130,7 @@ void TransferContext::icall(

read_args_to_array(buffer, variant_args, args_size);

auto* ptr = reinterpret_cast<Object*>(jPtr);
auto* ptr{reinterpret_cast<Object*>(static_cast<uintptr_t>(j_ptr))};

int method_index{static_cast<int>(p_method_index)};
MethodBind* methodBind{GDKotlin::get_instance().engine_type_method[method_index]};
Expand Down Expand Up @@ -192,7 +192,7 @@ void TransferContext::set_script(
jobject p_object,
jobject p_class_loader) {
Ref<KotlinScript> kotlin_script{GDKotlin::get_instance().user_scripts[static_cast<int>(p_class_index)]};
auto* owner{reinterpret_cast<Object*>(p_raw_ptr)};
auto* owner{reinterpret_cast<Object*>(static_cast<uintptr_t>(p_raw_ptr))};
auto* kt_object{new KtObject(jni::JObject(p_object), jni::JObject(p_class_loader))};
auto* script{memnew(KotlinInstance(kt_object, owner, kotlin_script->get_kotlin_class(), kotlin_script.ptr()))};
owner->set_script_instance(script);
Expand Down
2 changes: 1 addition & 1 deletion src/transfer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TransferContext : public JavaInstanceWrapper<TransferContext> {

static void icall(JNIEnv* rawEnv,
jobject instance,
jlong jPtr,
jlong j_ptr,
jint p_method_index,
jint expectedReturnType);

Expand Down